diff --git a/docs/helpers/extendedEnv.go b/docs/helpers/extendedEnv.go index b9271dd9ff..17f9019d0f 100644 --- a/docs/helpers/extendedEnv.go +++ b/docs/helpers/extendedEnv.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -58,7 +57,7 @@ func GetRogueEnvs() { re := regexp.MustCompile(`os.Getenv\(([^\)]+)\)`) vars := &ConfigVars{} fmt.Printf("Reading existing variable definitions from %s\n", fullYamlPath) - yfile, err := ioutil.ReadFile(fullYamlPath) + yfile, err := os.ReadFile(fullYamlPath) if err == nil { err := yaml.Unmarshal(yfile, &vars) if err != nil { @@ -129,7 +128,7 @@ func GetRogueEnvs() { log.Fatal(err) } fmt.Printf("Writing new variable definitions to %s\n", fullYamlPath) - err = ioutil.WriteFile(fullYamlPath, output, 0666) + err = os.WriteFile(fullYamlPath, output, 0666) if err != nil { log.Fatalf("could not write %s", fullYamlPath) } @@ -146,7 +145,7 @@ func RenderGlobalVarsTemplate() { } fullYamlPath := filepath.Join(curdir, yamlSource) - content, err := ioutil.ReadFile("../../docs/templates/ADOC_extended.tmpl") + content, err := os.ReadFile("../../docs/templates/ADOC_extended.tmpl") if err != nil { log.Fatal(err) } @@ -155,7 +154,7 @@ func RenderGlobalVarsTemplate() { vars := &ConfigVars{} fmt.Printf("Reading existing variable definitions from %s\n", fullYamlPath) - yfile, err := ioutil.ReadFile(fullYamlPath) + yfile, err := os.ReadFile(fullYamlPath) if err != nil { log.Fatal(err) } diff --git a/ocis-pkg/config/envdecode/envdecode_test.go b/ocis-pkg/config/envdecode/envdecode_test.go index d8cec54c93..cb3274c1c6 100644 --- a/ocis-pkg/config/envdecode/envdecode_test.go +++ b/ocis-pkg/config/envdecode/envdecode_test.go @@ -80,7 +80,7 @@ type testConfigOverride struct { } type testNoExportedFields struct { - // folowing unexported fields are used for tests + // following unexported fields are used for tests aString string `env:"TEST_STRING"` //nolint:structcheck,unused anInt64 int64 `env:"TEST_INT64"` //nolint:structcheck,unused aUint16 uint16 `env:"TEST_UINT16"` //nolint:structcheck,unused diff --git a/ocis-pkg/log/stream.go b/ocis-pkg/log/stream.go deleted file mode 100644 index 0bb0fd43f6..0000000000 --- a/ocis-pkg/log/stream.go +++ /dev/null @@ -1,24 +0,0 @@ -package log - -import ( - mdlog "go-micro.dev/v4/debug/log" -) - -type logStream struct { - stream <-chan mdlog.Record - stop chan bool -} - -func (l *logStream) Chan() <-chan mdlog.Record { - return l.stream -} - -func (l *logStream) Stop() error { - select { - case <-l.stop: - return nil - default: - close(l.stop) - } - return nil -} diff --git a/ocis-pkg/store/store.go b/ocis-pkg/store/store.go index f41cc7285c..14d91d2879 100644 --- a/ocis-pkg/store/store.go +++ b/ocis-pkg/store/store.go @@ -9,47 +9,37 @@ import ( "go-micro.dev/v4/store" ) -var ( - storeEnv = "OCIS_STORE" - storeAddressEnv = "OCIS_STORE_ADDRESS" - storeOCMemSize = "OCIS_STORE_OCMEM_SIZE" -) - var ocMemStore *store.Store type OcisStoreOptions struct { - Type string + // Type determines the implementation: + // * "noop", for a noop store (it does nothing) + // * "etcd", for etcd + // * "ocmem", custom in-memory implementation, with fixed size and optimized prefix + // and suffix search + // * "memory", for a in-memory implementation, which is the default if noone matches + Type string + + // Address is a comma-separated list of nodes that the store + // will use. This is currently usable only with the etcd implementation. If it + // isn't provided, "127.0.0.1:2379" will be the only node used. Address string - Size int + + // Size configures the maximum capacity of the cache for + // the "ocmem" implementation, in number of items that the cache can hold per table. + // You can use 5000 to make the cache hold up to 5000 elements. + // The parameter only affects to the "ocmem" implementation, the rest will ignore it. + // If an invalid value is used, the default of 512 will be used instead. + Size int } -// Get the configured key-value store to be used. +// GetStore returns a configured key-value store // // Each microservice (or whatever piece is using the store) should use the // options available in the interface's operations to choose the right database // and table to prevent collisions with other microservices. // Recommended approach is to use "services" or "ocis-pkg" for the database, // and "services//" or "ocis-pkg//" for the package name. -// -// So far, only the name of the store and the node addresses are configurable -// via environment variables. -// Available options for "OCIS_STORE" are: -// * "noop", for a noop store (it does nothing) -// * "etcd", for etcd -// * "ocmem", custom in-memory implementation, with fixed size and optimized prefix -// and suffix search -// * "memory", for a in-memory implementation, which is the default if noone matches -// -// "OCIS_STORE_ADDRESS" is a comma-separated list of nodes that the store -// will use. This is currently usable only with the etcd implementation. If it -// isn't provided, "127.0.0.1:2379" will be the only node used. -// -// "OCIS_STORE_OCMEM_SIZE" will configure the maximum capacity of the cache for -// the "ocmem" implementation, in number of items that the cache can hold per table. -// You can use "OCIS_STORE_OCMEM_SIZE=5000" so the cache will hold up to 5000 elements. -// The parameter only affects to the "ocmem" implementation, the rest will ignore it. -// If an invalid value is used, the default will be used instead, so up to 512 elements -// the cache will hold. func GetStore(ocisOpts OcisStoreOptions) store.Store { var s store.Store diff --git a/services/graph/pkg/identity/ldap_education_school_test.go b/services/graph/pkg/identity/ldap_education_school_test.go index f27714755f..12c25894e4 100644 --- a/services/graph/pkg/identity/ldap_education_school_test.go +++ b/services/graph/pkg/identity/ldap_education_school_test.go @@ -370,7 +370,7 @@ func TestGetEducationSchoolUsers(t *testing.T) { lm := &mocks.Client{} lm.On("Search", schoolByIDSearch1).Return(&ldap.SearchResult{Entries: []*ldap.Entry{schoolEntry, schoolEntry1}}, nil) lm.On("Search", usersBySchoolIDSearch).Return(&ldap.SearchResult{Entries: []*ldap.Entry{eduUserEntryWithSchool}}, nil) - b, err := getMockedBackend(lm, eduConfig, &logger) + b, _ := getMockedBackend(lm, eduConfig, &logger) users, err := b.GetEducationSchoolUsers(context.Background(), "abcd-defg") assert.Nil(t, err) assert.Equal(t, 1, len(users)) diff --git a/services/graph/pkg/identity/ldap_education_user_test.go b/services/graph/pkg/identity/ldap_education_user_test.go index 2d1017cff7..156ba29780 100644 --- a/services/graph/pkg/identity/ldap_education_user_test.go +++ b/services/graph/pkg/identity/ldap_education_user_test.go @@ -120,7 +120,7 @@ func TestGetEducationUser(t *testing.T) { assert.Equal(t, "Test User", user.GetDisplayName()) assert.Equal(t, "abcd-defg", user.GetId()) - user, err = b.GetEducationUser(context.Background(), "xxxx-xxxx", nil) + _, err = b.GetEducationUser(context.Background(), "xxxx-xxxx", nil) lm.AssertNumberOfCalls(t, "Search", 2) assert.NotNil(t, err) assert.Equal(t, "itemNotFound", err.Error()) diff --git a/services/graph/pkg/identity/ldap_test.go b/services/graph/pkg/identity/ldap_test.go index 1f92e50213..bece82a5dc 100644 --- a/services/graph/pkg/identity/ldap_test.go +++ b/services/graph/pkg/identity/ldap_test.go @@ -255,7 +255,7 @@ func TestGetUser(t *testing.T) { nil) b, _ = getMockedBackend(lm, lconfig, &logger) - u, err = b.GetUser(context.Background(), "invalid", nil) + _, err = b.GetUser(context.Background(), "invalid", nil) if err == nil || err.Error() != "itemNotFound" { t.Errorf("Expected 'itemNotFound' got '%s'", err.Error()) } diff --git a/services/graph/pkg/service/v0/educationclasses_test.go b/services/graph/pkg/service/v0/educationclasses_test.go index 850e1b8976..d1f2a9d0b3 100644 --- a/services/graph/pkg/service/v0/educationclasses_test.go +++ b/services/graph/pkg/service/v0/educationclasses_test.go @@ -6,7 +6,6 @@ import ( "encoding/json" "errors" "io" - "io/ioutil" "net/http" "net/http/httptest" @@ -301,7 +300,7 @@ var _ = Describe("EducationClass", func() { r = r.WithContext(context.WithValue(revactx.ContextSetUser(ctx, currentUser), chi.RouteCtxKey, rctx)) svc.PatchEducationClass(rr, r) - resp, err := ioutil.ReadAll(rr.Body) + resp, err := io.ReadAll(rr.Body) Expect(err).ToNot(HaveOccurred()) Expect(string(resp)).To(ContainSubstring("Request is limited to 20")) @@ -332,7 +331,7 @@ var _ = Describe("EducationClass", func() { r = r.WithContext(context.WithValue(revactx.ContextSetUser(ctx, currentUser), chi.RouteCtxKey, rctx)) svc.PatchEducationClass(rr, r) - resp, err := ioutil.ReadAll(rr.Body) + resp, err := io.ReadAll(rr.Body) Expect(err).ToNot(HaveOccurred()) Expect(string(resp)).To(ContainSubstring("Error parsing member@odata.bind values")) diff --git a/services/graph/pkg/service/v0/graph_test.go b/services/graph/pkg/service/v0/graph_test.go index fb44516444..82a896c282 100644 --- a/services/graph/pkg/service/v0/graph_test.go +++ b/services/graph/pkg/service/v0/graph_test.go @@ -12,7 +12,6 @@ import ( gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" userprovider "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" - userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" revactx "github.com/cs3org/reva/v2/pkg/ctx" @@ -46,8 +45,8 @@ var _ = Describe("Graph", func() { cfg *config.Config rr *httptest.ResponseRecorder - currentUser = &userv1beta1.User{ - Id: &userv1beta1.UserId{ + currentUser = &userprovider.User{ + Id: &userprovider.UserId{ OpaqueId: "user", }, } diff --git a/services/graph/pkg/service/v0/groups_test.go b/services/graph/pkg/service/v0/groups_test.go index 18406d0847..16f7aa572e 100644 --- a/services/graph/pkg/service/v0/groups_test.go +++ b/services/graph/pkg/service/v0/groups_test.go @@ -6,7 +6,6 @@ import ( "encoding/json" "errors" "io" - "io/ioutil" "net/http" "net/http/httptest" @@ -298,7 +297,7 @@ var _ = Describe("Groups", func() { r = r.WithContext(context.WithValue(revactx.ContextSetUser(ctx, currentUser), chi.RouteCtxKey, rctx)) svc.PatchGroup(rr, r) - resp, err := ioutil.ReadAll(rr.Body) + resp, err := io.ReadAll(rr.Body) Expect(err).ToNot(HaveOccurred()) Expect(string(resp)).To(ContainSubstring("Request is limited to 20")) @@ -329,7 +328,7 @@ var _ = Describe("Groups", func() { r = r.WithContext(context.WithValue(revactx.ContextSetUser(ctx, currentUser), chi.RouteCtxKey, rctx)) svc.PatchGroup(rr, r) - resp, err := ioutil.ReadAll(rr.Body) + resp, err := io.ReadAll(rr.Body) Expect(err).ToNot(HaveOccurred()) Expect(string(resp)).To(ContainSubstring("Error parsing member@odata.bind values")) diff --git a/services/graph/pkg/service/v0/password_test.go b/services/graph/pkg/service/v0/password_test.go index 0184b5e173..188e9e4def 100644 --- a/services/graph/pkg/service/v0/password_test.go +++ b/services/graph/pkg/service/v0/password_test.go @@ -25,13 +25,6 @@ import ( "github.com/stretchr/testify/mock" ) -type changePwTest struct { - desc string - currentpw string - newpw string - expected int -} - var _ = Describe("Users changing their own password", func() { var ( svc service.Service diff --git a/services/ocs/pkg/middleware/requireselforadmin.go b/services/ocs/pkg/middleware/requireselforadmin.go index 51ce63d1e7..f88863db5e 100644 --- a/services/ocs/pkg/middleware/requireselforadmin.go +++ b/services/ocs/pkg/middleware/requireselforadmin.go @@ -11,7 +11,6 @@ import ( "github.com/owncloud/ocis/v2/services/ocs/pkg/service/v0/data" "github.com/owncloud/ocis/v2/services/ocs/pkg/service/v0/response" settings "github.com/owncloud/ocis/v2/services/settings/pkg/service/v0" - settingsService "github.com/owncloud/ocis/v2/services/settings/pkg/service/v0" ) // RequireSelfOrAdmin middleware is used to require the requesting user to be an admin or the requested user himself @@ -48,7 +47,7 @@ func RequireSelfOrAdmin(opts ...Option) func(next http.Handler) http.Handler { return } if len(roleIDs) == 0 { - roleIDs = append(roleIDs, settingsService.BundleUUIDRoleUser, settingsService.SelfManagementPermissionID) + roleIDs = append(roleIDs, settings.BundleUUIDRoleUser, settings.SelfManagementPermissionID) // if roles are empty, assume we haven't seen the user before and assign a default user role. At least until // proper roles are provided. See https://github.com/owncloud/ocis/v2/issues/1825 for more context. //return user, nil diff --git a/services/proxy/pkg/command/server.go b/services/proxy/pkg/command/server.go index b52c99e74c..492a6448fc 100644 --- a/services/proxy/pkg/command/server.go +++ b/services/proxy/pkg/command/server.go @@ -17,7 +17,6 @@ import ( "github.com/owncloud/ocis/v2/ocis-pkg/log" pkgmiddleware "github.com/owncloud/ocis/v2/ocis-pkg/middleware" "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" - ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" "github.com/owncloud/ocis/v2/ocis-pkg/version" settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0" storesvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/store/v0" @@ -51,7 +50,7 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - err = ogrpc.Configure(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...) + err = grpc.Configure(grpc.GetClientOptions(cfg.GRPCClientTLS)...) if err != nil { return err } diff --git a/services/proxy/pkg/middleware/accesslog.go b/services/proxy/pkg/middleware/accesslog.go index ff5508f475..ff41eaf6b8 100644 --- a/services/proxy/pkg/middleware/accesslog.go +++ b/services/proxy/pkg/middleware/accesslog.go @@ -5,7 +5,6 @@ import ( "time" "github.com/go-chi/chi/v5/middleware" - chimiddleware "github.com/go-chi/chi/v5/middleware" "github.com/owncloud/ocis/v2/ocis-pkg/log" ) @@ -19,7 +18,7 @@ func AccessLog(logger log.Logger) func(http.Handler) http.Handler { logger.Info(). Str("proto", r.Proto). - Str(log.RequestIDString, chimiddleware.GetReqID(r.Context())). + Str(log.RequestIDString, middleware.GetReqID(r.Context())). Str("remote-addr", r.RemoteAddr). Str("method", r.Method). Int("status", wrap.Status()). diff --git a/services/proxy/pkg/server/http/server.go b/services/proxy/pkg/server/http/server.go index ce41fa3389..0f1931c2df 100644 --- a/services/proxy/pkg/server/http/server.go +++ b/services/proxy/pkg/server/http/server.go @@ -6,14 +6,13 @@ import ( pkgcrypto "github.com/owncloud/ocis/v2/ocis-pkg/crypto" "github.com/owncloud/ocis/v2/ocis-pkg/service/http" - svc "github.com/owncloud/ocis/v2/ocis-pkg/service/http" "github.com/owncloud/ocis/v2/ocis-pkg/shared" "github.com/owncloud/ocis/v2/ocis-pkg/version" "go-micro.dev/v4" ) // Server initializes the http service and server. -func Server(opts ...Option) (svc.Service, error) { +func Server(opts ...Option) (http.Service, error) { options := newOptions(opts...) l := options.Logger httpCfg := options.Config.HTTP @@ -33,19 +32,19 @@ func Server(opts ...Option) (svc.Service, error) { } chain := options.Middlewares.Then(options.Handler) - service, err := svc.NewService( - svc.Name(options.Config.Service.Name), - svc.Version(version.GetString()), + service, err := http.NewService( + http.Name(options.Config.Service.Name), + http.Version(version.GetString()), http.TLSConfig(shared.HTTPServiceTLS{ Enabled: options.Config.HTTP.TLS, Cert: options.Config.HTTP.TLSCert, Key: options.Config.HTTP.TLSKey, }), - svc.Logger(options.Logger), - svc.Address(options.Config.HTTP.Addr), - svc.Namespace(options.Config.HTTP.Namespace), - svc.Context(options.Context), - svc.Flags(options.Flags...), + http.Logger(options.Logger), + http.Address(options.Config.HTTP.Addr), + http.Namespace(options.Config.HTTP.Namespace), + http.Context(options.Context), + http.Flags(options.Flags...), ) if err != nil { options.Logger.Error(). @@ -55,7 +54,7 @@ func Server(opts ...Option) (svc.Service, error) { } if err := micro.RegisterHandler(service.Server(), chain); err != nil { - return svc.Service{}, err + return http.Service{}, err } return service, nil diff --git a/services/proxy/pkg/user/backend/cs3.go b/services/proxy/pkg/user/backend/cs3.go index bd848cc73a..13cb1bb4ed 100644 --- a/services/proxy/pkg/user/backend/cs3.go +++ b/services/proxy/pkg/user/backend/cs3.go @@ -189,7 +189,7 @@ func (c *cs3backend) CreateUserFromClaims(ctx context.Context, claims map[string if reread { c.logger.Debug().Msg("User already exist, re-reading via libregraph") gureq := lgClient.UserApi.GetUser(newctx, newUser.GetOnPremisesSamAccountName()) - created, resp, err = gureq.Execute() + created, _, err = gureq.Execute() if err != nil { c.logger.Error().Err(err).Msg("Error trying to re-read user from graphAPI") return nil, err diff --git a/services/search/pkg/service/grpc/v0/service.go b/services/search/pkg/service/grpc/v0/service.go index 925eeb6fb2..38e55d133c 100644 --- a/services/search/pkg/service/grpc/v0/service.go +++ b/services/search/pkg/service/grpc/v0/service.go @@ -11,7 +11,6 @@ import ( user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" - ctxpkg "github.com/cs3org/reva/v2/pkg/ctx" revactx "github.com/cs3org/reva/v2/pkg/ctx" "github.com/cs3org/reva/v2/pkg/errtypes" "github.com/cs3org/reva/v2/pkg/events/stream" @@ -145,7 +144,7 @@ func (s Service) Search(ctx context.Context, in *searchsvc.SearchRequest, out *s } ctx = grpcmetadata.AppendToOutgoingContext(ctx, revactx.TokenHeader, t) - u, _ := ctxpkg.ContextGetUser(ctx) + u, _ := revactx.ContextGetUser(ctx) key := cacheKey(in.Query, in.PageSize, in.Ref, u) res, ok := s.FromCache(key) if !ok {