diff --git a/assets/templates/middleware/telemetry_content b/assets/templates/middleware/telemetry_content index 7adcd36c4aef3ea9f3077fcd0771d50c34d406fb..ba993954167ae96ff87e8050b3a52aa4b74e2b4f 100644 --- a/assets/templates/middleware/telemetry_content +++ b/assets/templates/middleware/telemetry_content @@ -5,7 +5,7 @@ import ( "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - oid "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" otelmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" ) @@ -98,7 +98,7 @@ func (_d {{$decorator}}) {{$method.Declaration}} { if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } diff --git a/assets/templates/middleware/telemetry_default b/assets/templates/middleware/telemetry_default index 6616504f1f5db9bd0126eba40dd5b7f8f4d718a0..1e67da298b9287352454b1f6a95f3021d524a8af 100644 --- a/assets/templates/middleware/telemetry_default +++ b/assets/templates/middleware/telemetry_default @@ -5,7 +5,7 @@ import ( "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - oid "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" otelmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" ) @@ -63,7 +63,7 @@ func (_d {{$decorator}}) {{$method.Declaration}} { _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } diff --git a/images/middleware/telemetry_middleware.go b/images/middleware/telemetry_middleware.go index 36d09a320a2bd7fa92ceaa341fad44c89989942b..8eafa0290bfea3ec536167b6ebc64013db7aa212 100644 --- a/images/middleware/telemetry_middleware.go +++ b/images/middleware/telemetry_middleware.go @@ -10,7 +10,7 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/images" "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/files" @@ -69,7 +69,7 @@ func (_d telemetryMiddleware) Get(ctx context.Context, source *files.File, opts _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } diff --git a/logs/middleware/telemetry_middleware.go b/logs/middleware/telemetry_middleware.go index 3731386368aeb9cdd4678a1e3bd65d892798c610..c85083ee29f676321c8f6bcf445c6e5c0f8afe45 100644 --- a/logs/middleware/telemetry_middleware.go +++ b/logs/middleware/telemetry_middleware.go @@ -10,7 +10,7 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/logs" "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/options" @@ -69,7 +69,7 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, filter *logs.Filter) ( _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -108,7 +108,7 @@ func (_d telemetryMiddleware) Find(ctx context.Context, filter *logs.Filter, opt _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -149,7 +149,7 @@ func (_d telemetryMiddleware) Log(ctx context.Context, entries []*logs.Entry) (e _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } diff --git a/pkg/clients/middleware/telemetry_middleware.go b/pkg/clients/middleware/telemetry_middleware.go index cbb217153db160631a1e71ebf9d48d68cd787ebc..8925db9dc750869035423c528289ef5381c52470 100644 --- a/pkg/clients/middleware/telemetry_middleware.go +++ b/pkg/clients/middleware/telemetry_middleware.go @@ -10,7 +10,7 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/clients" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" @@ -84,7 +84,7 @@ func (_d telemetryMiddleware) Create(ctx context.Context, client *clients.Client if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -129,7 +129,7 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, id str if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -174,7 +174,7 @@ func (_d telemetryMiddleware) Enable(ctx context.Context, spaceId string, id str if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -220,7 +220,7 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, id string if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -266,7 +266,7 @@ func (_d telemetryMiddleware) GetBy(ctx context.Context, spaceId string, params if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -312,7 +312,7 @@ func (_d telemetryMiddleware) List(ctx context.Context, spaceId string) (clients if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -368,7 +368,7 @@ func (_d telemetryMiddleware) Update(ctx context.Context, client *clients.Client if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } diff --git a/pkg/collaborators/middleware/telemetry_middleware.go b/pkg/collaborators/middleware/telemetry_middleware.go index d4a6f56ccbc0d2b5334d596c8ca88932d677017b..1e53c7e1584c2d48be7642b6479bbea75bfb4615 100644 --- a/pkg/collaborators/middleware/telemetry_middleware.go +++ b/pkg/collaborators/middleware/telemetry_middleware.go @@ -10,7 +10,7 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/collaborators" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" @@ -73,7 +73,7 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, subject s if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -119,7 +119,7 @@ func (_d telemetryMiddleware) ListCollaborators(ctx context.Context, spaceId str if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -175,7 +175,7 @@ func (_d telemetryMiddleware) ListSpaces(ctx context.Context, subject string) (s if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -220,7 +220,7 @@ func (_d telemetryMiddleware) Remove(ctx context.Context, spaceId string, subjec if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -265,7 +265,7 @@ func (_d telemetryMiddleware) Set(ctx context.Context, spaceId string, subject s if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } diff --git a/pkg/collections/middleware/access_logging_middleware.go b/pkg/collections/middleware/access_logging_middleware.go index 3624955b5d3ef6201704932e623b4e8e00cc6192..0356fb8ff62a584d88f0bc6b45c6e2795657fd2c 100644 --- a/pkg/collections/middleware/access_logging_middleware.go +++ b/pkg/collections/middleware/access_logging_middleware.go @@ -32,15 +32,15 @@ func AccessLoggingMiddleware(logger *zap.Logger) Middleware { } } -func (m *accessLoggingMiddleware) Create(ctx context.Context, collection *collections.Collection) (created *collections.Collection, err error) { +func (m *accessLoggingMiddleware) Create(ctx context.Context, coll *collections.Collection) (created *collections.Collection, err error) { begin := time.Now() m.logger.Debug("Create.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), - zap.Reflect("collection", collection), + zap.Reflect("coll", coll), ) - created, err = m.next.Create(ctx, collection) + created, err = m.next.Create(ctx, coll) m.logger.Debug("Create.Response", zap.Duration("time", time.Since(begin)), @@ -51,17 +51,17 @@ func (m *accessLoggingMiddleware) Create(ctx context.Context, collection *collec return created, err } -func (m *accessLoggingMiddleware) Delete(ctx context.Context, spaceId string, envId string, collectionId string) (err error) { +func (m *accessLoggingMiddleware) Delete(ctx context.Context, spaceId string, envId string, id string) (err error) { begin := time.Now() m.logger.Debug("Delete.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), zap.Reflect("spaceId", spaceId), zap.Reflect("envId", envId), - zap.Reflect("collectionId", collectionId), + zap.Reflect("id", id), ) - err = m.next.Delete(ctx, spaceId, envId, collectionId) + err = m.next.Delete(ctx, spaceId, envId, id) m.logger.Debug("Delete.Response", zap.Duration("time", time.Since(begin)), @@ -71,29 +71,29 @@ func (m *accessLoggingMiddleware) Delete(ctx context.Context, spaceId string, en return err } -func (m *accessLoggingMiddleware) Get(ctx context.Context, spaceId string, envId string, collectionId string, options ...*collections.GetOptions) (collection *collections.Collection, err error) { +func (m *accessLoggingMiddleware) Get(ctx context.Context, spaceId string, envId string, id string, options ...*collections.GetOptions) (coll *collections.Collection, err error) { begin := time.Now() m.logger.Debug("Get.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), zap.Reflect("spaceId", spaceId), zap.Reflect("envId", envId), - zap.Reflect("collectionId", collectionId), + zap.Reflect("id", id), zap.Reflect("options", options), ) - collection, err = m.next.Get(ctx, spaceId, envId, collectionId, options...) + coll, err = m.next.Get(ctx, spaceId, envId, id, options...) m.logger.Debug("Get.Response", zap.Duration("time", time.Since(begin)), - zap.Reflect("collection", collection), + zap.Reflect("coll", coll), zap.Error(err), ) - return collection, err + return coll, err } -func (m *accessLoggingMiddleware) List(ctx context.Context, spaceId string, envId string, filter *collections.Filter) (collections []*collections.Collection, err error) { +func (m *accessLoggingMiddleware) List(ctx context.Context, spaceId string, envId string, filter *collections.Filter) (colls []*collections.Collection, err error) { begin := time.Now() m.logger.Debug("List.Request", @@ -103,29 +103,29 @@ func (m *accessLoggingMiddleware) List(ctx context.Context, spaceId string, envI zap.Reflect("filter", filter), ) - collections, err = m.next.List(ctx, spaceId, envId, filter) + colls, err = m.next.List(ctx, spaceId, envId, filter) m.logger.Debug("List.Response", zap.Duration("time", time.Since(begin)), - zap.Reflect("collections", collections), + zap.Reflect("colls", colls), zap.Error(err), ) - return collections, err + return colls, err } -func (m *accessLoggingMiddleware) SetSchema(ctx context.Context, spaceId string, envId string, collectionId string, schema *schema.Schema) (err error) { +func (m *accessLoggingMiddleware) SetSchema(ctx context.Context, spaceId string, envId string, id string, schema *schema.Schema) (err error) { begin := time.Now() m.logger.Debug("SetSchema.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), zap.Reflect("spaceId", spaceId), zap.Reflect("envId", envId), - zap.Reflect("collectionId", collectionId), + zap.Reflect("id", id), zap.Reflect("schema", schema), ) - err = m.next.SetSchema(ctx, spaceId, envId, collectionId, schema) + err = m.next.SetSchema(ctx, spaceId, envId, id, schema) m.logger.Debug("SetSchema.Response", zap.Duration("time", time.Since(begin)), @@ -135,18 +135,18 @@ func (m *accessLoggingMiddleware) SetSchema(ctx context.Context, spaceId string, return err } -func (m *accessLoggingMiddleware) SetState(ctx context.Context, spaceId string, envId string, collectionId string, state *collections.StateInfo) (err error) { +func (m *accessLoggingMiddleware) SetState(ctx context.Context, spaceId string, envId string, id string, state *collections.StateInfo) (err error) { begin := time.Now() m.logger.Debug("SetState.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), zap.Reflect("spaceId", spaceId), zap.Reflect("envId", envId), - zap.Reflect("collectionId", collectionId), + zap.Reflect("id", id), zap.Reflect("state", state), ) - err = m.next.SetState(ctx, spaceId, envId, collectionId, state) + err = m.next.SetState(ctx, spaceId, envId, id, state) m.logger.Debug("SetState.Response", zap.Duration("time", time.Since(begin)), diff --git a/pkg/collections/middleware/caching_middleware.go b/pkg/collections/middleware/caching_middleware.go index cb95d0d9a8772f91700f5f630fa9bb2631e51937..316121a393fe785956862ba033e44208df39d678 100644 --- a/pkg/collections/middleware/caching_middleware.go +++ b/pkg/collections/middleware/caching_middleware.go @@ -35,18 +35,18 @@ type cachingMiddleware struct { envs envService.Environments } -func (m cachingMiddleware) Create(ctx context.Context, collection *service.Collection) (coll *service.Collection, err error) { - return m.next.Create(ctx, collection) +func (m cachingMiddleware) Create(ctx context.Context, coll *service.Collection) (created *service.Collection, err error) { + return m.next.Create(ctx, coll) } -func (m cachingMiddleware) Get(ctx context.Context, spaceId string, envId string, collectionId string, options ...*service.GetOptions) (coll *service.Collection, err error) { +func (m cachingMiddleware) Get(ctx context.Context, spaceId string, envId string, id string, options ...*service.GetOptions) (coll *service.Collection, err error) { opts := service.MergeGetOptions(options...) - value, e := m.cache.Get(makeKey(spaceId, envId, collectionId, opts.DisableSchemaIncludes)) + value, e := m.cache.Get(makeKey(spaceId, envId, id, opts.DisableSchemaIncludes)) if e == nil { return value.(*service.Collection).Clone(), nil } - coll, err = m.next.Get(ctx, spaceId, envId, collectionId, options...) + coll, err = m.next.Get(ctx, spaceId, envId, id, options...) if err == nil { env, err := m.envs.Get(ctx, coll.SpaceID, coll.EnvID) if err != nil { @@ -61,7 +61,7 @@ func (m cachingMiddleware) Get(ctx context.Context, spaceId string, envId string return nil, err } -func (m cachingMiddleware) List(ctx context.Context, spaceId, envId string, filter *service.Filter) (collections []*service.Collection, err error) { +func (m cachingMiddleware) List(ctx context.Context, spaceId, envId string, filter *service.Filter) (colls []*service.Collection, err error) { return m.next.List(ctx, spaceId, envId, filter) } @@ -83,53 +83,53 @@ func (m cachingMiddleware) Update(ctx context.Context, coll *service.Collection) return err } -func (m cachingMiddleware) SetSchema(ctx context.Context, spaceId, envId, collectionId string, schema *schema.Schema) (err error) { - err = m.next.SetSchema(ctx, spaceId, envId, collectionId, schema) +func (m cachingMiddleware) SetSchema(ctx context.Context, spaceId, envId, id string, schema *schema.Schema) (err error) { + err = m.next.SetSchema(ctx, spaceId, envId, id, schema) if err == nil { env, err := m.envs.Get(ctx, spaceId, envId) if err != nil { return err } - _ = m.cache.Remove(makeKey(env.SpaceID, env.ID, collectionId, true)) - _ = m.cache.Remove(makeKey(env.SpaceID, env.ID, collectionId, false)) + _ = m.cache.Remove(makeKey(env.SpaceID, env.ID, id, true)) + _ = m.cache.Remove(makeKey(env.SpaceID, env.ID, id, false)) for _, al := range env.Aliases { - _ = m.cache.Remove(makeKey(env.SpaceID, al, collectionId, true)) - _ = m.cache.Remove(makeKey(env.SpaceID, al, collectionId, false)) + _ = m.cache.Remove(makeKey(env.SpaceID, al, id, true)) + _ = m.cache.Remove(makeKey(env.SpaceID, al, id, false)) } } return err } -func (m cachingMiddleware) SetState(ctx context.Context, spaceId, envId, collectionId string, state *service.StateInfo) (err error) { - err = m.next.SetState(ctx, spaceId, envId, collectionId, state) +func (m cachingMiddleware) SetState(ctx context.Context, spaceId, envId, id string, state *service.StateInfo) (err error) { + err = m.next.SetState(ctx, spaceId, envId, id, state) if err == nil { env, err := m.envs.Get(ctx, spaceId, envId) if err != nil { return err } - _ = m.cache.Remove(makeKey(env.SpaceID, env.ID, collectionId, true)) - _ = m.cache.Remove(makeKey(env.SpaceID, env.ID, collectionId, false)) + _ = m.cache.Remove(makeKey(env.SpaceID, env.ID, id, true)) + _ = m.cache.Remove(makeKey(env.SpaceID, env.ID, id, false)) for _, al := range env.Aliases { - _ = m.cache.Remove(makeKey(env.SpaceID, al, collectionId, true)) - _ = m.cache.Remove(makeKey(env.SpaceID, al, collectionId, false)) + _ = m.cache.Remove(makeKey(env.SpaceID, al, id, true)) + _ = m.cache.Remove(makeKey(env.SpaceID, al, id, false)) } } return err } -func (m cachingMiddleware) Delete(ctx context.Context, spaceId string, envId string, collectionId string) (err error) { +func (m cachingMiddleware) Delete(ctx context.Context, spaceId string, envId string, id string) (err error) { - err = m.next.Delete(ctx, spaceId, envId, collectionId) + err = m.next.Delete(ctx, spaceId, envId, id) if err == nil { env, err := m.envs.Get(ctx, spaceId, envId) if err != nil { return err } - _ = m.cache.Remove(makeKey(env.SpaceID, env.ID, collectionId, true)) - _ = m.cache.Remove(makeKey(env.SpaceID, env.ID, collectionId, false)) + _ = m.cache.Remove(makeKey(env.SpaceID, env.ID, id, true)) + _ = m.cache.Remove(makeKey(env.SpaceID, env.ID, id, false)) for _, al := range env.Aliases { - _ = m.cache.Remove(makeKey(env.SpaceID, al, collectionId, true)) - _ = m.cache.Remove(makeKey(env.SpaceID, al, collectionId, false)) + _ = m.cache.Remove(makeKey(env.SpaceID, al, id, true)) + _ = m.cache.Remove(makeKey(env.SpaceID, al, id, false)) } } return err diff --git a/pkg/collections/middleware/logging_middleware.go b/pkg/collections/middleware/logging_middleware.go index 92e2811bd2f30cd45eb0b1aa66da1d52cfbb2596..2d29c239b69791badad764d68c86ee27947e7957 100644 --- a/pkg/collections/middleware/logging_middleware.go +++ b/pkg/collections/middleware/logging_middleware.go @@ -3,7 +3,7 @@ package middleware import ( "context" - "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/collections" "git.perx.ru/perxis/perxis-go/pkg/schema" logzap "git.perx.ru/perxis/perxis-go/zap" @@ -24,19 +24,19 @@ func LoggingMiddleware(logger *zap.Logger) Middleware { } } -func (m *loggingMiddleware) Create(ctx context.Context, collection *collections.Collection) (created *collections.Collection, err error) { +func (m *loggingMiddleware) Create(ctx context.Context, coll *collections.Collection) (created *collections.Collection, err error) { var spaceID string - if collection != nil { - spaceID = collection.SpaceID + if coll != nil { + spaceID = coll.SpaceID } logger := m.logger.With( logzap.Caller(ctx, logzap.WithSpace(spaceID)), logzap.Event(collections.EventCreate), ) - created, err = m.next.Create(ctx, collection) + created, err = m.next.Create(ctx, coll) if err != nil { - logger.Error("Failed to create", zap.Error(err), logzap.Object(collection), logzap.Channels(logzap.Userlog, logzap.Syslog)) + logger.Error("Failed to create", zap.Error(err), logzap.Object(coll), logzap.Channels(logzap.Userlog, logzap.Syslog)) return } @@ -48,7 +48,7 @@ func (m *loggingMiddleware) Delete(ctx context.Context, spaceId string, envId st logger := m.logger.With( logzap.Caller(ctx, logzap.WithSpace(spaceId)), logzap.Event(collections.EventDelete), - logzap.Object(id.NewCollectionId(spaceId, envId, collectionId)), + logzap.Object(pkgId.NewCollectionId(spaceId, envId, collectionId)), ) err = m.next.Delete(ctx, spaceId, envId, collectionId) @@ -61,42 +61,42 @@ func (m *loggingMiddleware) Delete(ctx context.Context, spaceId string, envId st return err } -func (m *loggingMiddleware) Get(ctx context.Context, spaceId string, envId string, collectionId string, options ...*collections.GetOptions) (collection *collections.Collection, err error) { +func (m *loggingMiddleware) Get(ctx context.Context, spaceId string, envId string, id string, options ...*collections.GetOptions) (coll *collections.Collection, err error) { logger := m.logger.With( logzap.Caller(ctx, logzap.WithSpace(spaceId)), ) - collection, err = m.next.Get(ctx, spaceId, envId, collectionId, options...) + coll, err = m.next.Get(ctx, spaceId, envId, id, options...) if err != nil { logger.Error("Failed to get", zap.Error(err)) return } - return collection, err + return coll, err } -func (m *loggingMiddleware) List(ctx context.Context, spaceId string, envId string, filter *collections.Filter) (collections []*collections.Collection, err error) { +func (m *loggingMiddleware) List(ctx context.Context, spaceId string, envId string, filter *collections.Filter) (colls []*collections.Collection, err error) { logger := m.logger.With( logzap.Caller(ctx, logzap.WithSpace(spaceId)), ) - collections, err = m.next.List(ctx, spaceId, envId, filter) + colls, err = m.next.List(ctx, spaceId, envId, filter) if err != nil { logger.Error("Failed to list", zap.Error(err)) return } - return collections, err + return colls, err } -func (m *loggingMiddleware) SetSchema(ctx context.Context, spaceId string, envId string, collectionId string, schema *schema.Schema) (err error) { +func (m *loggingMiddleware) SetSchema(ctx context.Context, spaceId string, envId string, id string, schema *schema.Schema) (err error) { logger := m.logger.With( logzap.Caller(ctx, logzap.WithSpace(spaceId)), logzap.Event(collections.EventSetSchema), - logzap.Object(id.NewCollectionId(spaceId, envId, collectionId)), + logzap.Object(pkgId.NewCollectionId(spaceId, envId, id)), ) - err = m.next.SetSchema(ctx, spaceId, envId, collectionId, schema) + err = m.next.SetSchema(ctx, spaceId, envId, id, schema) if err != nil { logger.Error("Failed to set schema", zap.Error(err), logzap.Channels(logzap.Userlog, logzap.Syslog)) return @@ -106,12 +106,12 @@ func (m *loggingMiddleware) SetSchema(ctx context.Context, spaceId string, envId return err } -func (m *loggingMiddleware) SetState(ctx context.Context, spaceId string, envId string, collectionId string, state *collections.StateInfo) (err error) { +func (m *loggingMiddleware) SetState(ctx context.Context, spaceId string, envId string, id string, state *collections.StateInfo) (err error) { logger := m.logger.With( logzap.Caller(ctx, logzap.WithSpace(spaceId)), ) - err = m.next.SetState(ctx, spaceId, envId, collectionId, state) + err = m.next.SetState(ctx, spaceId, envId, id, state) if err != nil { logger.Error("Failed to set state", zap.Error(err)) return diff --git a/pkg/collections/middleware/recovering_middleware.go b/pkg/collections/middleware/recovering_middleware.go index 6f5594bcfd097d8ffa9132768f7f9538f6edf9da..f72f48f6eea75b0d5ec2d093dae5149395870cae 100644 --- a/pkg/collections/middleware/recovering_middleware.go +++ b/pkg/collections/middleware/recovering_middleware.go @@ -31,7 +31,7 @@ func RecoveringMiddleware(logger *zap.Logger) Middleware { } } -func (m *recoveringMiddleware) Create(ctx context.Context, collection *collections.Collection) (created *collections.Collection, err error) { +func (m *recoveringMiddleware) Create(ctx context.Context, coll *collections.Collection) (created *collections.Collection, err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -40,10 +40,10 @@ func (m *recoveringMiddleware) Create(ctx context.Context, collection *collectio } }() - return m.next.Create(ctx, collection) + return m.next.Create(ctx, coll) } -func (m *recoveringMiddleware) Delete(ctx context.Context, spaceId string, envId string, collectionId string) (err error) { +func (m *recoveringMiddleware) Delete(ctx context.Context, spaceId string, envId string, id string) (err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -52,10 +52,10 @@ func (m *recoveringMiddleware) Delete(ctx context.Context, spaceId string, envId } }() - return m.next.Delete(ctx, spaceId, envId, collectionId) + return m.next.Delete(ctx, spaceId, envId, id) } -func (m *recoveringMiddleware) Get(ctx context.Context, spaceId string, envId string, collectionId string, options ...*collections.GetOptions) (collection *collections.Collection, err error) { +func (m *recoveringMiddleware) Get(ctx context.Context, spaceId string, envId string, id string, options ...*collections.GetOptions) (coll *collections.Collection, err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -64,10 +64,10 @@ func (m *recoveringMiddleware) Get(ctx context.Context, spaceId string, envId st } }() - return m.next.Get(ctx, spaceId, envId, collectionId, options...) + return m.next.Get(ctx, spaceId, envId, id, options...) } -func (m *recoveringMiddleware) List(ctx context.Context, spaceId string, envId string, filter *collections.Filter) (collections []*collections.Collection, err error) { +func (m *recoveringMiddleware) List(ctx context.Context, spaceId string, envId string, filter *collections.Filter) (colls []*collections.Collection, err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -79,7 +79,7 @@ func (m *recoveringMiddleware) List(ctx context.Context, spaceId string, envId s return m.next.List(ctx, spaceId, envId, filter) } -func (m *recoveringMiddleware) SetSchema(ctx context.Context, spaceId string, envId string, collectionId string, schema *schema.Schema) (err error) { +func (m *recoveringMiddleware) SetSchema(ctx context.Context, spaceId string, envId string, id string, schema *schema.Schema) (err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -88,10 +88,10 @@ func (m *recoveringMiddleware) SetSchema(ctx context.Context, spaceId string, en } }() - return m.next.SetSchema(ctx, spaceId, envId, collectionId, schema) + return m.next.SetSchema(ctx, spaceId, envId, id, schema) } -func (m *recoveringMiddleware) SetState(ctx context.Context, spaceId string, envId string, collectionId string, state *collections.StateInfo) (err error) { +func (m *recoveringMiddleware) SetState(ctx context.Context, spaceId string, envId string, id string, state *collections.StateInfo) (err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -100,7 +100,7 @@ func (m *recoveringMiddleware) SetState(ctx context.Context, spaceId string, env } }() - return m.next.SetState(ctx, spaceId, envId, collectionId, state) + return m.next.SetState(ctx, spaceId, envId, id, state) } func (m *recoveringMiddleware) Update(ctx context.Context, coll *collections.Collection) (err error) { diff --git a/pkg/collections/middleware/telemetry_middleware.go b/pkg/collections/middleware/telemetry_middleware.go index c189a7bebaf727b818aa3f37ecb828ff89de6391..dba2f3436ac669c19a213153b049224de62854e0 100644 --- a/pkg/collections/middleware/telemetry_middleware.go +++ b/pkg/collections/middleware/telemetry_middleware.go @@ -10,7 +10,7 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/collections" "git.perx.ru/perxis/perxis-go/pkg/schema" @@ -54,7 +54,7 @@ func TelemetryMiddleware(base collections.Collections, instance string, spanDeco } // Create implements collections.Collections -func (_d telemetryMiddleware) Create(ctx context.Context, collection *collections.Collection) (created *collections.Collection, err error) { +func (_d telemetryMiddleware) Create(ctx context.Context, coll *collections.Collection) (created *collections.Collection, err error) { var att = []attribute.KeyValue{ attribute.String("service", "Collections"), attribute.String("method", "Create"), @@ -65,12 +65,12 @@ func (_d telemetryMiddleware) Create(ctx context.Context, collection *collection ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Collections.Create") defer _span.End() - created, err = _d.Collections.Create(ctx, collection) + created, err = _d.Collections.Create(ctx, coll) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) var spID string - params := []interface{}{ctx, collection, created, err} + params := []interface{}{ctx, coll, created, err} for _, p := range params { if p == nil { continue @@ -85,7 +85,7 @@ func (_d telemetryMiddleware) Create(ctx context.Context, collection *collection if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -94,8 +94,8 @@ func (_d telemetryMiddleware) Create(ctx context.Context, collection *collection if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ - "ctx": ctx, - "collection": collection}, map[string]interface{}{ + "ctx": ctx, + "coll": coll}, map[string]interface{}{ "created": created, "err": err}) } else if err != nil { @@ -110,7 +110,7 @@ func (_d telemetryMiddleware) Create(ctx context.Context, collection *collection } // Delete implements collections.Collections -func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, envId string, collectionId string) (err error) { +func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, envId string, id string) (err error) { var att = []attribute.KeyValue{ attribute.String("service", "Collections"), attribute.String("method", "Delete"), @@ -121,7 +121,7 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, envId ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Collections.Delete") defer _span.End() - err = _d.Collections.Delete(ctx, spaceId, envId, collectionId) + err = _d.Collections.Delete(ctx, spaceId, envId, id) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) @@ -130,7 +130,7 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, envId if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -139,10 +139,10 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, envId if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ - "ctx": ctx, - "spaceId": spaceId, - "envId": envId, - "collectionId": collectionId}, map[string]interface{}{ + "ctx": ctx, + "spaceId": spaceId, + "envId": envId, + "id": id}, map[string]interface{}{ "err": err}) } else if err != nil { _d.requestMetrics.FailedTotal.Add(ctx, 1, attributes) @@ -156,7 +156,7 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, envId } // Get implements collections.Collections -func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId string, collectionId string, options ...*collections.GetOptions) (collection *collections.Collection, err error) { +func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId string, id string, options ...*collections.GetOptions) (coll *collections.Collection, err error) { var att = []attribute.KeyValue{ attribute.String("service", "Collections"), attribute.String("method", "Get"), @@ -167,7 +167,7 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId str ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Collections.Get") defer _span.End() - collection, err = _d.Collections.Get(ctx, spaceId, envId, collectionId, options...) + coll, err = _d.Collections.Get(ctx, spaceId, envId, id, options...) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) @@ -176,7 +176,7 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId str if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -185,13 +185,13 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId str if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ - "ctx": ctx, - "spaceId": spaceId, - "envId": envId, - "collectionId": collectionId, - "options": options}, map[string]interface{}{ - "collection": collection, - "err": err}) + "ctx": ctx, + "spaceId": spaceId, + "envId": envId, + "id": id, + "options": options}, map[string]interface{}{ + "coll": coll, + "err": err}) } else if err != nil { _d.requestMetrics.FailedTotal.Add(ctx, 1, attributes) @@ -200,11 +200,11 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId str _span.SetAttributes(attribute.String("message", err.Error())) } - return collection, err + return coll, err } // List implements collections.Collections -func (_d telemetryMiddleware) List(ctx context.Context, spaceId string, envId string, filter *collections.Filter) (collections []*collections.Collection, err error) { +func (_d telemetryMiddleware) List(ctx context.Context, spaceId string, envId string, filter *collections.Filter) (colls []*collections.Collection, err error) { var att = []attribute.KeyValue{ attribute.String("service", "Collections"), attribute.String("method", "List"), @@ -215,7 +215,7 @@ func (_d telemetryMiddleware) List(ctx context.Context, spaceId string, envId st ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Collections.List") defer _span.End() - collections, err = _d.Collections.List(ctx, spaceId, envId, filter) + colls, err = _d.Collections.List(ctx, spaceId, envId, filter) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) @@ -224,7 +224,7 @@ func (_d telemetryMiddleware) List(ctx context.Context, spaceId string, envId st if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -237,8 +237,8 @@ func (_d telemetryMiddleware) List(ctx context.Context, spaceId string, envId st "spaceId": spaceId, "envId": envId, "filter": filter}, map[string]interface{}{ - "collections": collections, - "err": err}) + "colls": colls, + "err": err}) } else if err != nil { _d.requestMetrics.FailedTotal.Add(ctx, 1, attributes) @@ -247,11 +247,11 @@ func (_d telemetryMiddleware) List(ctx context.Context, spaceId string, envId st _span.SetAttributes(attribute.String("message", err.Error())) } - return collections, err + return colls, err } // SetSchema implements collections.Collections -func (_d telemetryMiddleware) SetSchema(ctx context.Context, spaceId string, envId string, collectionId string, schema *schema.Schema) (err error) { +func (_d telemetryMiddleware) SetSchema(ctx context.Context, spaceId string, envId string, id string, schema *schema.Schema) (err error) { var att = []attribute.KeyValue{ attribute.String("service", "Collections"), attribute.String("method", "SetSchema"), @@ -262,7 +262,7 @@ func (_d telemetryMiddleware) SetSchema(ctx context.Context, spaceId string, env ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Collections.SetSchema") defer _span.End() - err = _d.Collections.SetSchema(ctx, spaceId, envId, collectionId, schema) + err = _d.Collections.SetSchema(ctx, spaceId, envId, id, schema) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) @@ -271,7 +271,7 @@ func (_d telemetryMiddleware) SetSchema(ctx context.Context, spaceId string, env if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -280,11 +280,11 @@ func (_d telemetryMiddleware) SetSchema(ctx context.Context, spaceId string, env if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ - "ctx": ctx, - "spaceId": spaceId, - "envId": envId, - "collectionId": collectionId, - "schema": schema}, map[string]interface{}{ + "ctx": ctx, + "spaceId": spaceId, + "envId": envId, + "id": id, + "schema": schema}, map[string]interface{}{ "err": err}) } else if err != nil { _d.requestMetrics.FailedTotal.Add(ctx, 1, attributes) @@ -298,7 +298,7 @@ func (_d telemetryMiddleware) SetSchema(ctx context.Context, spaceId string, env } // SetState implements collections.Collections -func (_d telemetryMiddleware) SetState(ctx context.Context, spaceId string, envId string, collectionId string, state *collections.StateInfo) (err error) { +func (_d telemetryMiddleware) SetState(ctx context.Context, spaceId string, envId string, id string, state *collections.StateInfo) (err error) { var att = []attribute.KeyValue{ attribute.String("service", "Collections"), attribute.String("method", "SetState"), @@ -309,7 +309,7 @@ func (_d telemetryMiddleware) SetState(ctx context.Context, spaceId string, envI ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Collections.SetState") defer _span.End() - err = _d.Collections.SetState(ctx, spaceId, envId, collectionId, state) + err = _d.Collections.SetState(ctx, spaceId, envId, id, state) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) @@ -318,7 +318,7 @@ func (_d telemetryMiddleware) SetState(ctx context.Context, spaceId string, envI if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -327,11 +327,11 @@ func (_d telemetryMiddleware) SetState(ctx context.Context, spaceId string, envI if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ - "ctx": ctx, - "spaceId": spaceId, - "envId": envId, - "collectionId": collectionId, - "state": state}, map[string]interface{}{ + "ctx": ctx, + "spaceId": spaceId, + "envId": envId, + "id": id, + "state": state}, map[string]interface{}{ "err": err}) } else if err != nil { _d.requestMetrics.FailedTotal.Add(ctx, 1, attributes) @@ -376,7 +376,7 @@ func (_d telemetryMiddleware) Update(ctx context.Context, coll *collections.Coll if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } diff --git a/pkg/collections/mocks/CollectionCreatedObserver.go b/pkg/collections/mocks/CollectionCreatedObserver.go index 55b38993e7a3ed0d92c4d7f16047834caeb4ef3e..608a183443412663c3ee354fb5eefcaabb95b526 100644 --- a/pkg/collections/mocks/CollectionCreatedObserver.go +++ b/pkg/collections/mocks/CollectionCreatedObserver.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -19,6 +19,10 @@ type CollectionCreatedObserver struct { func (_m *CollectionCreatedObserver) OnCollectionCreated(ctx context.Context, coll *collections.Collection) (string, error) { ret := _m.Called(ctx, coll) + if len(ret) == 0 { + panic("no return value specified for OnCollectionCreated") + } + var r0 string var r1 error if rf, ok := ret.Get(0).(func(context.Context, *collections.Collection) (string, error)); ok { diff --git a/pkg/collections/mocks/CollectionDeletedObserver.go b/pkg/collections/mocks/CollectionDeletedObserver.go index a529def57ce8131e20ad9d03fc00d4038b318fff..be29d3e0efddbab4ca9276aa92f9ef2f64ab7150 100644 --- a/pkg/collections/mocks/CollectionDeletedObserver.go +++ b/pkg/collections/mocks/CollectionDeletedObserver.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -19,6 +19,10 @@ type CollectionDeletedObserver struct { func (_m *CollectionDeletedObserver) OnCollectionDeleted(ctx context.Context, coll *collections.Collection) (string, error) { ret := _m.Called(ctx, coll) + if len(ret) == 0 { + panic("no return value specified for OnCollectionDeleted") + } + var r0 string var r1 error if rf, ok := ret.Get(0).(func(context.Context, *collections.Collection) (string, error)); ok { diff --git a/pkg/collections/mocks/CollectionPreSetSchemaObserver.go b/pkg/collections/mocks/CollectionPreSetSchemaObserver.go new file mode 100644 index 0000000000000000000000000000000000000000..fe9c6159dcfb7c01d8538d5497e220c5dcb1fbcc --- /dev/null +++ b/pkg/collections/mocks/CollectionPreSetSchemaObserver.go @@ -0,0 +1,58 @@ +// Code generated by mockery v2.46.3. DO NOT EDIT. + +package mocks + +import ( + context "context" + + collections "git.perx.ru/perxis/perxis-go/pkg/collections" + + mock "github.com/stretchr/testify/mock" +) + +// CollectionPreSetSchemaObserver is an autogenerated mock type for the CollectionPreSetSchemaObserver type +type CollectionPreSetSchemaObserver struct { + mock.Mock +} + +// OnCollectionPreSetSchema provides a mock function with given fields: ctx, before, coll +func (_m *CollectionPreSetSchemaObserver) OnCollectionPreSetSchema(ctx context.Context, before *collections.Collection, coll *collections.Collection) (string, error) { + ret := _m.Called(ctx, before, coll) + + if len(ret) == 0 { + panic("no return value specified for OnCollectionPreSetSchema") + } + + var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *collections.Collection, *collections.Collection) (string, error)); ok { + return rf(ctx, before, coll) + } + if rf, ok := ret.Get(0).(func(context.Context, *collections.Collection, *collections.Collection) string); ok { + r0 = rf(ctx, before, coll) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(context.Context, *collections.Collection, *collections.Collection) error); ok { + r1 = rf(ctx, before, coll) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewCollectionPreSetSchemaObserver creates a new instance of CollectionPreSetSchemaObserver. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewCollectionPreSetSchemaObserver(t interface { + mock.TestingT + Cleanup(func()) +}) *CollectionPreSetSchemaObserver { + mock := &CollectionPreSetSchemaObserver{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/collections/mocks/CollectionPreUpdateObserver.go b/pkg/collections/mocks/CollectionPreUpdateObserver.go index 6d1fa2f25c1bb46e8143495a368ac44650375b79..38c4f55fa322d2a00d662621703b4656290e408e 100644 --- a/pkg/collections/mocks/CollectionPreUpdateObserver.go +++ b/pkg/collections/mocks/CollectionPreUpdateObserver.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -19,6 +19,10 @@ type CollectionPreUpdateObserver struct { func (_m *CollectionPreUpdateObserver) OnCollectionPreUpdate(ctx context.Context, before *collections.Collection, coll *collections.Collection) (string, error) { ret := _m.Called(ctx, before, coll) + if len(ret) == 0 { + panic("no return value specified for OnCollectionPreUpdate") + } + var r0 string var r1 error if rf, ok := ret.Get(0).(func(context.Context, *collections.Collection, *collections.Collection) (string, error)); ok { diff --git a/pkg/collections/mocks/CollectionSetSchemaObserver.go b/pkg/collections/mocks/CollectionSetSchemaObserver.go index 5453aef6abf21f03075b5be16fd2e252e736d0e2..5b7e9d9a4bc2b758011e694c8760249b3386c006 100644 --- a/pkg/collections/mocks/CollectionSetSchemaObserver.go +++ b/pkg/collections/mocks/CollectionSetSchemaObserver.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -19,6 +19,10 @@ type CollectionSetSchemaObserver struct { func (_m *CollectionSetSchemaObserver) OnCollectionSetSchema(ctx context.Context, before *collections.Collection, coll *collections.Collection) (string, error) { ret := _m.Called(ctx, before, coll) + if len(ret) == 0 { + panic("no return value specified for OnCollectionSetSchema") + } + var r0 string var r1 error if rf, ok := ret.Get(0).(func(context.Context, *collections.Collection, *collections.Collection) (string, error)); ok { diff --git a/pkg/collections/mocks/CollectionUpdatedObserver.go b/pkg/collections/mocks/CollectionUpdatedObserver.go index 4a0dc34dd9abeab91d1e2219d75fddceecc1fa5b..79593e37d1388aeeaec285bbb8c9142f896714b2 100644 --- a/pkg/collections/mocks/CollectionUpdatedObserver.go +++ b/pkg/collections/mocks/CollectionUpdatedObserver.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -19,6 +19,10 @@ type CollectionUpdatedObserver struct { func (_m *CollectionUpdatedObserver) OnCollectionUpdated(ctx context.Context, before *collections.Collection, after *collections.Collection) (string, error) { ret := _m.Called(ctx, before, after) + if len(ret) == 0 { + panic("no return value specified for OnCollectionUpdated") + } + var r0 string var r1 error if rf, ok := ret.Get(0).(func(context.Context, *collections.Collection, *collections.Collection) (string, error)); ok { diff --git a/pkg/collections/mocks/Collections.go b/pkg/collections/mocks/Collections.go index 9a0a67f6dba82b5e7343dba1f0cc152ce82acb6a..33c6af548469a06df6f07026eca95e0a6fad4fe8 100644 --- a/pkg/collections/mocks/Collections.go +++ b/pkg/collections/mocks/Collections.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -17,17 +17,21 @@ type Collections struct { mock.Mock } -// Create provides a mock function with given fields: ctx, collection -func (_m *Collections) Create(ctx context.Context, collection *collections.Collection) (*collections.Collection, error) { - ret := _m.Called(ctx, collection) +// Create provides a mock function with given fields: ctx, coll +func (_m *Collections) Create(ctx context.Context, coll *collections.Collection) (*collections.Collection, error) { + ret := _m.Called(ctx, coll) + + if len(ret) == 0 { + panic("no return value specified for Create") + } var r0 *collections.Collection var r1 error if rf, ok := ret.Get(0).(func(context.Context, *collections.Collection) (*collections.Collection, error)); ok { - return rf(ctx, collection) + return rf(ctx, coll) } if rf, ok := ret.Get(0).(func(context.Context, *collections.Collection) *collections.Collection); ok { - r0 = rf(ctx, collection) + r0 = rf(ctx, coll) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*collections.Collection) @@ -35,7 +39,7 @@ func (_m *Collections) Create(ctx context.Context, collection *collections.Colle } if rf, ok := ret.Get(1).(func(context.Context, *collections.Collection) error); ok { - r1 = rf(ctx, collection) + r1 = rf(ctx, coll) } else { r1 = ret.Error(1) } @@ -43,13 +47,17 @@ func (_m *Collections) Create(ctx context.Context, collection *collections.Colle return r0, r1 } -// Delete provides a mock function with given fields: ctx, spaceId, envId, collectionId -func (_m *Collections) Delete(ctx context.Context, spaceId string, envId string, collectionId string) error { - ret := _m.Called(ctx, spaceId, envId, collectionId) +// Delete provides a mock function with given fields: ctx, spaceId, envId, id +func (_m *Collections) Delete(ctx context.Context, spaceId string, envId string, id string) error { + ret := _m.Called(ctx, spaceId, envId, id) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, string, string) error); ok { - r0 = rf(ctx, spaceId, envId, collectionId) + r0 = rf(ctx, spaceId, envId, id) } else { r0 = ret.Error(0) } @@ -57,24 +65,28 @@ func (_m *Collections) Delete(ctx context.Context, spaceId string, envId string, return r0 } -// Get provides a mock function with given fields: ctx, spaceId, envId, collectionId, options -func (_m *Collections) Get(ctx context.Context, spaceId string, envId string, collectionId string, options ...*collections.GetOptions) (*collections.Collection, error) { +// Get provides a mock function with given fields: ctx, spaceId, envId, id, options +func (_m *Collections) Get(ctx context.Context, spaceId string, envId string, id string, options ...*collections.GetOptions) (*collections.Collection, error) { _va := make([]interface{}, len(options)) for _i := range options { _va[_i] = options[_i] } var _ca []interface{} - _ca = append(_ca, ctx, spaceId, envId, collectionId) + _ca = append(_ca, ctx, spaceId, envId, id) _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for Get") + } + var r0 *collections.Collection var r1 error if rf, ok := ret.Get(0).(func(context.Context, string, string, string, ...*collections.GetOptions) (*collections.Collection, error)); ok { - return rf(ctx, spaceId, envId, collectionId, options...) + return rf(ctx, spaceId, envId, id, options...) } if rf, ok := ret.Get(0).(func(context.Context, string, string, string, ...*collections.GetOptions) *collections.Collection); ok { - r0 = rf(ctx, spaceId, envId, collectionId, options...) + r0 = rf(ctx, spaceId, envId, id, options...) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*collections.Collection) @@ -82,7 +94,7 @@ func (_m *Collections) Get(ctx context.Context, spaceId string, envId string, co } if rf, ok := ret.Get(1).(func(context.Context, string, string, string, ...*collections.GetOptions) error); ok { - r1 = rf(ctx, spaceId, envId, collectionId, options...) + r1 = rf(ctx, spaceId, envId, id, options...) } else { r1 = ret.Error(1) } @@ -94,6 +106,10 @@ func (_m *Collections) Get(ctx context.Context, spaceId string, envId string, co func (_m *Collections) List(ctx context.Context, spaceId string, envId string, filter *collections.Filter) ([]*collections.Collection, error) { ret := _m.Called(ctx, spaceId, envId, filter) + if len(ret) == 0 { + panic("no return value specified for List") + } + var r0 []*collections.Collection var r1 error if rf, ok := ret.Get(0).(func(context.Context, string, string, *collections.Filter) ([]*collections.Collection, error)); ok { @@ -116,13 +132,17 @@ func (_m *Collections) List(ctx context.Context, spaceId string, envId string, f return r0, r1 } -// SetSchema provides a mock function with given fields: ctx, spaceId, envId, collectionId, _a4 -func (_m *Collections) SetSchema(ctx context.Context, spaceId string, envId string, collectionId string, _a4 *schema.Schema) error { - ret := _m.Called(ctx, spaceId, envId, collectionId, _a4) +// SetSchema provides a mock function with given fields: ctx, spaceId, envId, id, _a4 +func (_m *Collections) SetSchema(ctx context.Context, spaceId string, envId string, id string, _a4 *schema.Schema) error { + ret := _m.Called(ctx, spaceId, envId, id, _a4) + + if len(ret) == 0 { + panic("no return value specified for SetSchema") + } var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, string, string, *schema.Schema) error); ok { - r0 = rf(ctx, spaceId, envId, collectionId, _a4) + r0 = rf(ctx, spaceId, envId, id, _a4) } else { r0 = ret.Error(0) } @@ -130,13 +150,17 @@ func (_m *Collections) SetSchema(ctx context.Context, spaceId string, envId stri return r0 } -// SetState provides a mock function with given fields: ctx, spaceId, envId, collectionId, state -func (_m *Collections) SetState(ctx context.Context, spaceId string, envId string, collectionId string, state *collections.StateInfo) error { - ret := _m.Called(ctx, spaceId, envId, collectionId, state) +// SetState provides a mock function with given fields: ctx, spaceId, envId, id, state +func (_m *Collections) SetState(ctx context.Context, spaceId string, envId string, id string, state *collections.StateInfo) error { + ret := _m.Called(ctx, spaceId, envId, id, state) + + if len(ret) == 0 { + panic("no return value specified for SetState") + } var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, string, string, *collections.StateInfo) error); ok { - r0 = rf(ctx, spaceId, envId, collectionId, state) + r0 = rf(ctx, spaceId, envId, id, state) } else { r0 = ret.Error(0) } @@ -148,6 +172,10 @@ func (_m *Collections) SetState(ctx context.Context, spaceId string, envId strin func (_m *Collections) Update(ctx context.Context, coll *collections.Collection) error { ret := _m.Called(ctx, coll) + if len(ret) == 0 { + panic("no return value specified for Update") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, *collections.Collection) error); ok { r0 = rf(ctx, coll) diff --git a/pkg/collections/mocks/Middleware.go b/pkg/collections/mocks/Middleware.go index 761a6f460bf8a54c406f7137a903782cd01b9486..6f2cfa5d6cb08d5fd58be7c43959b7cd85e06209 100644 --- a/pkg/collections/mocks/Middleware.go +++ b/pkg/collections/mocks/Middleware.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -17,6 +17,10 @@ type Middleware struct { func (_m *Middleware) Execute(_a0 collections.Collections) collections.Collections { ret := _m.Called(_a0) + if len(ret) == 0 { + panic("no return value specified for Execute") + } + var r0 collections.Collections if rf, ok := ret.Get(0).(func(collections.Collections) collections.Collections); ok { r0 = rf(_a0) diff --git a/pkg/collections/mocks/Storage.go b/pkg/collections/mocks/Storage.go index 7e4bdb4a9f9b3c7632c8157750ada779aa10223c..e5c05c6b6e22a9355af58b3620026f8ad6ded544 100644 --- a/pkg/collections/mocks/Storage.go +++ b/pkg/collections/mocks/Storage.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -19,6 +19,10 @@ type Storage struct { func (_m *Storage) Create(ctx context.Context, coll *collections.Collection) (*collections.Collection, error) { ret := _m.Called(ctx, coll) + if len(ret) == 0 { + panic("no return value specified for Create") + } + var r0 *collections.Collection var r1 error if rf, ok := ret.Get(0).(func(context.Context, *collections.Collection) (*collections.Collection, error)); ok { @@ -45,6 +49,10 @@ func (_m *Storage) Create(ctx context.Context, coll *collections.Collection) (*c func (_m *Storage) Delete(ctx context.Context, spaceId string, envId string, collectionId string) error { ret := _m.Called(ctx, spaceId, envId, collectionId) + if len(ret) == 0 { + panic("no return value specified for Delete") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, string, string) error); ok { r0 = rf(ctx, spaceId, envId, collectionId) @@ -59,6 +67,10 @@ func (_m *Storage) Delete(ctx context.Context, spaceId string, envId string, col func (_m *Storage) Get(ctx context.Context, spaceId string, envId string, collectionId string) (*collections.Collection, error) { ret := _m.Called(ctx, spaceId, envId, collectionId) + if len(ret) == 0 { + panic("no return value specified for Get") + } + var r0 *collections.Collection var r1 error if rf, ok := ret.Get(0).(func(context.Context, string, string, string) (*collections.Collection, error)); ok { @@ -85,6 +97,10 @@ func (_m *Storage) Get(ctx context.Context, spaceId string, envId string, collec func (_m *Storage) Init(ctx context.Context, spaceID string, envID string) error { ret := _m.Called(ctx, spaceID, envID) + if len(ret) == 0 { + panic("no return value specified for Init") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, string) error); ok { r0 = rf(ctx, spaceID, envID) @@ -99,6 +115,10 @@ func (_m *Storage) Init(ctx context.Context, spaceID string, envID string) error func (_m *Storage) List(ctx context.Context, spaceId string, envId string, filter *collections.Filter) ([]*collections.Collection, error) { ret := _m.Called(ctx, spaceId, envId, filter) + if len(ret) == 0 { + panic("no return value specified for List") + } + var r0 []*collections.Collection var r1 error if rf, ok := ret.Get(0).(func(context.Context, string, string, *collections.Filter) ([]*collections.Collection, error)); ok { @@ -125,6 +145,10 @@ func (_m *Storage) List(ctx context.Context, spaceId string, envId string, filte func (_m *Storage) Reset(ctx context.Context, spaceId string, envId string) error { ret := _m.Called(ctx, spaceId, envId) + if len(ret) == 0 { + panic("no return value specified for Reset") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, string) error); ok { r0 = rf(ctx, spaceId, envId) @@ -139,6 +163,10 @@ func (_m *Storage) Reset(ctx context.Context, spaceId string, envId string) erro func (_m *Storage) Update(ctx context.Context, coll *collections.Collection) (int, int, error) { ret := _m.Called(ctx, coll) + if len(ret) == 0 { + panic("no return value specified for Update") + } + var r0 int var r1 int var r2 error diff --git a/pkg/collections/mocks/spaceGetter.go b/pkg/collections/mocks/spaceGetter.go new file mode 100644 index 0000000000000000000000000000000000000000..0dfa462e8b1af6c8feeee2bed7cd7e4c1317d0b1 --- /dev/null +++ b/pkg/collections/mocks/spaceGetter.go @@ -0,0 +1,42 @@ +// Code generated by mockery v2.46.3. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// spaceGetter is an autogenerated mock type for the spaceGetter type +type spaceGetter struct { + mock.Mock +} + +// GetSpaceID provides a mock function with given fields: +func (_m *spaceGetter) GetSpaceID() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetSpaceID") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// newSpaceGetter creates a new instance of spaceGetter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newSpaceGetter(t interface { + mock.TestingT + Cleanup(func()) +}) *spaceGetter { + mock := &spaceGetter{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/collections/service.go b/pkg/collections/service.go index 362c9dc70885fab37fc06b3d3dd033ae63be0436..6c65f3f1c10718f6a5873f3184a65ea676e56a30 100644 --- a/pkg/collections/service.go +++ b/pkg/collections/service.go @@ -10,15 +10,15 @@ import ( // @protobuf git.perx.ru/perxis/perxis-go/proto/collections // @grpc-addr content.collections.Collections type Collections interface { - Create(ctx context.Context, collection *Collection) (created *Collection, err error) - Get(ctx context.Context, spaceId, envId, collectionId string, options ...*GetOptions) (collection *Collection, err error) - List(ctx context.Context, spaceId, envId string, filter *Filter) (collections []*Collection, err error) + Create(ctx context.Context, coll *Collection) (created *Collection, err error) + Get(ctx context.Context, spaceId, envId, id string, options ...*GetOptions) (coll *Collection, err error) + List(ctx context.Context, spaceId, envId string, filter *Filter) (colls []*Collection, err error) Update(ctx context.Context, coll *Collection) (err error) - SetSchema(ctx context.Context, spaceId, envId, collectionId string, schema *schema.Schema) (err error) + SetSchema(ctx context.Context, spaceId, envId, id string, schema *schema.Schema) (err error) // @microgen - - SetState(ctx context.Context, spaceId, envId, collectionId string, state *StateInfo) (err error) - Delete(ctx context.Context, spaceId, envId, collectionId string) (err error) + SetState(ctx context.Context, spaceId, envId, id string, state *StateInfo) (err error) + Delete(ctx context.Context, spaceId, envId, id string) (err error) } type Filter struct { diff --git a/pkg/delivery/middleware/telemetry_middleware.go b/pkg/delivery/middleware/telemetry_middleware.go index 600b6a61caec8391507735e01d12d82ee822c8e3..276d3f62ff5d91c78d30aa07b79b4ee37c785a04 100644 --- a/pkg/delivery/middleware/telemetry_middleware.go +++ b/pkg/delivery/middleware/telemetry_middleware.go @@ -10,7 +10,7 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/collections" "git.perx.ru/perxis/perxis-go/pkg/delivery" @@ -77,7 +77,7 @@ func (_d telemetryMiddleware) Aggregate(ctx context.Context, spaceId string, env if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -126,7 +126,7 @@ func (_d telemetryMiddleware) FindItems(ctx context.Context, spaceId string, env if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -176,7 +176,7 @@ func (_d telemetryMiddleware) GetCollection(ctx context.Context, spaceId string, if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -223,7 +223,7 @@ func (_d telemetryMiddleware) GetEnvironment(ctx context.Context, spaceId string if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -269,7 +269,7 @@ func (_d telemetryMiddleware) GetItem(ctx context.Context, spaceId string, envId if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -318,7 +318,7 @@ func (_d telemetryMiddleware) ListCollections(ctx context.Context, spaceId strin if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -364,7 +364,7 @@ func (_d telemetryMiddleware) ListEnvironments(ctx context.Context, spaceId stri if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -409,7 +409,7 @@ func (_d telemetryMiddleware) ListLocales(ctx context.Context, spaceId string) ( if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } diff --git a/pkg/environments/middleware/access_logging_middleware.go b/pkg/environments/middleware/access_logging_middleware.go index e357e2ec9786edb9f67a7b14445558f86938e924..dd4f27bfce0dfcbe57e03be47b319436b42234f9 100644 --- a/pkg/environments/middleware/access_logging_middleware.go +++ b/pkg/environments/middleware/access_logging_middleware.go @@ -50,16 +50,16 @@ func (m *accessLoggingMiddleware) Create(ctx context.Context, env *environments. return created, err } -func (m *accessLoggingMiddleware) Delete(ctx context.Context, spaceId string, envId string) (err error) { +func (m *accessLoggingMiddleware) Delete(ctx context.Context, spaceId string, id string) (err error) { begin := time.Now() m.logger.Debug("Delete.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), zap.Reflect("spaceId", spaceId), - zap.Reflect("envId", envId), + zap.Reflect("id", id), ) - err = m.next.Delete(ctx, spaceId, envId) + err = m.next.Delete(ctx, spaceId, id) m.logger.Debug("Delete.Response", zap.Duration("time", time.Since(begin)), @@ -69,16 +69,16 @@ func (m *accessLoggingMiddleware) Delete(ctx context.Context, spaceId string, en return err } -func (m *accessLoggingMiddleware) Get(ctx context.Context, spaceId string, envId string) (env *environments.Environment, err error) { +func (m *accessLoggingMiddleware) Get(ctx context.Context, spaceId string, id string) (env *environments.Environment, err error) { begin := time.Now() m.logger.Debug("Get.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), zap.Reflect("spaceId", spaceId), - zap.Reflect("envId", envId), + zap.Reflect("id", id), ) - env, err = m.next.Get(ctx, spaceId, envId) + env, err = m.next.Get(ctx, spaceId, id) m.logger.Debug("Get.Response", zap.Duration("time", time.Since(begin)), @@ -108,17 +108,17 @@ func (m *accessLoggingMiddleware) List(ctx context.Context, spaceId string) (env return envs, err } -func (m *accessLoggingMiddleware) Migrate(ctx context.Context, spaceId string, envId string, options ...*environments.MigrateOptions) (err error) { +func (m *accessLoggingMiddleware) Migrate(ctx context.Context, spaceId string, id string, options ...*environments.MigrateOptions) (err error) { begin := time.Now() m.logger.Debug("Migrate.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), zap.Reflect("spaceId", spaceId), - zap.Reflect("envId", envId), + zap.Reflect("id", id), zap.Reflect("options", options), ) - err = m.next.Migrate(ctx, spaceId, envId, options...) + err = m.next.Migrate(ctx, spaceId, id, options...) m.logger.Debug("Migrate.Response", zap.Duration("time", time.Since(begin)), @@ -128,17 +128,17 @@ func (m *accessLoggingMiddleware) Migrate(ctx context.Context, spaceId string, e return err } -func (m *accessLoggingMiddleware) RemoveAlias(ctx context.Context, spaceId string, envId string, alias string) (err error) { +func (m *accessLoggingMiddleware) RemoveAlias(ctx context.Context, spaceId string, id string, alias string) (err error) { begin := time.Now() m.logger.Debug("RemoveAlias.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), zap.Reflect("spaceId", spaceId), - zap.Reflect("envId", envId), + zap.Reflect("id", id), zap.Reflect("alias", alias), ) - err = m.next.RemoveAlias(ctx, spaceId, envId, alias) + err = m.next.RemoveAlias(ctx, spaceId, id, alias) m.logger.Debug("RemoveAlias.Response", zap.Duration("time", time.Since(begin)), @@ -148,17 +148,17 @@ func (m *accessLoggingMiddleware) RemoveAlias(ctx context.Context, spaceId strin return err } -func (m *accessLoggingMiddleware) SetAlias(ctx context.Context, spaceId string, envId string, alias string) (err error) { +func (m *accessLoggingMiddleware) SetAlias(ctx context.Context, spaceId string, id string, alias string) (err error) { begin := time.Now() m.logger.Debug("SetAlias.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), zap.Reflect("spaceId", spaceId), - zap.Reflect("envId", envId), + zap.Reflect("id", id), zap.Reflect("alias", alias), ) - err = m.next.SetAlias(ctx, spaceId, envId, alias) + err = m.next.SetAlias(ctx, spaceId, id, alias) m.logger.Debug("SetAlias.Response", zap.Duration("time", time.Since(begin)), diff --git a/pkg/environments/middleware/caching_middleware.go b/pkg/environments/middleware/caching_middleware.go index c53f45e8bdcdb61f59f1af0acf11bc0f412c2629..ffcd85b8486fae49851160af8d6e4b6e7795efe9 100644 --- a/pkg/environments/middleware/caching_middleware.go +++ b/pkg/environments/middleware/caching_middleware.go @@ -27,42 +27,42 @@ type cachingMiddleware struct { next service.Environments } -func (m cachingMiddleware) Create(ctx context.Context, env *service.Environment) (environment *service.Environment, err error) { +func (m cachingMiddleware) Create(ctx context.Context, env *service.Environment) (created *service.Environment, err error) { - environment, err = m.next.Create(ctx, env) + created, err = m.next.Create(ctx, env) if err == nil { - _ = m.cache.Remove(environment.SpaceID) + _ = m.cache.Remove(created.SpaceID) } - return environment, err + return created, err } -func (m cachingMiddleware) Get(ctx context.Context, spaceId string, envId string) (environment *service.Environment, err error) { +func (m cachingMiddleware) Get(ctx context.Context, spaceId string, id string) (env *service.Environment, err error) { - value, e := m.cache.Get(makeKey(spaceId, envId)) + value, e := m.cache.Get(makeKey(spaceId, id)) if e == nil { return value.(*service.Environment).Clone(), nil } - environment, err = m.next.Get(ctx, spaceId, envId) + env, err = m.next.Get(ctx, spaceId, id) if err == nil { - _ = m.cache.Set(makeKey(spaceId, environment.ID), environment) - for _, a := range environment.Aliases { - _ = m.cache.Set(makeKey(spaceId, a), environment) + _ = m.cache.Set(makeKey(spaceId, env.ID), env) + for _, a := range env.Aliases { + _ = m.cache.Set(makeKey(spaceId, a), env) } - return environment.Clone(), nil + return env.Clone(), nil } return nil, err } -func (m cachingMiddleware) List(ctx context.Context, spaceId string) (environments []*service.Environment, err error) { +func (m cachingMiddleware) List(ctx context.Context, spaceId string) (envs []*service.Environment, err error) { value, e := m.cache.Get(spaceId) if e == nil { return data.CloneSlice(value.([]*service.Environment)), nil } - environments, err = m.next.List(ctx, spaceId) + envs, err = m.next.List(ctx, spaceId) if err == nil { - _ = m.cache.Set(spaceId, environments) - return data.CloneSlice(environments), nil + _ = m.cache.Set(spaceId, envs) + return data.CloneSlice(envs), nil } return nil, err } @@ -84,11 +84,11 @@ func (m cachingMiddleware) Update(ctx context.Context, env *service.Environment) return err } -func (m cachingMiddleware) Delete(ctx context.Context, spaceId string, envId string) (err error) { +func (m cachingMiddleware) Delete(ctx context.Context, spaceId string, id string) (err error) { - err = m.next.Delete(ctx, spaceId, envId) + err = m.next.Delete(ctx, spaceId, id) if err == nil { - value, e := m.cache.Get(makeKey(spaceId, envId)) + value, e := m.cache.Get(makeKey(spaceId, id)) if e == nil { env := value.(*service.Environment) _ = m.cache.Remove(makeKey(env.SpaceID, env.ID)) @@ -101,9 +101,9 @@ func (m cachingMiddleware) Delete(ctx context.Context, spaceId string, envId str return err } -func (m cachingMiddleware) SetAlias(ctx context.Context, spaceId string, envId string, alias string) (err error) { +func (m cachingMiddleware) SetAlias(ctx context.Context, spaceId string, id string, alias string) (err error) { - err = m.next.SetAlias(ctx, spaceId, envId, alias) + err = m.next.SetAlias(ctx, spaceId, id, alias) if err == nil { value, e := m.cache.Get(makeKey(spaceId, alias)) if e == nil { @@ -114,7 +114,7 @@ func (m cachingMiddleware) SetAlias(ctx context.Context, spaceId string, envId s } } - value, e = m.cache.Get(makeKey(spaceId, envId)) + value, e = m.cache.Get(makeKey(spaceId, id)) if e == nil { env := value.(*service.Environment) _ = m.cache.Remove(makeKey(env.SpaceID, env.ID)) @@ -127,9 +127,9 @@ func (m cachingMiddleware) SetAlias(ctx context.Context, spaceId string, envId s return err } -func (m cachingMiddleware) RemoveAlias(ctx context.Context, spaceId string, envId string, alias string) (err error) { +func (m cachingMiddleware) RemoveAlias(ctx context.Context, spaceId string, id string, alias string) (err error) { - err = m.next.RemoveAlias(ctx, spaceId, envId, alias) + err = m.next.RemoveAlias(ctx, spaceId, id, alias) if err == nil { _ = m.cache.Remove(spaceId) value, e := m.cache.Get(makeKey(spaceId, alias)) @@ -141,7 +141,7 @@ func (m cachingMiddleware) RemoveAlias(ctx context.Context, spaceId string, envI } } - value, e = m.cache.Get(makeKey(spaceId, envId)) + value, e = m.cache.Get(makeKey(spaceId, id)) if e == nil { env := value.(*service.Environment) _ = m.cache.Remove(makeKey(env.SpaceID, env.ID)) @@ -153,11 +153,11 @@ func (m cachingMiddleware) RemoveAlias(ctx context.Context, spaceId string, envI return err } -func (m cachingMiddleware) Migrate(ctx context.Context, spaceId, envId string, options ...*service.MigrateOptions) (err error) { - err = m.next.Migrate(ctx, spaceId, envId, options...) +func (m cachingMiddleware) Migrate(ctx context.Context, spaceId, id string, options ...*service.MigrateOptions) (err error) { + err = m.next.Migrate(ctx, spaceId, id, options...) // значение из кÑша удалить вне завиÑимоÑти от Ð½Ð°Ð»Ð¸Ñ‡Ð¸Ñ Ð¾ÑˆÐ¸Ð±ÐºÐ¸, поÑкольку ÑоÑтоÑние Ð¾ÐºÑ€ÑƒÐ¶ÐµÐ½Ð¸Ñ Ð¼Ð¾Ð³Ð»Ð¾ изменитьÑÑ - value, e := m.cache.Get(makeKey(spaceId, envId)) + value, e := m.cache.Get(makeKey(spaceId, id)) if e == nil { env := value.(*service.Environment) _ = m.cache.Remove(makeKey(env.SpaceID, env.ID)) diff --git a/pkg/environments/middleware/error_logging_middleware.go b/pkg/environments/middleware/error_logging_middleware.go index 812de4033878fe1c6d774730c68d2e6e00489751..4a5656e20329b10ab50d8c3888b5015590d8d929 100644 --- a/pkg/environments/middleware/error_logging_middleware.go +++ b/pkg/environments/middleware/error_logging_middleware.go @@ -39,24 +39,24 @@ func (m *errorLoggingMiddleware) Create(ctx context.Context, env *environments.E return m.next.Create(ctx, env) } -func (m *errorLoggingMiddleware) Delete(ctx context.Context, spaceId string, envId string) (err error) { +func (m *errorLoggingMiddleware) Delete(ctx context.Context, spaceId string, id string) (err error) { logger := m.logger defer func() { if err != nil { logger.Warn("response error", zap.Error(err)) } }() - return m.next.Delete(ctx, spaceId, envId) + return m.next.Delete(ctx, spaceId, id) } -func (m *errorLoggingMiddleware) Get(ctx context.Context, spaceId string, envId string) (env *environments.Environment, err error) { +func (m *errorLoggingMiddleware) Get(ctx context.Context, spaceId string, id string) (env *environments.Environment, err error) { logger := m.logger defer func() { if err != nil { logger.Warn("response error", zap.Error(err)) } }() - return m.next.Get(ctx, spaceId, envId) + return m.next.Get(ctx, spaceId, id) } func (m *errorLoggingMiddleware) List(ctx context.Context, spaceId string) (envs []*environments.Environment, err error) { @@ -69,34 +69,34 @@ func (m *errorLoggingMiddleware) List(ctx context.Context, spaceId string) (envs return m.next.List(ctx, spaceId) } -func (m *errorLoggingMiddleware) Migrate(ctx context.Context, spaceId string, envId string, options ...*environments.MigrateOptions) (err error) { +func (m *errorLoggingMiddleware) Migrate(ctx context.Context, spaceId string, id string, options ...*environments.MigrateOptions) (err error) { logger := m.logger defer func() { if err != nil { logger.Warn("response error", zap.Error(err)) } }() - return m.next.Migrate(ctx, spaceId, envId, options...) + return m.next.Migrate(ctx, spaceId, id, options...) } -func (m *errorLoggingMiddleware) RemoveAlias(ctx context.Context, spaceId string, envId string, alias string) (err error) { +func (m *errorLoggingMiddleware) RemoveAlias(ctx context.Context, spaceId string, id string, alias string) (err error) { logger := m.logger defer func() { if err != nil { logger.Warn("response error", zap.Error(err)) } }() - return m.next.RemoveAlias(ctx, spaceId, envId, alias) + return m.next.RemoveAlias(ctx, spaceId, id, alias) } -func (m *errorLoggingMiddleware) SetAlias(ctx context.Context, spaceId string, envId string, alias string) (err error) { +func (m *errorLoggingMiddleware) SetAlias(ctx context.Context, spaceId string, id string, alias string) (err error) { logger := m.logger defer func() { if err != nil { logger.Warn("response error", zap.Error(err)) } }() - return m.next.SetAlias(ctx, spaceId, envId, alias) + return m.next.SetAlias(ctx, spaceId, id, alias) } func (m *errorLoggingMiddleware) Update(ctx context.Context, env *environments.Environment) (err error) { diff --git a/pkg/environments/middleware/logging_middleware.go b/pkg/environments/middleware/logging_middleware.go index 2cb0112956df53f7d89c489427997e35ddad2c96..86a73c2af541dbb30b243e1cfbce5e1a46e5556a 100644 --- a/pkg/environments/middleware/logging_middleware.go +++ b/pkg/environments/middleware/logging_middleware.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/environments" logzap "git.perx.ru/perxis/perxis-go/zap" @@ -42,14 +42,14 @@ func (m *loggingMiddleware) Create(ctx context.Context, env *environments.Enviro return created, err } -func (m *loggingMiddleware) Delete(ctx context.Context, spaceId string, envId string) (err error) { +func (m *loggingMiddleware) Delete(ctx context.Context, spaceId string, id string) (err error) { logger := m.logger.With( logzap.Caller(ctx), logzap.Event(environments.EventDelete), - logzap.Object(id.NewEnvironmentId(spaceId, envId)), + logzap.Object(pkgId.NewEnvironmentId(spaceId, id)), ) - err = m.next.Delete(ctx, spaceId, envId) + err = m.next.Delete(ctx, spaceId, id) if err != nil { logger.Error("Failed to delete", zap.Error(err), logzap.Channels(logzap.Userlog, logzap.Syslog)) return @@ -60,13 +60,13 @@ func (m *loggingMiddleware) Delete(ctx context.Context, spaceId string, envId st return err } -func (m *loggingMiddleware) Get(ctx context.Context, spaceId string, envId string) (env *environments.Environment, err error) { +func (m *loggingMiddleware) Get(ctx context.Context, spaceId string, id string) (env *environments.Environment, err error) { logger := m.logger.With( logzap.Caller(ctx), - logzap.Object(id.NewEnvironmentId(spaceId, envId)), + logzap.Object(pkgId.NewEnvironmentId(spaceId, id)), ) - env, err = m.next.Get(ctx, spaceId, envId) + env, err = m.next.Get(ctx, spaceId, id) if err != nil { logger.Error("Failed to get", zap.Error(err)) return @@ -89,14 +89,14 @@ func (m *loggingMiddleware) List(ctx context.Context, spaceId string) (envs []*e return envs, err } -func (m *loggingMiddleware) Migrate(ctx context.Context, spaceId string, envId string, options ...*environments.MigrateOptions) (err error) { +func (m *loggingMiddleware) Migrate(ctx context.Context, spaceId string, id string, options ...*environments.MigrateOptions) (err error) { logger := m.logger.With( logzap.Caller(ctx), logzap.Event(environments.EventMigrate), - logzap.Object(id.NewEnvironmentId(spaceId, envId)), + logzap.Object(pkgId.NewEnvironmentId(spaceId, id)), ) - err = m.next.Migrate(ctx, spaceId, envId, options...) + err = m.next.Migrate(ctx, spaceId, id, options...) if err != nil { logger.Error("Failed to migrate", zap.Error(err), logzap.Channels(logzap.Userlog, logzap.Syslog)) return @@ -107,14 +107,14 @@ func (m *loggingMiddleware) Migrate(ctx context.Context, spaceId string, envId s return err } -func (m *loggingMiddleware) RemoveAlias(ctx context.Context, spaceId string, envId string, alias string) (err error) { +func (m *loggingMiddleware) RemoveAlias(ctx context.Context, spaceId string, id string, alias string) (err error) { logger := m.logger.With( logzap.Caller(ctx), logzap.Event(environments.EventUpdate), - logzap.Object(id.NewEnvironmentId(spaceId, envId)), + logzap.Object(pkgId.NewEnvironmentId(spaceId, id)), ) - err = m.next.RemoveAlias(ctx, spaceId, envId, alias) + err = m.next.RemoveAlias(ctx, spaceId, id, alias) if err != nil { logger.Error(fmt.Sprintf("Failed to remove alias '%s'", alias), zap.Error(err), logzap.Channels(logzap.Userlog, logzap.Syslog)) return @@ -124,14 +124,14 @@ func (m *loggingMiddleware) RemoveAlias(ctx context.Context, spaceId string, env return err } -func (m *loggingMiddleware) SetAlias(ctx context.Context, spaceId string, envId string, alias string) (err error) { +func (m *loggingMiddleware) SetAlias(ctx context.Context, spaceId string, id string, alias string) (err error) { logger := m.logger.With( logzap.Caller(ctx), logzap.Event(environments.EventUpdate), - logzap.Object(id.NewEnvironmentId(spaceId, envId)), + logzap.Object(pkgId.NewEnvironmentId(spaceId, id)), ) - err = m.next.SetAlias(ctx, spaceId, envId, alias) + err = m.next.SetAlias(ctx, spaceId, id, alias) if err != nil { logger.Error(fmt.Sprintf("Failed to set alias '%s'", alias), zap.Error(err), logzap.Channels(logzap.Userlog, logzap.Syslog)) return diff --git a/pkg/environments/middleware/recovering_middleware.go b/pkg/environments/middleware/recovering_middleware.go index 57a59406a38b7051e2ff65d7ca6e41f198e562a6..6e07a8790191b9cea2053cc9663cac7f525d0933 100644 --- a/pkg/environments/middleware/recovering_middleware.go +++ b/pkg/environments/middleware/recovering_middleware.go @@ -42,7 +42,7 @@ func (m *recoveringMiddleware) Create(ctx context.Context, env *environments.Env return m.next.Create(ctx, env) } -func (m *recoveringMiddleware) Delete(ctx context.Context, spaceId string, envId string) (err error) { +func (m *recoveringMiddleware) Delete(ctx context.Context, spaceId string, id string) (err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -51,10 +51,10 @@ func (m *recoveringMiddleware) Delete(ctx context.Context, spaceId string, envId } }() - return m.next.Delete(ctx, spaceId, envId) + return m.next.Delete(ctx, spaceId, id) } -func (m *recoveringMiddleware) Get(ctx context.Context, spaceId string, envId string) (env *environments.Environment, err error) { +func (m *recoveringMiddleware) Get(ctx context.Context, spaceId string, id string) (env *environments.Environment, err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -63,7 +63,7 @@ func (m *recoveringMiddleware) Get(ctx context.Context, spaceId string, envId st } }() - return m.next.Get(ctx, spaceId, envId) + return m.next.Get(ctx, spaceId, id) } func (m *recoveringMiddleware) List(ctx context.Context, spaceId string) (envs []*environments.Environment, err error) { @@ -78,7 +78,7 @@ func (m *recoveringMiddleware) List(ctx context.Context, spaceId string) (envs [ return m.next.List(ctx, spaceId) } -func (m *recoveringMiddleware) Migrate(ctx context.Context, spaceId string, envId string, options ...*environments.MigrateOptions) (err error) { +func (m *recoveringMiddleware) Migrate(ctx context.Context, spaceId string, id string, options ...*environments.MigrateOptions) (err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -87,10 +87,10 @@ func (m *recoveringMiddleware) Migrate(ctx context.Context, spaceId string, envI } }() - return m.next.Migrate(ctx, spaceId, envId, options...) + return m.next.Migrate(ctx, spaceId, id, options...) } -func (m *recoveringMiddleware) RemoveAlias(ctx context.Context, spaceId string, envId string, alias string) (err error) { +func (m *recoveringMiddleware) RemoveAlias(ctx context.Context, spaceId string, id string, alias string) (err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -99,10 +99,10 @@ func (m *recoveringMiddleware) RemoveAlias(ctx context.Context, spaceId string, } }() - return m.next.RemoveAlias(ctx, spaceId, envId, alias) + return m.next.RemoveAlias(ctx, spaceId, id, alias) } -func (m *recoveringMiddleware) SetAlias(ctx context.Context, spaceId string, envId string, alias string) (err error) { +func (m *recoveringMiddleware) SetAlias(ctx context.Context, spaceId string, id string, alias string) (err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -111,7 +111,7 @@ func (m *recoveringMiddleware) SetAlias(ctx context.Context, spaceId string, env } }() - return m.next.SetAlias(ctx, spaceId, envId, alias) + return m.next.SetAlias(ctx, spaceId, id, alias) } func (m *recoveringMiddleware) Update(ctx context.Context, env *environments.Environment) (err error) { diff --git a/pkg/environments/middleware/telemetry_middleware.go b/pkg/environments/middleware/telemetry_middleware.go index f1fb94c767248ac3db42617e9f8c0475ddcece64..94c90c2f7bf47b0519604375c3a7f8dd6dbdc144 100644 --- a/pkg/environments/middleware/telemetry_middleware.go +++ b/pkg/environments/middleware/telemetry_middleware.go @@ -10,7 +10,7 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/environments" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" @@ -84,7 +84,7 @@ func (_d telemetryMiddleware) Create(ctx context.Context, env *environments.Envi if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -109,7 +109,7 @@ func (_d telemetryMiddleware) Create(ctx context.Context, env *environments.Envi } // Delete implements environments.Environments -func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, envId string) (err error) { +func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, id string) (err error) { var att = []attribute.KeyValue{ attribute.String("service", "Environments"), attribute.String("method", "Delete"), @@ -120,7 +120,7 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, envId ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Environments.Delete") defer _span.End() - err = _d.Environments.Delete(ctx, spaceId, envId) + err = _d.Environments.Delete(ctx, spaceId, id) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) @@ -129,7 +129,7 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, envId if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -140,7 +140,7 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, envId _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, "spaceId": spaceId, - "envId": envId}, map[string]interface{}{ + "id": id}, map[string]interface{}{ "err": err}) } else if err != nil { _d.requestMetrics.FailedTotal.Add(ctx, 1, attributes) @@ -154,7 +154,7 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, envId } // Get implements environments.Environments -func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId string) (env *environments.Environment, err error) { +func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, id string) (env *environments.Environment, err error) { var att = []attribute.KeyValue{ attribute.String("service", "Environments"), attribute.String("method", "Get"), @@ -165,7 +165,7 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId str ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Environments.Get") defer _span.End() - env, err = _d.Environments.Get(ctx, spaceId, envId) + env, err = _d.Environments.Get(ctx, spaceId, id) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) @@ -174,7 +174,7 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId str if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -185,7 +185,7 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId str _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, "spaceId": spaceId, - "envId": envId}, map[string]interface{}{ + "id": id}, map[string]interface{}{ "env": env, "err": err}) } else if err != nil { @@ -220,7 +220,7 @@ func (_d telemetryMiddleware) List(ctx context.Context, spaceId string) (envs [] if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -245,7 +245,7 @@ func (_d telemetryMiddleware) List(ctx context.Context, spaceId string) (envs [] } // Migrate implements environments.Environments -func (_d telemetryMiddleware) Migrate(ctx context.Context, spaceId string, envId string, options ...*environments.MigrateOptions) (err error) { +func (_d telemetryMiddleware) Migrate(ctx context.Context, spaceId string, id string, options ...*environments.MigrateOptions) (err error) { var att = []attribute.KeyValue{ attribute.String("service", "Environments"), attribute.String("method", "Migrate"), @@ -256,7 +256,7 @@ func (_d telemetryMiddleware) Migrate(ctx context.Context, spaceId string, envId ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Environments.Migrate") defer _span.End() - err = _d.Environments.Migrate(ctx, spaceId, envId, options...) + err = _d.Environments.Migrate(ctx, spaceId, id, options...) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) @@ -265,7 +265,7 @@ func (_d telemetryMiddleware) Migrate(ctx context.Context, spaceId string, envId if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -276,7 +276,7 @@ func (_d telemetryMiddleware) Migrate(ctx context.Context, spaceId string, envId _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, "spaceId": spaceId, - "envId": envId, + "id": id, "options": options}, map[string]interface{}{ "err": err}) } else if err != nil { @@ -291,7 +291,7 @@ func (_d telemetryMiddleware) Migrate(ctx context.Context, spaceId string, envId } // RemoveAlias implements environments.Environments -func (_d telemetryMiddleware) RemoveAlias(ctx context.Context, spaceId string, envId string, alias string) (err error) { +func (_d telemetryMiddleware) RemoveAlias(ctx context.Context, spaceId string, id string, alias string) (err error) { var att = []attribute.KeyValue{ attribute.String("service", "Environments"), attribute.String("method", "RemoveAlias"), @@ -302,7 +302,7 @@ func (_d telemetryMiddleware) RemoveAlias(ctx context.Context, spaceId string, e ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Environments.RemoveAlias") defer _span.End() - err = _d.Environments.RemoveAlias(ctx, spaceId, envId, alias) + err = _d.Environments.RemoveAlias(ctx, spaceId, id, alias) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) @@ -311,7 +311,7 @@ func (_d telemetryMiddleware) RemoveAlias(ctx context.Context, spaceId string, e if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -322,7 +322,7 @@ func (_d telemetryMiddleware) RemoveAlias(ctx context.Context, spaceId string, e _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, "spaceId": spaceId, - "envId": envId, + "id": id, "alias": alias}, map[string]interface{}{ "err": err}) } else if err != nil { @@ -337,7 +337,7 @@ func (_d telemetryMiddleware) RemoveAlias(ctx context.Context, spaceId string, e } // SetAlias implements environments.Environments -func (_d telemetryMiddleware) SetAlias(ctx context.Context, spaceId string, envId string, alias string) (err error) { +func (_d telemetryMiddleware) SetAlias(ctx context.Context, spaceId string, id string, alias string) (err error) { var att = []attribute.KeyValue{ attribute.String("service", "Environments"), attribute.String("method", "SetAlias"), @@ -348,7 +348,7 @@ func (_d telemetryMiddleware) SetAlias(ctx context.Context, spaceId string, envI ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Environments.SetAlias") defer _span.End() - err = _d.Environments.SetAlias(ctx, spaceId, envId, alias) + err = _d.Environments.SetAlias(ctx, spaceId, id, alias) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) @@ -357,7 +357,7 @@ func (_d telemetryMiddleware) SetAlias(ctx context.Context, spaceId string, envI if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -368,7 +368,7 @@ func (_d telemetryMiddleware) SetAlias(ctx context.Context, spaceId string, envI _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, "spaceId": spaceId, - "envId": envId, + "id": id, "alias": alias}, map[string]interface{}{ "err": err}) } else if err != nil { @@ -414,7 +414,7 @@ func (_d telemetryMiddleware) Update(ctx context.Context, env *environments.Envi if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } diff --git a/pkg/environments/mocks/EnvironmentConfigurationObserver.go b/pkg/environments/mocks/EnvironmentConfigurationObserver.go index 32c8efd8b78c3e7af8e4d1d887223329fd76a43a..fc3518c4754014146fd0bae68edd85b798c93c61 100644 --- a/pkg/environments/mocks/EnvironmentConfigurationObserver.go +++ b/pkg/environments/mocks/EnvironmentConfigurationObserver.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -18,6 +18,10 @@ type EnvironmentConfigurationObserver struct { func (_m *EnvironmentConfigurationObserver) OnEnvironmentConfiguration(ctx context.Context, before *environments.Environment, after *environments.Environment) error { ret := _m.Called(ctx, before, after) + if len(ret) == 0 { + panic("no return value specified for OnEnvironmentConfiguration") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, *environments.Environment, *environments.Environment) error); ok { r0 = rf(ctx, before, after) diff --git a/pkg/environments/mocks/EnvironmentCreatedObserver.go b/pkg/environments/mocks/EnvironmentCreatedObserver.go index 6bed116a9a28f1ad913eed0abb0cd2f2b2931548..0420cff22f1ea4e6f94072d7cbeb10a2a7bdddda 100644 --- a/pkg/environments/mocks/EnvironmentCreatedObserver.go +++ b/pkg/environments/mocks/EnvironmentCreatedObserver.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -18,6 +18,10 @@ type EnvironmentCreatedObserver struct { func (_m *EnvironmentCreatedObserver) OnEnvironmentCreated(ctx context.Context, env *environments.Environment) (string, error) { ret := _m.Called(ctx, env) + if len(ret) == 0 { + panic("no return value specified for OnEnvironmentCreated") + } + var r0 string var r1 error if rf, ok := ret.Get(0).(func(context.Context, *environments.Environment) (string, error)); ok { diff --git a/pkg/environments/mocks/EnvironmentDeletedObserver.go b/pkg/environments/mocks/EnvironmentDeletedObserver.go index 1a101f04be093b1b48e89d8173c969beebb66754..3f559b8e5c87f8834a5f2b50761bfbc73701011e 100644 --- a/pkg/environments/mocks/EnvironmentDeletedObserver.go +++ b/pkg/environments/mocks/EnvironmentDeletedObserver.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -18,6 +18,10 @@ type EnvironmentDeletedObserver struct { func (_m *EnvironmentDeletedObserver) OnEnvironmentDeleted(ctx context.Context, env *environments.Environment) error { ret := _m.Called(ctx, env) + if len(ret) == 0 { + panic("no return value specified for OnEnvironmentDeleted") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, *environments.Environment) error); ok { r0 = rf(ctx, env) diff --git a/pkg/environments/mocks/EnvironmentMigratedObserver.go b/pkg/environments/mocks/EnvironmentMigratedObserver.go index c529a8b81f9caecbb4d78b4d10079f406dc88bf6..c1a01bd8e98fdd10bb4764e1f05f6626ef6731e7 100644 --- a/pkg/environments/mocks/EnvironmentMigratedObserver.go +++ b/pkg/environments/mocks/EnvironmentMigratedObserver.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -18,6 +18,10 @@ type EnvironmentMigratedObserver struct { func (_m *EnvironmentMigratedObserver) OnEnvironmentMigrated(ctx context.Context, env *environments.Environment) error { ret := _m.Called(ctx, env) + if len(ret) == 0 { + panic("no return value specified for OnEnvironmentMigrated") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, *environments.Environment) error); ok { r0 = rf(ctx, env) diff --git a/pkg/environments/mocks/EnvironmentUpdatedObserver.go b/pkg/environments/mocks/EnvironmentUpdatedObserver.go index 75073188aeb89593bf12555d9ada3a7cc9ec7837..4d9493a0658c23744347ec8199c1b36d1f67dc9c 100644 --- a/pkg/environments/mocks/EnvironmentUpdatedObserver.go +++ b/pkg/environments/mocks/EnvironmentUpdatedObserver.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -18,6 +18,10 @@ type EnvironmentUpdatedObserver struct { func (_m *EnvironmentUpdatedObserver) OnEnvironmentUpdated(ctx context.Context, before *environments.Environment, after *environments.Environment) error { ret := _m.Called(ctx, before, after) + if len(ret) == 0 { + panic("no return value specified for OnEnvironmentUpdated") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, *environments.Environment, *environments.Environment) error); ok { r0 = rf(ctx, before, after) diff --git a/pkg/environments/mocks/Environments.go b/pkg/environments/mocks/Environments.go index 22da5d024c9cd43506a35e6e11a264fff9189a54..0f22798e121d216c5efe7dcaf2d71e0dffe9e1d8 100644 --- a/pkg/environments/mocks/Environments.go +++ b/pkg/environments/mocks/Environments.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -18,6 +18,10 @@ type Environments struct { func (_m *Environments) Create(ctx context.Context, env *environments.Environment) (*environments.Environment, error) { ret := _m.Called(ctx, env) + if len(ret) == 0 { + panic("no return value specified for Create") + } + var r0 *environments.Environment var r1 error if rf, ok := ret.Get(0).(func(context.Context, *environments.Environment) (*environments.Environment, error)); ok { @@ -40,13 +44,17 @@ func (_m *Environments) Create(ctx context.Context, env *environments.Environmen return r0, r1 } -// Delete provides a mock function with given fields: ctx, spaceId, envId -func (_m *Environments) Delete(ctx context.Context, spaceId string, envId string) error { - ret := _m.Called(ctx, spaceId, envId) +// Delete provides a mock function with given fields: ctx, spaceId, id +func (_m *Environments) Delete(ctx context.Context, spaceId string, id string) error { + ret := _m.Called(ctx, spaceId, id) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, string) error); ok { - r0 = rf(ctx, spaceId, envId) + r0 = rf(ctx, spaceId, id) } else { r0 = ret.Error(0) } @@ -54,17 +62,21 @@ func (_m *Environments) Delete(ctx context.Context, spaceId string, envId string return r0 } -// Get provides a mock function with given fields: ctx, spaceId, envId -func (_m *Environments) Get(ctx context.Context, spaceId string, envId string) (*environments.Environment, error) { - ret := _m.Called(ctx, spaceId, envId) +// Get provides a mock function with given fields: ctx, spaceId, id +func (_m *Environments) Get(ctx context.Context, spaceId string, id string) (*environments.Environment, error) { + ret := _m.Called(ctx, spaceId, id) + + if len(ret) == 0 { + panic("no return value specified for Get") + } var r0 *environments.Environment var r1 error if rf, ok := ret.Get(0).(func(context.Context, string, string) (*environments.Environment, error)); ok { - return rf(ctx, spaceId, envId) + return rf(ctx, spaceId, id) } if rf, ok := ret.Get(0).(func(context.Context, string, string) *environments.Environment); ok { - r0 = rf(ctx, spaceId, envId) + r0 = rf(ctx, spaceId, id) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*environments.Environment) @@ -72,7 +84,7 @@ func (_m *Environments) Get(ctx context.Context, spaceId string, envId string) ( } if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { - r1 = rf(ctx, spaceId, envId) + r1 = rf(ctx, spaceId, id) } else { r1 = ret.Error(1) } @@ -84,6 +96,10 @@ func (_m *Environments) Get(ctx context.Context, spaceId string, envId string) ( func (_m *Environments) List(ctx context.Context, spaceId string) ([]*environments.Environment, error) { ret := _m.Called(ctx, spaceId) + if len(ret) == 0 { + panic("no return value specified for List") + } + var r0 []*environments.Environment var r1 error if rf, ok := ret.Get(0).(func(context.Context, string) ([]*environments.Environment, error)); ok { @@ -106,20 +122,24 @@ func (_m *Environments) List(ctx context.Context, spaceId string) ([]*environmen return r0, r1 } -// Migrate provides a mock function with given fields: ctx, spaceId, envId, options -func (_m *Environments) Migrate(ctx context.Context, spaceId string, envId string, options ...*environments.MigrateOptions) error { +// Migrate provides a mock function with given fields: ctx, spaceId, id, options +func (_m *Environments) Migrate(ctx context.Context, spaceId string, id string, options ...*environments.MigrateOptions) error { _va := make([]interface{}, len(options)) for _i := range options { _va[_i] = options[_i] } var _ca []interface{} - _ca = append(_ca, ctx, spaceId, envId) + _ca = append(_ca, ctx, spaceId, id) _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for Migrate") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, string, ...*environments.MigrateOptions) error); ok { - r0 = rf(ctx, spaceId, envId, options...) + r0 = rf(ctx, spaceId, id, options...) } else { r0 = ret.Error(0) } @@ -127,13 +147,17 @@ func (_m *Environments) Migrate(ctx context.Context, spaceId string, envId strin return r0 } -// RemoveAlias provides a mock function with given fields: ctx, spaceId, envId, alias -func (_m *Environments) RemoveAlias(ctx context.Context, spaceId string, envId string, alias string) error { - ret := _m.Called(ctx, spaceId, envId, alias) +// RemoveAlias provides a mock function with given fields: ctx, spaceId, id, alias +func (_m *Environments) RemoveAlias(ctx context.Context, spaceId string, id string, alias string) error { + ret := _m.Called(ctx, spaceId, id, alias) + + if len(ret) == 0 { + panic("no return value specified for RemoveAlias") + } var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, string, string) error); ok { - r0 = rf(ctx, spaceId, envId, alias) + r0 = rf(ctx, spaceId, id, alias) } else { r0 = ret.Error(0) } @@ -141,13 +165,17 @@ func (_m *Environments) RemoveAlias(ctx context.Context, spaceId string, envId s return r0 } -// SetAlias provides a mock function with given fields: ctx, spaceId, envId, alias -func (_m *Environments) SetAlias(ctx context.Context, spaceId string, envId string, alias string) error { - ret := _m.Called(ctx, spaceId, envId, alias) +// SetAlias provides a mock function with given fields: ctx, spaceId, id, alias +func (_m *Environments) SetAlias(ctx context.Context, spaceId string, id string, alias string) error { + ret := _m.Called(ctx, spaceId, id, alias) + + if len(ret) == 0 { + panic("no return value specified for SetAlias") + } var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, string, string) error); ok { - r0 = rf(ctx, spaceId, envId, alias) + r0 = rf(ctx, spaceId, id, alias) } else { r0 = ret.Error(0) } @@ -159,6 +187,10 @@ func (_m *Environments) SetAlias(ctx context.Context, spaceId string, envId stri func (_m *Environments) Update(ctx context.Context, env *environments.Environment) error { ret := _m.Called(ctx, env) + if len(ret) == 0 { + panic("no return value specified for Update") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, *environments.Environment) error); ok { r0 = rf(ctx, env) diff --git a/pkg/environments/mocks/Middleware.go b/pkg/environments/mocks/Middleware.go index e88e67e9c4b541450200ab8cf9f313383366d44b..1dded44d5b5b0cfdb9afe0bdf36ba05b3d9fc297 100644 --- a/pkg/environments/mocks/Middleware.go +++ b/pkg/environments/mocks/Middleware.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -17,6 +17,10 @@ type Middleware struct { func (_m *Middleware) Execute(_a0 environments.Environments) environments.Environments { ret := _m.Called(_a0) + if len(ret) == 0 { + panic("no return value specified for Execute") + } + var r0 environments.Environments if rf, ok := ret.Get(0).(func(environments.Environments) environments.Environments); ok { r0 = rf(_a0) diff --git a/pkg/environments/mocks/Storage.go b/pkg/environments/mocks/Storage.go index 37b8f6e5ef7349b4739969b8bba457979a8faad0..3a8671cd539f5dd2bd3b156155b71f43b7439e8f 100644 --- a/pkg/environments/mocks/Storage.go +++ b/pkg/environments/mocks/Storage.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -18,6 +18,10 @@ type Storage struct { func (_m *Storage) Create(ctx context.Context, create *environments.Environment) (*environments.Environment, error) { ret := _m.Called(ctx, create) + if len(ret) == 0 { + panic("no return value specified for Create") + } + var r0 *environments.Environment var r1 error if rf, ok := ret.Get(0).(func(context.Context, *environments.Environment) (*environments.Environment, error)); ok { @@ -44,6 +48,10 @@ func (_m *Storage) Create(ctx context.Context, create *environments.Environment) func (_m *Storage) Delete(ctx context.Context, spaceId string, envId string) error { ret := _m.Called(ctx, spaceId, envId) + if len(ret) == 0 { + panic("no return value specified for Delete") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, string) error); ok { r0 = rf(ctx, spaceId, envId) @@ -58,6 +66,10 @@ func (_m *Storage) Delete(ctx context.Context, spaceId string, envId string) err func (_m *Storage) Get(ctx context.Context, spaceId string, envId string) (*environments.Environment, error) { ret := _m.Called(ctx, spaceId, envId) + if len(ret) == 0 { + panic("no return value specified for Get") + } + var r0 *environments.Environment var r1 error if rf, ok := ret.Get(0).(func(context.Context, string, string) (*environments.Environment, error)); ok { @@ -84,6 +96,10 @@ func (_m *Storage) Get(ctx context.Context, spaceId string, envId string) (*envi func (_m *Storage) Init(ctx context.Context, spaceID string) error { ret := _m.Called(ctx, spaceID) + if len(ret) == 0 { + panic("no return value specified for Init") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { r0 = rf(ctx, spaceID) @@ -98,6 +114,10 @@ func (_m *Storage) Init(ctx context.Context, spaceID string) error { func (_m *Storage) List(ctx context.Context, spaceId string) ([]*environments.Environment, error) { ret := _m.Called(ctx, spaceId) + if len(ret) == 0 { + panic("no return value specified for List") + } + var r0 []*environments.Environment var r1 error if rf, ok := ret.Get(0).(func(context.Context, string) ([]*environments.Environment, error)); ok { @@ -124,6 +144,10 @@ func (_m *Storage) List(ctx context.Context, spaceId string) ([]*environments.En func (_m *Storage) RemoveAlias(ctx context.Context, spaceId string, envId string, alias string) error { ret := _m.Called(ctx, spaceId, envId, alias) + if len(ret) == 0 { + panic("no return value specified for RemoveAlias") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, string, string) error); ok { r0 = rf(ctx, spaceId, envId, alias) @@ -143,6 +167,10 @@ func (_m *Storage) Reset(ctx context.Context, spaceId string) { func (_m *Storage) SetAlias(ctx context.Context, spaceId string, envId string, alias string) error { ret := _m.Called(ctx, spaceId, envId, alias) + if len(ret) == 0 { + panic("no return value specified for SetAlias") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, string, string) error); ok { r0 = rf(ctx, spaceId, envId, alias) @@ -164,6 +192,10 @@ func (_m *Storage) Update(ctx context.Context, up *environments.Environment, opt _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for Update") + } + var r0 int var r1 int var r2 error diff --git a/pkg/environments/mocks/spaceGetter.go b/pkg/environments/mocks/spaceGetter.go new file mode 100644 index 0000000000000000000000000000000000000000..0dfa462e8b1af6c8feeee2bed7cd7e4c1317d0b1 --- /dev/null +++ b/pkg/environments/mocks/spaceGetter.go @@ -0,0 +1,42 @@ +// Code generated by mockery v2.46.3. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// spaceGetter is an autogenerated mock type for the spaceGetter type +type spaceGetter struct { + mock.Mock +} + +// GetSpaceID provides a mock function with given fields: +func (_m *spaceGetter) GetSpaceID() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetSpaceID") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// newSpaceGetter creates a new instance of spaceGetter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newSpaceGetter(t interface { + mock.TestingT + Cleanup(func()) +}) *spaceGetter { + mock := &spaceGetter{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/environments/service.go b/pkg/environments/service.go index 920fc043704f9d7dcf51d83032d98292be758550..c4c3a9a5c45dae547ce02d47b915d62ae4331cbb 100644 --- a/pkg/environments/service.go +++ b/pkg/environments/service.go @@ -15,13 +15,13 @@ import ( // @grpc-addr content.environments.Environments type Environments interface { Create(ctx context.Context, env *Environment) (created *Environment, err error) - Get(ctx context.Context, spaceId, envId string) (env *Environment, err error) + Get(ctx context.Context, spaceId, id string) (env *Environment, err error) List(ctx context.Context, spaceId string) (envs []*Environment, err error) Update(ctx context.Context, env *Environment) (err error) - Delete(ctx context.Context, spaceId, envId string) (err error) - SetAlias(ctx context.Context, spaceId, envId, alias string) (err error) - RemoveAlias(ctx context.Context, spaceId, envId, alias string) (err error) - Migrate(ctx context.Context, spaceId, envId string, options ...*MigrateOptions) (err error) + Delete(ctx context.Context, spaceId, id string) (err error) + SetAlias(ctx context.Context, spaceId, id, alias string) (err error) + RemoveAlias(ctx context.Context, spaceId, id, alias string) (err error) + Migrate(ctx context.Context, spaceId, id string, options ...*MigrateOptions) (err error) } const ( diff --git a/pkg/extension/middleware/telemetry_middleware.go b/pkg/extension/middleware/telemetry_middleware.go index 7302cab3b4ecf364f475b0dbe7d77a37c96cd784..10349b313f96f3f4770f9ea7d58adcfcd73dd0f7 100644 --- a/pkg/extension/middleware/telemetry_middleware.go +++ b/pkg/extension/middleware/telemetry_middleware.go @@ -10,7 +10,7 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/extension" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" @@ -68,7 +68,7 @@ func (_d telemetryMiddleware) Action(ctx context.Context, in *extension.ActionRe _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -108,7 +108,7 @@ func (_d telemetryMiddleware) Check(ctx context.Context, in *extension.CheckRequ _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -147,7 +147,7 @@ func (_d telemetryMiddleware) Install(ctx context.Context, in *extension.Install _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -186,7 +186,7 @@ func (_d telemetryMiddleware) ListExtensions(ctx context.Context, space string, _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -228,7 +228,7 @@ func (_d telemetryMiddleware) ListRegisteredExtensions(ctx context.Context, exte _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -268,7 +268,7 @@ func (_d telemetryMiddleware) RegisterExtensions(ctx context.Context, ext ...*ex _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -307,7 +307,7 @@ func (_d telemetryMiddleware) Uninstall(ctx context.Context, in *extension.Unins _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -346,7 +346,7 @@ func (_d telemetryMiddleware) UnregisterExtensions(ctx context.Context, ext ...* _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } diff --git a/pkg/files/middleware/telemetry_middleware.go b/pkg/files/middleware/telemetry_middleware.go index e2e482a6af8f4ffde281120f35c17fae425202f6..156f9d8b1e340d4c27891c517b749b0e707995f8 100644 --- a/pkg/files/middleware/telemetry_middleware.go +++ b/pkg/files/middleware/telemetry_middleware.go @@ -10,7 +10,7 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/files" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" @@ -68,7 +68,7 @@ func (_d telemetryMiddleware) AbortUpload(ctx context.Context, upload *files.Mul _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -107,7 +107,7 @@ func (_d telemetryMiddleware) CompleteUpload(ctx context.Context, upload *files. _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -147,7 +147,7 @@ func (_d telemetryMiddleware) DeleteFile(ctx context.Context, file *files.File) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -186,7 +186,7 @@ func (_d telemetryMiddleware) GetFile(ctx context.Context, file *files.File) (f _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -226,7 +226,7 @@ func (_d telemetryMiddleware) MoveUpload(ctx context.Context, upload *files.Mult _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -266,7 +266,7 @@ func (_d telemetryMiddleware) StartUpload(ctx context.Context, upload *files.Mul _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -306,7 +306,7 @@ func (_d telemetryMiddleware) Upload(ctx context.Context, file *files.File) (u * _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } diff --git a/pkg/invitations/middleware/telemetry_middleware.go b/pkg/invitations/middleware/telemetry_middleware.go index 1696f81a9ada1457336e928ebb44c79aa6852bcd..a80140c1ca52dff6c5b8e0cd55cee26bdd600fbd 100644 --- a/pkg/invitations/middleware/telemetry_middleware.go +++ b/pkg/invitations/middleware/telemetry_middleware.go @@ -10,7 +10,7 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/invitations" "git.perx.ru/perxis/perxis-go/pkg/options" @@ -85,7 +85,7 @@ func (_d telemetryMiddleware) Accept(ctx context.Context, invitationId string, u if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -141,7 +141,7 @@ func (_d telemetryMiddleware) Create(ctx context.Context, invitation *invitation if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -197,7 +197,7 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, invitationId string) ( if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -252,7 +252,7 @@ func (_d telemetryMiddleware) Find(ctx context.Context, filter *invitations.Filt if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -310,7 +310,7 @@ func (_d telemetryMiddleware) Get(ctx context.Context, invitationId string) (inv if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } diff --git a/pkg/items/middleware/access_logging_middleware.go b/pkg/items/middleware/access_logging_middleware.go index 2342a6d99249f427aa0f4ad6b4220a43ba872a4f..e8c68bd45569aeb070056533ee5287b33df86464 100644 --- a/pkg/items/middleware/access_logging_middleware.go +++ b/pkg/items/middleware/access_logging_middleware.go @@ -208,7 +208,7 @@ func (m *accessLoggingMiddleware) FindPublished(ctx context.Context, spaceId str return items, total, err } -func (m *accessLoggingMiddleware) Get(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.GetOptions) (item *items.Item, err error) { +func (m *accessLoggingMiddleware) Get(ctx context.Context, spaceId string, envId string, collectionId string, id string, options ...*items.GetOptions) (item *items.Item, err error) { begin := time.Now() m.logger.Debug("Get.Request", @@ -216,11 +216,11 @@ func (m *accessLoggingMiddleware) Get(ctx context.Context, spaceId string, envId zap.Reflect("spaceId", spaceId), zap.Reflect("envId", envId), zap.Reflect("collectionId", collectionId), - zap.Reflect("itemId", itemId), + zap.Reflect("id", id), zap.Reflect("options", options), ) - item, err = m.next.Get(ctx, spaceId, envId, collectionId, itemId, options...) + item, err = m.next.Get(ctx, spaceId, envId, collectionId, id, options...) m.logger.Debug("Get.Response", zap.Duration("time", time.Since(begin)), @@ -231,7 +231,7 @@ func (m *accessLoggingMiddleware) Get(ctx context.Context, spaceId string, envId return item, err } -func (m *accessLoggingMiddleware) GetPublished(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.GetPublishedOptions) (item *items.Item, err error) { +func (m *accessLoggingMiddleware) GetPublished(ctx context.Context, spaceId string, envId string, collectionId string, id string, options ...*items.GetPublishedOptions) (item *items.Item, err error) { begin := time.Now() m.logger.Debug("GetPublished.Request", @@ -239,11 +239,11 @@ func (m *accessLoggingMiddleware) GetPublished(ctx context.Context, spaceId stri zap.Reflect("spaceId", spaceId), zap.Reflect("envId", envId), zap.Reflect("collectionId", collectionId), - zap.Reflect("itemId", itemId), + zap.Reflect("id", id), zap.Reflect("options", options), ) - item, err = m.next.GetPublished(ctx, spaceId, envId, collectionId, itemId, options...) + item, err = m.next.GetPublished(ctx, spaceId, envId, collectionId, id, options...) m.logger.Debug("GetPublished.Response", zap.Duration("time", time.Since(begin)), @@ -254,7 +254,7 @@ func (m *accessLoggingMiddleware) GetPublished(ctx context.Context, spaceId stri return item, err } -func (m *accessLoggingMiddleware) GetRevision(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, revisionId string, options ...*items.GetRevisionOptions) (item *items.Item, err error) { +func (m *accessLoggingMiddleware) GetRevision(ctx context.Context, spaceId string, envId string, collectionId string, id string, revisionId string, options ...*items.GetRevisionOptions) (item *items.Item, err error) { begin := time.Now() m.logger.Debug("GetRevision.Request", @@ -262,12 +262,12 @@ func (m *accessLoggingMiddleware) GetRevision(ctx context.Context, spaceId strin zap.Reflect("spaceId", spaceId), zap.Reflect("envId", envId), zap.Reflect("collectionId", collectionId), - zap.Reflect("itemId", itemId), + zap.Reflect("id", id), zap.Reflect("revisionId", revisionId), zap.Reflect("options", options), ) - item, err = m.next.GetRevision(ctx, spaceId, envId, collectionId, itemId, revisionId, options...) + item, err = m.next.GetRevision(ctx, spaceId, envId, collectionId, id, revisionId, options...) m.logger.Debug("GetRevision.Response", zap.Duration("time", time.Since(begin)), @@ -299,7 +299,7 @@ func (m *accessLoggingMiddleware) Introspect(ctx context.Context, item *items.It return itm, sch, err } -func (m *accessLoggingMiddleware) ListRevisions(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.ListRevisionsOptions) (items []*items.Item, err error) { +func (m *accessLoggingMiddleware) ListRevisions(ctx context.Context, spaceId string, envId string, collectionId string, id string, options ...*items.ListRevisionsOptions) (items []*items.Item, err error) { begin := time.Now() m.logger.Debug("ListRevisions.Request", @@ -307,11 +307,11 @@ func (m *accessLoggingMiddleware) ListRevisions(ctx context.Context, spaceId str zap.Reflect("spaceId", spaceId), zap.Reflect("envId", envId), zap.Reflect("collectionId", collectionId), - zap.Reflect("itemId", itemId), + zap.Reflect("id", id), zap.Reflect("options", options), ) - items, err = m.next.ListRevisions(ctx, spaceId, envId, collectionId, itemId, options...) + items, err = m.next.ListRevisions(ctx, spaceId, envId, collectionId, id, options...) m.logger.Debug("ListRevisions.Response", zap.Duration("time", time.Since(begin)), diff --git a/pkg/items/middleware/caching_middleware.go b/pkg/items/middleware/caching_middleware.go index 60d3bf80250843f2ddc963fe5d242e58f590a3f7..b140e61168995b9334c4e64b1088f43b38e1640f 100644 --- a/pkg/items/middleware/caching_middleware.go +++ b/pkg/items/middleware/caching_middleware.go @@ -33,7 +33,7 @@ type cachingMiddleware struct { service.Items } -func (m cachingMiddleware) Get(ctx context.Context, spaceId, envId, collectionId, itemId string, options ...*service.GetOptions) (itm *service.Item, err error) { +func (m cachingMiddleware) Get(ctx context.Context, spaceId, envId, collectionId, id string, options ...*service.GetOptions) (itm *service.Item, err error) { opts := service.MergeGetOptions(options...) localeID := opts.LocaleID if localeID == "" { @@ -45,7 +45,7 @@ func (m cachingMiddleware) Get(ctx context.Context, spaceId, envId, collectionId // нечаÑтый Ð·Ð°Ð¿Ñ€Ð¾Ñ Ð¸ Ñодержание кÑша Ñ Ñ€Ð°Ð·Ð½Ñ‹Ð¼Ð¸ переводами ÑÐµÐ±Ñ Ð½Ðµ оправдывает var value = make(map[string]*service.Item) if len(opts.TranslationsIDs) == 0 { - val, e := m.cache.Get(makeKey(spaceId, envId, collectionId, itemId)) + val, e := m.cache.Get(makeKey(spaceId, envId, collectionId, id)) if e == nil { value = val.(map[string]*service.Item) if i, ok := value[localeID]; ok { @@ -54,7 +54,7 @@ func (m cachingMiddleware) Get(ctx context.Context, spaceId, envId, collectionId } } - itm, err = m.Items.Get(ctx, spaceId, envId, collectionId, itemId, options...) + itm, err = m.Items.Get(ctx, spaceId, envId, collectionId, id, options...) if err == nil { env, err := m.envs.Get(ctx, itm.SpaceID, itm.EnvID) if err != nil { @@ -123,7 +123,7 @@ func (m cachingMiddleware) Unpublish(ctx context.Context, item *service.Item, op return m.invalidateCache(ctx, item) } -func (m cachingMiddleware) GetPublished(ctx context.Context, spaceId, envId, collectionId, itemId string, options ...*service.GetPublishedOptions) (itm *service.Item, err error) { +func (m cachingMiddleware) GetPublished(ctx context.Context, spaceId, envId, collectionId, id string, options ...*service.GetPublishedOptions) (itm *service.Item, err error) { opts := service.MergeGetPublishedOptions(options...) localeID := opts.LocaleID if localeID == "" { @@ -135,7 +135,7 @@ func (m cachingMiddleware) GetPublished(ctx context.Context, spaceId, envId, col // нечаÑтый Ð·Ð°Ð¿Ñ€Ð¾Ñ Ð¸ Ñодержание кÑша Ñ Ñ€Ð°Ð·Ð½Ñ‹Ð¼Ð¸ переводами ÑÐµÐ±Ñ Ð½Ðµ оправдывает var value = make(map[string]*service.Item) if len(opts.TranslationsIDs) == 0 { - val, e := m.cachePublished.Get(makeKey(spaceId, envId, collectionId, itemId)) + val, e := m.cachePublished.Get(makeKey(spaceId, envId, collectionId, id)) if e == nil { value = val.(map[string]*service.Item) if i, ok := value[localeID]; ok { @@ -144,7 +144,7 @@ func (m cachingMiddleware) GetPublished(ctx context.Context, spaceId, envId, col } } - itm, err = m.Items.GetPublished(ctx, spaceId, envId, collectionId, itemId, opts) + itm, err = m.Items.GetPublished(ctx, spaceId, envId, collectionId, id, opts) if err == nil { env, err := m.envs.Get(ctx, itm.SpaceID, itm.EnvID) if err != nil { diff --git a/pkg/items/middleware/client_encode_middleware.go b/pkg/items/middleware/client_encode_middleware.go index 873a0e97c7690bcf51a042528787c57860d6163f..13c6e0dfe843e1234ccacba159f3b264386843bb 100644 --- a/pkg/items/middleware/client_encode_middleware.go +++ b/pkg/items/middleware/client_encode_middleware.go @@ -111,8 +111,8 @@ func (m *encodeDecodeMiddleware) Find(ctx context.Context, spaceId, envId, colle return } -func (m *encodeDecodeMiddleware) Get(ctx context.Context, spaceId, envId, collectionId, itemId string, options ...*items.GetOptions) (item *items.Item, err error) { - item, err = m.next.Get(ctx, spaceId, envId, collectionId, itemId, options...) +func (m *encodeDecodeMiddleware) Get(ctx context.Context, spaceId, envId, collectionId, id string, options ...*items.GetOptions) (item *items.Item, err error) { + item, err = m.next.Get(ctx, spaceId, envId, collectionId, id, options...) if err == nil && item != nil { col, err := m.colls.Get(ctx, spaceId, envId, collectionId) if err != nil { @@ -157,8 +157,8 @@ func (m *encodeDecodeMiddleware) Unpublish(ctx context.Context, item *items.Item return m.next.Unpublish(ctx, item, opts...) } -func (m *encodeDecodeMiddleware) GetPublished(ctx context.Context, spaceId, envId, collectionId, itemId string, options ...*items.GetPublishedOptions) (item *items.Item, err error) { - item, err = m.next.GetPublished(ctx, spaceId, envId, collectionId, itemId, options...) +func (m *encodeDecodeMiddleware) GetPublished(ctx context.Context, spaceId, envId, collectionId, id string, options ...*items.GetPublishedOptions) (item *items.Item, err error) { + item, err = m.next.GetPublished(ctx, spaceId, envId, collectionId, id, options...) if err == nil && item != nil { col, err := m.colls.Get(ctx, spaceId, envId, collectionId) if err != nil { @@ -192,8 +192,8 @@ func (m *encodeDecodeMiddleware) FindPublished(ctx context.Context, spaceId, env return } -func (m *encodeDecodeMiddleware) GetRevision(ctx context.Context, spaceId, envId, collectionId, itemId, revisionId string, options ...*items.GetRevisionOptions) (item *items.Item, err error) { - item, err = m.next.GetRevision(ctx, spaceId, envId, collectionId, itemId, revisionId, options...) +func (m *encodeDecodeMiddleware) GetRevision(ctx context.Context, spaceId, envId, collectionId, id, revisionId string, options ...*items.GetRevisionOptions) (item *items.Item, err error) { + item, err = m.next.GetRevision(ctx, spaceId, envId, collectionId, id, revisionId, options...) if err == nil && item != nil { col, err := m.colls.Get(ctx, spaceId, envId, collectionId) if err != nil { @@ -208,8 +208,8 @@ func (m *encodeDecodeMiddleware) GetRevision(ctx context.Context, spaceId, envId return } -func (m *encodeDecodeMiddleware) ListRevisions(ctx context.Context, spaceId, envId, collectionId, itemId string, options ...*items.ListRevisionsOptions) (items []*items.Item, err error) { - items, err = m.next.ListRevisions(ctx, spaceId, envId, collectionId, itemId, options...) +func (m *encodeDecodeMiddleware) ListRevisions(ctx context.Context, spaceId, envId, collectionId, id string, options ...*items.ListRevisionsOptions) (items []*items.Item, err error) { + items, err = m.next.ListRevisions(ctx, spaceId, envId, collectionId, id, options...) if err == nil && len(items) > 0 { col, err := m.colls.Get(ctx, spaceId, envId, collectionId) if err != nil { diff --git a/pkg/items/middleware/logging_middleware.go b/pkg/items/middleware/logging_middleware.go index 1178719ee2ad0190e12316165b2536de67f1324e..4ac01fd5b56c1bee738b996b18eaf5116a3ac8b2 100644 --- a/pkg/items/middleware/logging_middleware.go +++ b/pkg/items/middleware/logging_middleware.go @@ -3,7 +3,7 @@ package middleware import ( "context" - "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/items" "git.perx.ru/perxis/perxis-go/pkg/schema" logzap "git.perx.ru/perxis/perxis-go/zap" @@ -157,13 +157,13 @@ func (m *loggingMiddleware) FindPublished(ctx context.Context, spaceId string, e return items, total, err } -func (m *loggingMiddleware) Get(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.GetOptions) (item *items.Item, err error) { +func (m *loggingMiddleware) Get(ctx context.Context, spaceId string, envId string, collectionId string, id string, options ...*items.GetOptions) (item *items.Item, err error) { logger := m.logger.With( logzap.Caller(ctx, logzap.WithSpace(spaceId)), - logzap.Object(id.NewItemId(spaceId, envId, collectionId, itemId)), + logzap.Object(pkgId.NewItemId(spaceId, envId, collectionId, id)), ) - item, err = m.next.Get(ctx, spaceId, envId, collectionId, itemId, options...) + item, err = m.next.Get(ctx, spaceId, envId, collectionId, id, options...) if err != nil { logger.Error("Failed to get", zap.Error(err)) return @@ -172,13 +172,13 @@ func (m *loggingMiddleware) Get(ctx context.Context, spaceId string, envId strin return item, err } -func (m *loggingMiddleware) GetPublished(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.GetPublishedOptions) (item *items.Item, err error) { +func (m *loggingMiddleware) GetPublished(ctx context.Context, spaceId string, envId string, collectionId string, id string, options ...*items.GetPublishedOptions) (item *items.Item, err error) { logger := m.logger.With( logzap.Caller(ctx, logzap.WithSpace(spaceId)), - logzap.Object(id.NewItemId(spaceId, envId, collectionId, itemId)), + logzap.Object(pkgId.NewItemId(spaceId, envId, collectionId, id)), ) - item, err = m.next.GetPublished(ctx, spaceId, envId, collectionId, itemId, options...) + item, err = m.next.GetPublished(ctx, spaceId, envId, collectionId, id, options...) if err != nil { logger.Error("Failed to get published", zap.Error(err)) return @@ -187,13 +187,13 @@ func (m *loggingMiddleware) GetPublished(ctx context.Context, spaceId string, en return item, err } -func (m *loggingMiddleware) GetRevision(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, revisionId string, options ...*items.GetRevisionOptions) (item *items.Item, err error) { +func (m *loggingMiddleware) GetRevision(ctx context.Context, spaceId string, envId string, collectionId string, id string, revisionId string, options ...*items.GetRevisionOptions) (item *items.Item, err error) { logger := m.logger.With( logzap.Caller(ctx, logzap.WithSpace(spaceId)), - logzap.Object(id.NewItemId(spaceId, envId, collectionId, itemId)), + logzap.Object(pkgId.NewItemId(spaceId, envId, collectionId, id)), ) - item, err = m.next.GetRevision(ctx, spaceId, envId, collectionId, itemId, revisionId, options...) + item, err = m.next.GetRevision(ctx, spaceId, envId, collectionId, id, revisionId, options...) if err != nil { logger.Error("Failed to get revision", zap.Error(err)) return @@ -221,13 +221,13 @@ func (m *loggingMiddleware) Introspect(ctx context.Context, item *items.Item, op return itm, sch, err } -func (m *loggingMiddleware) ListRevisions(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.ListRevisionsOptions) (items []*items.Item, err error) { +func (m *loggingMiddleware) ListRevisions(ctx context.Context, spaceId string, envId string, collectionId string, id string, options ...*items.ListRevisionsOptions) (items []*items.Item, err error) { logger := m.logger.With( logzap.Caller(ctx, logzap.WithSpace(spaceId)), - logzap.Object(id.NewItemId(spaceId, envId, collectionId, itemId)), + logzap.Object(pkgId.NewItemId(spaceId, envId, collectionId, id)), ) - items, err = m.next.ListRevisions(ctx, spaceId, envId, collectionId, itemId, options...) + items, err = m.next.ListRevisions(ctx, spaceId, envId, collectionId, id, options...) if err != nil { logger.Error("Failed to list revisions", zap.Error(err)) return diff --git a/pkg/items/middleware/recovering_middleware.go b/pkg/items/middleware/recovering_middleware.go index d719dd114010f4a28658a0508030042fe80c7d5e..8db90e7fab7bb02f58e22c72d32567a33767b3d4 100644 --- a/pkg/items/middleware/recovering_middleware.go +++ b/pkg/items/middleware/recovering_middleware.go @@ -127,7 +127,7 @@ func (m *recoveringMiddleware) FindPublished(ctx context.Context, spaceId string return m.next.FindPublished(ctx, spaceId, envId, collectionId, filter, options...) } -func (m *recoveringMiddleware) Get(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.GetOptions) (item *items.Item, err error) { +func (m *recoveringMiddleware) Get(ctx context.Context, spaceId string, envId string, collectionId string, id string, options ...*items.GetOptions) (item *items.Item, err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -136,10 +136,10 @@ func (m *recoveringMiddleware) Get(ctx context.Context, spaceId string, envId st } }() - return m.next.Get(ctx, spaceId, envId, collectionId, itemId, options...) + return m.next.Get(ctx, spaceId, envId, collectionId, id, options...) } -func (m *recoveringMiddleware) GetPublished(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.GetPublishedOptions) (item *items.Item, err error) { +func (m *recoveringMiddleware) GetPublished(ctx context.Context, spaceId string, envId string, collectionId string, id string, options ...*items.GetPublishedOptions) (item *items.Item, err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -148,10 +148,10 @@ func (m *recoveringMiddleware) GetPublished(ctx context.Context, spaceId string, } }() - return m.next.GetPublished(ctx, spaceId, envId, collectionId, itemId, options...) + return m.next.GetPublished(ctx, spaceId, envId, collectionId, id, options...) } -func (m *recoveringMiddleware) GetRevision(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, revisionId string, options ...*items.GetRevisionOptions) (item *items.Item, err error) { +func (m *recoveringMiddleware) GetRevision(ctx context.Context, spaceId string, envId string, collectionId string, id string, revisionId string, options ...*items.GetRevisionOptions) (item *items.Item, err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -160,7 +160,7 @@ func (m *recoveringMiddleware) GetRevision(ctx context.Context, spaceId string, } }() - return m.next.GetRevision(ctx, spaceId, envId, collectionId, itemId, revisionId, options...) + return m.next.GetRevision(ctx, spaceId, envId, collectionId, id, revisionId, options...) } func (m *recoveringMiddleware) Introspect(ctx context.Context, item *items.Item, opts ...*items.IntrospectOptions) (itm *items.Item, sch *schema.Schema, err error) { @@ -175,7 +175,7 @@ func (m *recoveringMiddleware) Introspect(ctx context.Context, item *items.Item, return m.next.Introspect(ctx, item, opts...) } -func (m *recoveringMiddleware) ListRevisions(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.ListRevisionsOptions) (items []*items.Item, err error) { +func (m *recoveringMiddleware) ListRevisions(ctx context.Context, spaceId string, envId string, collectionId string, id string, options ...*items.ListRevisionsOptions) (items []*items.Item, err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -184,7 +184,7 @@ func (m *recoveringMiddleware) ListRevisions(ctx context.Context, spaceId string } }() - return m.next.ListRevisions(ctx, spaceId, envId, collectionId, itemId, options...) + return m.next.ListRevisions(ctx, spaceId, envId, collectionId, id, options...) } func (m *recoveringMiddleware) Publish(ctx context.Context, item *items.Item, options ...*items.PublishOptions) (err error) { diff --git a/pkg/items/middleware/telemetry_middleware.go b/pkg/items/middleware/telemetry_middleware.go index da626aa53ea846ce5747bd0deded09d300d48d95..08ff97515c118c4543cd028b3ae555062665cc3d 100644 --- a/pkg/items/middleware/telemetry_middleware.go +++ b/pkg/items/middleware/telemetry_middleware.go @@ -10,7 +10,7 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/items" "git.perx.ru/perxis/perxis-go/pkg/schema" @@ -74,7 +74,7 @@ func (_d telemetryMiddleware) Aggregate(ctx context.Context, spaceId string, env if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -123,7 +123,7 @@ func (_d telemetryMiddleware) AggregatePublished(ctx context.Context, spaceId st if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -183,7 +183,7 @@ func (_d telemetryMiddleware) Archive(ctx context.Context, item *items.Item, opt if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -239,7 +239,7 @@ func (_d telemetryMiddleware) Create(ctx context.Context, item *items.Item, opts if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -296,7 +296,7 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, item *items.Item, opti if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -341,7 +341,7 @@ func (_d telemetryMiddleware) Find(ctx context.Context, spaceId string, envId st if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -391,7 +391,7 @@ func (_d telemetryMiddleware) FindArchived(ctx context.Context, spaceId string, if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -441,7 +441,7 @@ func (_d telemetryMiddleware) FindPublished(ctx context.Context, spaceId string, if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -471,7 +471,7 @@ func (_d telemetryMiddleware) FindPublished(ctx context.Context, spaceId string, } // Get implements items.Items -func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.GetOptions) (item *items.Item, err error) { +func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId string, collectionId string, id string, options ...*items.GetOptions) (item *items.Item, err error) { var att = []attribute.KeyValue{ attribute.String("service", "Items"), attribute.String("method", "Get"), @@ -482,7 +482,7 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId str ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Items.Get") defer _span.End() - item, err = _d.Items.Get(ctx, spaceId, envId, collectionId, itemId, options...) + item, err = _d.Items.Get(ctx, spaceId, envId, collectionId, id, options...) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) @@ -491,7 +491,7 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId str if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -504,7 +504,7 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId str "spaceId": spaceId, "envId": envId, "collectionId": collectionId, - "itemId": itemId, + "id": id, "options": options}, map[string]interface{}{ "item": item, "err": err}) @@ -520,7 +520,7 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId str } // GetPublished implements items.Items -func (_d telemetryMiddleware) GetPublished(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.GetPublishedOptions) (item *items.Item, err error) { +func (_d telemetryMiddleware) GetPublished(ctx context.Context, spaceId string, envId string, collectionId string, id string, options ...*items.GetPublishedOptions) (item *items.Item, err error) { var att = []attribute.KeyValue{ attribute.String("service", "Items"), attribute.String("method", "GetPublished"), @@ -531,7 +531,7 @@ func (_d telemetryMiddleware) GetPublished(ctx context.Context, spaceId string, ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Items.GetPublished") defer _span.End() - item, err = _d.Items.GetPublished(ctx, spaceId, envId, collectionId, itemId, options...) + item, err = _d.Items.GetPublished(ctx, spaceId, envId, collectionId, id, options...) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) @@ -540,7 +540,7 @@ func (_d telemetryMiddleware) GetPublished(ctx context.Context, spaceId string, if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -553,7 +553,7 @@ func (_d telemetryMiddleware) GetPublished(ctx context.Context, spaceId string, "spaceId": spaceId, "envId": envId, "collectionId": collectionId, - "itemId": itemId, + "id": id, "options": options}, map[string]interface{}{ "item": item, "err": err}) @@ -569,7 +569,7 @@ func (_d telemetryMiddleware) GetPublished(ctx context.Context, spaceId string, } // GetRevision implements items.Items -func (_d telemetryMiddleware) GetRevision(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, revisionId string, options ...*items.GetRevisionOptions) (item *items.Item, err error) { +func (_d telemetryMiddleware) GetRevision(ctx context.Context, spaceId string, envId string, collectionId string, id string, revisionId string, options ...*items.GetRevisionOptions) (item *items.Item, err error) { var att = []attribute.KeyValue{ attribute.String("service", "Items"), attribute.String("method", "GetRevision"), @@ -580,7 +580,7 @@ func (_d telemetryMiddleware) GetRevision(ctx context.Context, spaceId string, e ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Items.GetRevision") defer _span.End() - item, err = _d.Items.GetRevision(ctx, spaceId, envId, collectionId, itemId, revisionId, options...) + item, err = _d.Items.GetRevision(ctx, spaceId, envId, collectionId, id, revisionId, options...) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) @@ -589,7 +589,7 @@ func (_d telemetryMiddleware) GetRevision(ctx context.Context, spaceId string, e if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -602,7 +602,7 @@ func (_d telemetryMiddleware) GetRevision(ctx context.Context, spaceId string, e "spaceId": spaceId, "envId": envId, "collectionId": collectionId, - "itemId": itemId, + "id": id, "revisionId": revisionId, "options": options}, map[string]interface{}{ "item": item, @@ -650,7 +650,7 @@ func (_d telemetryMiddleware) Introspect(ctx context.Context, item *items.Item, if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -677,7 +677,7 @@ func (_d telemetryMiddleware) Introspect(ctx context.Context, item *items.Item, } // ListRevisions implements items.Items -func (_d telemetryMiddleware) ListRevisions(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.ListRevisionsOptions) (items []*items.Item, err error) { +func (_d telemetryMiddleware) ListRevisions(ctx context.Context, spaceId string, envId string, collectionId string, id string, options ...*items.ListRevisionsOptions) (items []*items.Item, err error) { var att = []attribute.KeyValue{ attribute.String("service", "Items"), attribute.String("method", "ListRevisions"), @@ -688,7 +688,7 @@ func (_d telemetryMiddleware) ListRevisions(ctx context.Context, spaceId string, ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Items.ListRevisions") defer _span.End() - items, err = _d.Items.ListRevisions(ctx, spaceId, envId, collectionId, itemId, options...) + items, err = _d.Items.ListRevisions(ctx, spaceId, envId, collectionId, id, options...) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) @@ -697,7 +697,7 @@ func (_d telemetryMiddleware) ListRevisions(ctx context.Context, spaceId string, if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -710,7 +710,7 @@ func (_d telemetryMiddleware) ListRevisions(ctx context.Context, spaceId string, "spaceId": spaceId, "envId": envId, "collectionId": collectionId, - "itemId": itemId, + "id": id, "options": options}, map[string]interface{}{ "items": items, "err": err}) @@ -757,7 +757,7 @@ func (_d telemetryMiddleware) Publish(ctx context.Context, item *items.Item, opt if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -813,7 +813,7 @@ func (_d telemetryMiddleware) Unarchive(ctx context.Context, item *items.Item, o if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -869,7 +869,7 @@ func (_d telemetryMiddleware) Undelete(ctx context.Context, item *items.Item, op if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -925,7 +925,7 @@ func (_d telemetryMiddleware) Unpublish(ctx context.Context, item *items.Item, o if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -981,7 +981,7 @@ func (_d telemetryMiddleware) Update(ctx context.Context, item *items.Item, opti if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } diff --git a/pkg/items/mocks/Decoder.go b/pkg/items/mocks/Decoder.go index fcc4d502ee3d57504560a69c35ebdea06460b595..1d3208d2b53d64a886e296c9e79fe9f83430db9c 100644 --- a/pkg/items/mocks/Decoder.go +++ b/pkg/items/mocks/Decoder.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -13,7 +13,7 @@ type Decoder struct { } // Decode provides a mock function with given fields: value, item -func (_m *Decoder) Decode(value interface{}, item *items.Item) error { +func (_m *Decoder) Decode(value any, item *items.Item) error { ret := _m.Called(value, item) if len(ret) == 0 { @@ -21,7 +21,7 @@ func (_m *Decoder) Decode(value interface{}, item *items.Item) error { } var r0 error - if rf, ok := ret.Get(0).(func(interface{}, *items.Item) error); ok { + if rf, ok := ret.Get(0).(func(any, *items.Item) error); ok { r0 = rf(value, item) } else { r0 = ret.Error(0) diff --git a/pkg/items/mocks/Encoder.go b/pkg/items/mocks/Encoder.go index cd2dd5c9762c84131974b6e612086ad61d3699f3..6af2b841b04bf61b41103821740d954d4d5feb06 100644 --- a/pkg/items/mocks/Encoder.go +++ b/pkg/items/mocks/Encoder.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -13,23 +13,23 @@ type Encoder struct { } // Encode provides a mock function with given fields: item -func (_m *Encoder) Encode(item *items.Item) (interface{}, error) { +func (_m *Encoder) Encode(item *items.Item) (any, error) { ret := _m.Called(item) if len(ret) == 0 { panic("no return value specified for Encode") } - var r0 interface{} + var r0 any var r1 error - if rf, ok := ret.Get(0).(func(*items.Item) (interface{}, error)); ok { + if rf, ok := ret.Get(0).(func(*items.Item) (any, error)); ok { return rf(item) } - if rf, ok := ret.Get(0).(func(*items.Item) interface{}); ok { + if rf, ok := ret.Get(0).(func(*items.Item) any); ok { r0 = rf(item) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(interface{}) + r0 = ret.Get(0).(any) } } diff --git a/pkg/items/mocks/Items.go b/pkg/items/mocks/Items.go index e134822e2869693fa3801affac8660eb357cd70c..4a073fce36b5e7131d248da20da3aeb66dae472e 100644 --- a/pkg/items/mocks/Items.go +++ b/pkg/items/mocks/Items.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -309,14 +309,14 @@ func (_m *Items) FindPublished(ctx context.Context, spaceId string, envId string return r0, r1, r2 } -// Get provides a mock function with given fields: ctx, spaceId, envId, collectionId, itemId, options -func (_m *Items) Get(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.GetOptions) (*items.Item, error) { +// Get provides a mock function with given fields: ctx, spaceId, envId, collectionId, id, options +func (_m *Items) Get(ctx context.Context, spaceId string, envId string, collectionId string, id string, options ...*items.GetOptions) (*items.Item, error) { _va := make([]interface{}, len(options)) for _i := range options { _va[_i] = options[_i] } var _ca []interface{} - _ca = append(_ca, ctx, spaceId, envId, collectionId, itemId) + _ca = append(_ca, ctx, spaceId, envId, collectionId, id) _ca = append(_ca, _va...) ret := _m.Called(_ca...) @@ -327,10 +327,10 @@ func (_m *Items) Get(ctx context.Context, spaceId string, envId string, collecti var r0 *items.Item var r1 error if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string, ...*items.GetOptions) (*items.Item, error)); ok { - return rf(ctx, spaceId, envId, collectionId, itemId, options...) + return rf(ctx, spaceId, envId, collectionId, id, options...) } if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string, ...*items.GetOptions) *items.Item); ok { - r0 = rf(ctx, spaceId, envId, collectionId, itemId, options...) + r0 = rf(ctx, spaceId, envId, collectionId, id, options...) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*items.Item) @@ -338,7 +338,7 @@ func (_m *Items) Get(ctx context.Context, spaceId string, envId string, collecti } if rf, ok := ret.Get(1).(func(context.Context, string, string, string, string, ...*items.GetOptions) error); ok { - r1 = rf(ctx, spaceId, envId, collectionId, itemId, options...) + r1 = rf(ctx, spaceId, envId, collectionId, id, options...) } else { r1 = ret.Error(1) } @@ -346,14 +346,14 @@ func (_m *Items) Get(ctx context.Context, spaceId string, envId string, collecti return r0, r1 } -// GetPublished provides a mock function with given fields: ctx, spaceId, envId, collectionId, itemId, options -func (_m *Items) GetPublished(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.GetPublishedOptions) (*items.Item, error) { +// GetPublished provides a mock function with given fields: ctx, spaceId, envId, collectionId, id, options +func (_m *Items) GetPublished(ctx context.Context, spaceId string, envId string, collectionId string, id string, options ...*items.GetPublishedOptions) (*items.Item, error) { _va := make([]interface{}, len(options)) for _i := range options { _va[_i] = options[_i] } var _ca []interface{} - _ca = append(_ca, ctx, spaceId, envId, collectionId, itemId) + _ca = append(_ca, ctx, spaceId, envId, collectionId, id) _ca = append(_ca, _va...) ret := _m.Called(_ca...) @@ -364,10 +364,10 @@ func (_m *Items) GetPublished(ctx context.Context, spaceId string, envId string, var r0 *items.Item var r1 error if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string, ...*items.GetPublishedOptions) (*items.Item, error)); ok { - return rf(ctx, spaceId, envId, collectionId, itemId, options...) + return rf(ctx, spaceId, envId, collectionId, id, options...) } if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string, ...*items.GetPublishedOptions) *items.Item); ok { - r0 = rf(ctx, spaceId, envId, collectionId, itemId, options...) + r0 = rf(ctx, spaceId, envId, collectionId, id, options...) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*items.Item) @@ -375,7 +375,7 @@ func (_m *Items) GetPublished(ctx context.Context, spaceId string, envId string, } if rf, ok := ret.Get(1).(func(context.Context, string, string, string, string, ...*items.GetPublishedOptions) error); ok { - r1 = rf(ctx, spaceId, envId, collectionId, itemId, options...) + r1 = rf(ctx, spaceId, envId, collectionId, id, options...) } else { r1 = ret.Error(1) } @@ -383,14 +383,14 @@ func (_m *Items) GetPublished(ctx context.Context, spaceId string, envId string, return r0, r1 } -// GetRevision provides a mock function with given fields: ctx, spaceId, envId, collectionId, itemId, revisionId, options -func (_m *Items) GetRevision(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, revisionId string, options ...*items.GetRevisionOptions) (*items.Item, error) { +// GetRevision provides a mock function with given fields: ctx, spaceId, envId, collectionId, id, revisionId, options +func (_m *Items) GetRevision(ctx context.Context, spaceId string, envId string, collectionId string, id string, revisionId string, options ...*items.GetRevisionOptions) (*items.Item, error) { _va := make([]interface{}, len(options)) for _i := range options { _va[_i] = options[_i] } var _ca []interface{} - _ca = append(_ca, ctx, spaceId, envId, collectionId, itemId, revisionId) + _ca = append(_ca, ctx, spaceId, envId, collectionId, id, revisionId) _ca = append(_ca, _va...) ret := _m.Called(_ca...) @@ -401,10 +401,10 @@ func (_m *Items) GetRevision(ctx context.Context, spaceId string, envId string, var r0 *items.Item var r1 error if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string, string, ...*items.GetRevisionOptions) (*items.Item, error)); ok { - return rf(ctx, spaceId, envId, collectionId, itemId, revisionId, options...) + return rf(ctx, spaceId, envId, collectionId, id, revisionId, options...) } if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string, string, ...*items.GetRevisionOptions) *items.Item); ok { - r0 = rf(ctx, spaceId, envId, collectionId, itemId, revisionId, options...) + r0 = rf(ctx, spaceId, envId, collectionId, id, revisionId, options...) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*items.Item) @@ -412,7 +412,7 @@ func (_m *Items) GetRevision(ctx context.Context, spaceId string, envId string, } if rf, ok := ret.Get(1).(func(context.Context, string, string, string, string, string, ...*items.GetRevisionOptions) error); ok { - r1 = rf(ctx, spaceId, envId, collectionId, itemId, revisionId, options...) + r1 = rf(ctx, spaceId, envId, collectionId, id, revisionId, options...) } else { r1 = ret.Error(1) } @@ -466,14 +466,14 @@ func (_m *Items) Introspect(ctx context.Context, item *items.Item, opts ...*item return r0, r1, r2 } -// ListRevisions provides a mock function with given fields: ctx, spaceId, envId, collectionId, itemId, options -func (_m *Items) ListRevisions(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.ListRevisionsOptions) ([]*items.Item, error) { +// ListRevisions provides a mock function with given fields: ctx, spaceId, envId, collectionId, id, options +func (_m *Items) ListRevisions(ctx context.Context, spaceId string, envId string, collectionId string, id string, options ...*items.ListRevisionsOptions) ([]*items.Item, error) { _va := make([]interface{}, len(options)) for _i := range options { _va[_i] = options[_i] } var _ca []interface{} - _ca = append(_ca, ctx, spaceId, envId, collectionId, itemId) + _ca = append(_ca, ctx, spaceId, envId, collectionId, id) _ca = append(_ca, _va...) ret := _m.Called(_ca...) @@ -484,10 +484,10 @@ func (_m *Items) ListRevisions(ctx context.Context, spaceId string, envId string var r0 []*items.Item var r1 error if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string, ...*items.ListRevisionsOptions) ([]*items.Item, error)); ok { - return rf(ctx, spaceId, envId, collectionId, itemId, options...) + return rf(ctx, spaceId, envId, collectionId, id, options...) } if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string, ...*items.ListRevisionsOptions) []*items.Item); ok { - r0 = rf(ctx, spaceId, envId, collectionId, itemId, options...) + r0 = rf(ctx, spaceId, envId, collectionId, id, options...) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]*items.Item) @@ -495,7 +495,7 @@ func (_m *Items) ListRevisions(ctx context.Context, spaceId string, envId string } if rf, ok := ret.Get(1).(func(context.Context, string, string, string, string, ...*items.ListRevisionsOptions) error); ok { - r1 = rf(ctx, spaceId, envId, collectionId, itemId, options...) + r1 = rf(ctx, spaceId, envId, collectionId, id, options...) } else { r1 = ret.Error(1) } diff --git a/pkg/items/mocks/Middleware.go b/pkg/items/mocks/Middleware.go index 0bebef848868bd06d6539b5159f5973f6a39315e..92a5017f5d8ad95d6c191a14aa9f824eada51337 100644 --- a/pkg/items/mocks/Middleware.go +++ b/pkg/items/mocks/Middleware.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks diff --git a/pkg/items/mocks/Storage.go b/pkg/items/mocks/Storage.go index 4ce04d02d6985f5e4da86137d74763999da02136..f1c6e1bbdf6c69a6b2b8ddb45fa2125d5838976e 100644 --- a/pkg/items/mocks/Storage.go +++ b/pkg/items/mocks/Storage.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.45.0. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks diff --git a/pkg/items/mocks/spaceGetter.go b/pkg/items/mocks/spaceGetter.go new file mode 100644 index 0000000000000000000000000000000000000000..0dfa462e8b1af6c8feeee2bed7cd7e4c1317d0b1 --- /dev/null +++ b/pkg/items/mocks/spaceGetter.go @@ -0,0 +1,42 @@ +// Code generated by mockery v2.46.3. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// spaceGetter is an autogenerated mock type for the spaceGetter type +type spaceGetter struct { + mock.Mock +} + +// GetSpaceID provides a mock function with given fields: +func (_m *spaceGetter) GetSpaceID() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetSpaceID") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// newSpaceGetter creates a new instance of spaceGetter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newSpaceGetter(t interface { + mock.TestingT + Cleanup(func()) +}) *spaceGetter { + mock := &spaceGetter{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/items/service.go b/pkg/items/service.go index 1f4f2867ebfc78ef5bc32bc68c4cd9371acd84bb..dba760119314d2bb1ed4046fdcc7431e33f88cfc 100644 --- a/pkg/items/service.go +++ b/pkg/items/service.go @@ -16,7 +16,7 @@ import ( type Items interface { Create(ctx context.Context, item *Item, opts ...*CreateOptions) (created *Item, err error) Introspect(ctx context.Context, item *Item, opts ...*IntrospectOptions) (itm *Item, sch *schema.Schema, err error) - Get(ctx context.Context, spaceId, envId, collectionId, itemId string, options ...*GetOptions) (item *Item, err error) + Get(ctx context.Context, spaceId, envId, collectionId, id string, options ...*GetOptions) (item *Item, err error) Find(ctx context.Context, spaceId, envId, collectionId string, filter *Filter, options ...*FindOptions) (items []*Item, total int, err error) Update(ctx context.Context, item *Item, options ...*UpdateOptions) (err error) @@ -30,11 +30,11 @@ type Items interface { Publish(ctx context.Context, item *Item, options ...*PublishOptions) (err error) Unpublish(ctx context.Context, item *Item, options ...*UnpublishOptions) (err error) - GetPublished(ctx context.Context, spaceId, envId, collectionId, itemId string, options ...*GetPublishedOptions) (item *Item, err error) + GetPublished(ctx context.Context, spaceId, envId, collectionId, id string, options ...*GetPublishedOptions) (item *Item, err error) FindPublished(ctx context.Context, spaceId, envId, collectionId string, filter *Filter, options ...*FindPublishedOptions) (items []*Item, total int, err error) - GetRevision(ctx context.Context, spaceId, envId, collectionId, itemId, revisionId string, options ...*GetRevisionOptions) (item *Item, err error) - ListRevisions(ctx context.Context, spaceId, envId, collectionId, itemId string, options ...*ListRevisionsOptions) (items []*Item, err error) + GetRevision(ctx context.Context, spaceId, envId, collectionId, id, revisionId string, options ...*GetRevisionOptions) (item *Item, err error) + ListRevisions(ctx context.Context, spaceId, envId, collectionId, id string, options ...*ListRevisionsOptions) (items []*Item, err error) Archive(ctx context.Context, item *Item, options ...*ArchiveOptions) (err error) FindArchived(ctx context.Context, spaceId, envId, collectionId string, filter *Filter, options ...*FindArchivedOptions) (items []*Item, total int, err error) diff --git a/pkg/locales/middleware/access_logging_middleware.go b/pkg/locales/middleware/access_logging_middleware.go index ab31fc8c81ec51af35e63ab8eadbc400a9b717db..bf2b6619cc46a455daf4fdc3ecb5f53a5a044606 100644 --- a/pkg/locales/middleware/access_logging_middleware.go +++ b/pkg/locales/middleware/access_logging_middleware.go @@ -50,16 +50,16 @@ func (m *accessLoggingMiddleware) Create(ctx context.Context, locale *locales.Lo return created, err } -func (m *accessLoggingMiddleware) Delete(ctx context.Context, spaceId string, localeId string) (err error) { +func (m *accessLoggingMiddleware) Delete(ctx context.Context, spaceId string, id string) (err error) { begin := time.Now() m.logger.Debug("Delete.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), zap.Reflect("spaceId", spaceId), - zap.Reflect("localeId", localeId), + zap.Reflect("id", id), ) - err = m.next.Delete(ctx, spaceId, localeId) + err = m.next.Delete(ctx, spaceId, id) m.logger.Debug("Delete.Response", zap.Duration("time", time.Since(begin)), diff --git a/pkg/locales/middleware/caching_middleware.go b/pkg/locales/middleware/caching_middleware.go index 64f82bc2347323140674cb7375bfe41a36a5bfb0..f993a80ada02e3d5102fe289507527f73bc01338 100644 --- a/pkg/locales/middleware/caching_middleware.go +++ b/pkg/locales/middleware/caching_middleware.go @@ -54,9 +54,9 @@ func (m cachingMiddleware) List(ctx context.Context, spaceId string) (locales [] return nil, err } -func (m cachingMiddleware) Delete(ctx context.Context, spaceId string, localeId string) (err error) { +func (m cachingMiddleware) Delete(ctx context.Context, spaceId string, id string) (err error) { - err = m.next.Delete(ctx, spaceId, localeId) + err = m.next.Delete(ctx, spaceId, id) if err == nil { _ = m.cache.Remove(spaceId) } diff --git a/pkg/locales/middleware/error_logging_middleware.go b/pkg/locales/middleware/error_logging_middleware.go index 0dd4ae2e6748c35fa7a0592c274a9dfeb86f5d7b..74f4ce723a9c67fd64cc57c0531e44c0da419d6f 100644 --- a/pkg/locales/middleware/error_logging_middleware.go +++ b/pkg/locales/middleware/error_logging_middleware.go @@ -39,14 +39,14 @@ func (m *errorLoggingMiddleware) Create(ctx context.Context, locale *locales.Loc return m.next.Create(ctx, locale) } -func (m *errorLoggingMiddleware) Delete(ctx context.Context, spaceId string, localeId string) (err error) { +func (m *errorLoggingMiddleware) Delete(ctx context.Context, spaceId string, id string) (err error) { logger := m.logger defer func() { if err != nil { logger.Warn("response error", zap.Error(err)) } }() - return m.next.Delete(ctx, spaceId, localeId) + return m.next.Delete(ctx, spaceId, id) } func (m *errorLoggingMiddleware) List(ctx context.Context, spaceId string) (locales []*locales.Locale, err error) { diff --git a/pkg/locales/middleware/logging_middleware.go b/pkg/locales/middleware/logging_middleware.go index 2b6bfea5281a89bf9050094fe2d631fed200c9a4..22ea6a822d1517b3c0272e9d0eb6070446cdeaf5 100644 --- a/pkg/locales/middleware/logging_middleware.go +++ b/pkg/locales/middleware/logging_middleware.go @@ -3,7 +3,7 @@ package middleware import ( "context" - "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/locales" logzap "git.perx.ru/perxis/perxis-go/zap" "go.uber.org/zap" @@ -70,14 +70,14 @@ func (m *loggingMiddleware) List(ctx context.Context, spaceId string) (locales [ return locales, err } -func (m *loggingMiddleware) Delete(ctx context.Context, spaceId, localeId string) (err error) { +func (m *loggingMiddleware) Delete(ctx context.Context, spaceId, id string) (err error) { logger := m.logger.With( logzap.Caller(ctx), logzap.Event(locales.EventDelete), - logzap.Object(id.NewLocaleId(spaceId, localeId)), + logzap.Object(pkgId.NewLocaleId(spaceId, id)), ) - err = m.next.Delete(ctx, spaceId, localeId) + err = m.next.Delete(ctx, spaceId, id) if err != nil { logger.Error("Failed to delete", zap.Error(err), logzap.Channels(logzap.Userlog, logzap.Syslog)) return diff --git a/pkg/locales/middleware/recovering_middleware.go b/pkg/locales/middleware/recovering_middleware.go index 85f14bdbe6493c40c24c91bf539e33b9ca7e397b..586e2305433187e6fdf584af6308f9526103eba6 100644 --- a/pkg/locales/middleware/recovering_middleware.go +++ b/pkg/locales/middleware/recovering_middleware.go @@ -42,7 +42,7 @@ func (m *recoveringMiddleware) Create(ctx context.Context, locale *locales.Local return m.next.Create(ctx, locale) } -func (m *recoveringMiddleware) Delete(ctx context.Context, spaceId string, localeId string) (err error) { +func (m *recoveringMiddleware) Delete(ctx context.Context, spaceId string, id string) (err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -51,7 +51,7 @@ func (m *recoveringMiddleware) Delete(ctx context.Context, spaceId string, local } }() - return m.next.Delete(ctx, spaceId, localeId) + return m.next.Delete(ctx, spaceId, id) } func (m *recoveringMiddleware) List(ctx context.Context, spaceId string) (locales []*locales.Locale, err error) { diff --git a/pkg/locales/middleware/telemetry_middleware.go b/pkg/locales/middleware/telemetry_middleware.go index 709a6bab9a23210954ae0c756e6c10ac7fa2bd05..8016481d9aa52df48913535ad2498757eebc6e7d 100644 --- a/pkg/locales/middleware/telemetry_middleware.go +++ b/pkg/locales/middleware/telemetry_middleware.go @@ -10,7 +10,7 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/locales" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" @@ -84,7 +84,7 @@ func (_d telemetryMiddleware) Create(ctx context.Context, locale *locales.Locale if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -109,7 +109,7 @@ func (_d telemetryMiddleware) Create(ctx context.Context, locale *locales.Locale } // Delete implements locales.Locales -func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, localeId string) (err error) { +func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, id string) (err error) { var att = []attribute.KeyValue{ attribute.String("service", "Locales"), attribute.String("method", "Delete"), @@ -120,7 +120,7 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, locale ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Locales.Delete") defer _span.End() - err = _d.Locales.Delete(ctx, spaceId, localeId) + err = _d.Locales.Delete(ctx, spaceId, id) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) @@ -129,7 +129,7 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, locale if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -138,9 +138,9 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, locale if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ - "ctx": ctx, - "spaceId": spaceId, - "localeId": localeId}, map[string]interface{}{ + "ctx": ctx, + "spaceId": spaceId, + "id": id}, map[string]interface{}{ "err": err}) } else if err != nil { _d.requestMetrics.FailedTotal.Add(ctx, 1, attributes) @@ -174,7 +174,7 @@ func (_d telemetryMiddleware) List(ctx context.Context, spaceId string) (locales if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -230,7 +230,7 @@ func (_d telemetryMiddleware) Update(ctx context.Context, locale *locales.Locale if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } diff --git a/pkg/locales/mocks/LocaleCreatedObserver.go b/pkg/locales/mocks/LocaleCreatedObserver.go new file mode 100644 index 0000000000000000000000000000000000000000..8c9170662a8c06027a0bab344a4442536822992c --- /dev/null +++ b/pkg/locales/mocks/LocaleCreatedObserver.go @@ -0,0 +1,57 @@ +// Code generated by mockery v2.46.3. DO NOT EDIT. + +package mocks + +import ( + context "context" + + locales "git.perx.ru/perxis/perxis-go/pkg/locales" + mock "github.com/stretchr/testify/mock" +) + +// LocaleCreatedObserver is an autogenerated mock type for the LocaleCreatedObserver type +type LocaleCreatedObserver struct { + mock.Mock +} + +// OnLocaleCreated provides a mock function with given fields: ctx, locale +func (_m *LocaleCreatedObserver) OnLocaleCreated(ctx context.Context, locale *locales.Locale) (string, error) { + ret := _m.Called(ctx, locale) + + if len(ret) == 0 { + panic("no return value specified for OnLocaleCreated") + } + + var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *locales.Locale) (string, error)); ok { + return rf(ctx, locale) + } + if rf, ok := ret.Get(0).(func(context.Context, *locales.Locale) string); ok { + r0 = rf(ctx, locale) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(context.Context, *locales.Locale) error); ok { + r1 = rf(ctx, locale) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewLocaleCreatedObserver creates a new instance of LocaleCreatedObserver. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewLocaleCreatedObserver(t interface { + mock.TestingT + Cleanup(func()) +}) *LocaleCreatedObserver { + mock := &LocaleCreatedObserver{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/locales/mocks/LocaleDeletedObserver.go b/pkg/locales/mocks/LocaleDeletedObserver.go new file mode 100644 index 0000000000000000000000000000000000000000..f5862d9b63be18405a4fc0d0a78e83e5dfaf9542 --- /dev/null +++ b/pkg/locales/mocks/LocaleDeletedObserver.go @@ -0,0 +1,57 @@ +// Code generated by mockery v2.46.3. DO NOT EDIT. + +package mocks + +import ( + context "context" + + locales "git.perx.ru/perxis/perxis-go/pkg/locales" + mock "github.com/stretchr/testify/mock" +) + +// LocaleDeletedObserver is an autogenerated mock type for the LocaleDeletedObserver type +type LocaleDeletedObserver struct { + mock.Mock +} + +// OnLocaleDeleted provides a mock function with given fields: ctx, locale +func (_m *LocaleDeletedObserver) OnLocaleDeleted(ctx context.Context, locale *locales.Locale) (string, error) { + ret := _m.Called(ctx, locale) + + if len(ret) == 0 { + panic("no return value specified for OnLocaleDeleted") + } + + var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *locales.Locale) (string, error)); ok { + return rf(ctx, locale) + } + if rf, ok := ret.Get(0).(func(context.Context, *locales.Locale) string); ok { + r0 = rf(ctx, locale) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(context.Context, *locales.Locale) error); ok { + r1 = rf(ctx, locale) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewLocaleDeletedObserver creates a new instance of LocaleDeletedObserver. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewLocaleDeletedObserver(t interface { + mock.TestingT + Cleanup(func()) +}) *LocaleDeletedObserver { + mock := &LocaleDeletedObserver{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/locales/mocks/LocaleUpdatedObserver.go b/pkg/locales/mocks/LocaleUpdatedObserver.go new file mode 100644 index 0000000000000000000000000000000000000000..1e3b395c0bc944d919ef01eaf62e82fb0751a192 --- /dev/null +++ b/pkg/locales/mocks/LocaleUpdatedObserver.go @@ -0,0 +1,57 @@ +// Code generated by mockery v2.46.3. DO NOT EDIT. + +package mocks + +import ( + context "context" + + locales "git.perx.ru/perxis/perxis-go/pkg/locales" + mock "github.com/stretchr/testify/mock" +) + +// LocaleUpdatedObserver is an autogenerated mock type for the LocaleUpdatedObserver type +type LocaleUpdatedObserver struct { + mock.Mock +} + +// OnLocaleUpdated provides a mock function with given fields: ctx, before, locale +func (_m *LocaleUpdatedObserver) OnLocaleUpdated(ctx context.Context, before *locales.Locale, locale *locales.Locale) (string, error) { + ret := _m.Called(ctx, before, locale) + + if len(ret) == 0 { + panic("no return value specified for OnLocaleUpdated") + } + + var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *locales.Locale, *locales.Locale) (string, error)); ok { + return rf(ctx, before, locale) + } + if rf, ok := ret.Get(0).(func(context.Context, *locales.Locale, *locales.Locale) string); ok { + r0 = rf(ctx, before, locale) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(context.Context, *locales.Locale, *locales.Locale) error); ok { + r1 = rf(ctx, before, locale) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewLocaleUpdatedObserver creates a new instance of LocaleUpdatedObserver. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewLocaleUpdatedObserver(t interface { + mock.TestingT + Cleanup(func()) +}) *LocaleUpdatedObserver { + mock := &LocaleUpdatedObserver{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/locales/mocks/Locales.go b/pkg/locales/mocks/Locales.go index 6519e3cc9b5e02895fa22b778c15437737f606de..7f17c3865e0188434a80f3e1579180f02ad5f98c 100644 --- a/pkg/locales/mocks/Locales.go +++ b/pkg/locales/mocks/Locales.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -44,9 +44,9 @@ func (_m *Locales) Create(ctx context.Context, locale *locales.Locale) (*locales return r0, r1 } -// Delete provides a mock function with given fields: ctx, spaceId, localeId -func (_m *Locales) Delete(ctx context.Context, spaceId string, localeId string) error { - ret := _m.Called(ctx, spaceId, localeId) +// Delete provides a mock function with given fields: ctx, spaceId, id +func (_m *Locales) Delete(ctx context.Context, spaceId string, id string) error { + ret := _m.Called(ctx, spaceId, id) if len(ret) == 0 { panic("no return value specified for Delete") @@ -54,7 +54,7 @@ func (_m *Locales) Delete(ctx context.Context, spaceId string, localeId string) var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, string) error); ok { - r0 = rf(ctx, spaceId, localeId) + r0 = rf(ctx, spaceId, id) } else { r0 = ret.Error(0) } diff --git a/pkg/locales/mocks/Middleware.go b/pkg/locales/mocks/Middleware.go index bab6711d69138d1b72529c89c979f9e03dd47cd1..11136a3b995cc8838b7204a06bbe11c8b61acb2b 100644 --- a/pkg/locales/mocks/Middleware.go +++ b/pkg/locales/mocks/Middleware.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.15.0. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -17,6 +17,10 @@ type Middleware struct { func (_m *Middleware) Execute(_a0 locales.Locales) locales.Locales { ret := _m.Called(_a0) + if len(ret) == 0 { + panic("no return value specified for Execute") + } + var r0 locales.Locales if rf, ok := ret.Get(0).(func(locales.Locales) locales.Locales); ok { r0 = rf(_a0) @@ -29,13 +33,12 @@ func (_m *Middleware) Execute(_a0 locales.Locales) locales.Locales { return r0 } -type mockConstructorTestingTNewMiddleware interface { +// NewMiddleware creates a new instance of Middleware. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMiddleware(t interface { mock.TestingT Cleanup(func()) -} - -// NewMiddleware creates a new instance of Middleware. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewMiddleware(t mockConstructorTestingTNewMiddleware) *Middleware { +}) *Middleware { mock := &Middleware{} mock.Mock.Test(t) diff --git a/pkg/locales/mocks/Storage.go b/pkg/locales/mocks/Storage.go index 42946781b45c100bfb962fde0a2f6098699cec80..af42d88311c342e66ef8ff637cfec6a119b03904 100644 --- a/pkg/locales/mocks/Storage.go +++ b/pkg/locales/mocks/Storage.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks diff --git a/pkg/locales/mocks/spaceGetter.go b/pkg/locales/mocks/spaceGetter.go new file mode 100644 index 0000000000000000000000000000000000000000..0dfa462e8b1af6c8feeee2bed7cd7e4c1317d0b1 --- /dev/null +++ b/pkg/locales/mocks/spaceGetter.go @@ -0,0 +1,42 @@ +// Code generated by mockery v2.46.3. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// spaceGetter is an autogenerated mock type for the spaceGetter type +type spaceGetter struct { + mock.Mock +} + +// GetSpaceID provides a mock function with given fields: +func (_m *spaceGetter) GetSpaceID() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetSpaceID") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// newSpaceGetter creates a new instance of spaceGetter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newSpaceGetter(t interface { + mock.TestingT + Cleanup(func()) +}) *spaceGetter { + mock := &spaceGetter{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/locales/service.go b/pkg/locales/service.go index ba303e13f671a700a5518ca1b200cb48dcad5695..1c1f136eae44746de2d0ec9ea00ba42499528b29 100644 --- a/pkg/locales/service.go +++ b/pkg/locales/service.go @@ -11,5 +11,5 @@ type Locales interface { Create(ctx context.Context, locale *Locale) (created *Locale, err error) Update(ctx context.Context, locale *Locale) (err error) List(ctx context.Context, spaceId string) (locales []*Locale, err error) - Delete(ctx context.Context, spaceId, localeId string) (err error) + Delete(ctx context.Context, spaceId, id string) (err error) } diff --git a/pkg/members/middleware/telemetry_middleware.go b/pkg/members/middleware/telemetry_middleware.go index bf339f3fd998e3e49d842a6b99612759743aced5..04dc47d3f407b91ea60bf9f1b78e70aabec4ce1d 100644 --- a/pkg/members/middleware/telemetry_middleware.go +++ b/pkg/members/middleware/telemetry_middleware.go @@ -10,7 +10,7 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/members" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" @@ -68,7 +68,7 @@ func (_d telemetryMiddleware) Get(ctx context.Context, orgId string, userId stri _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -109,7 +109,7 @@ func (_d telemetryMiddleware) ListMembers(ctx context.Context, orgId string) (me _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -149,7 +149,7 @@ func (_d telemetryMiddleware) ListOrganizations(ctx context.Context, userId stri _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -189,7 +189,7 @@ func (_d telemetryMiddleware) Remove(ctx context.Context, orgId string, userId s _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -229,7 +229,7 @@ func (_d telemetryMiddleware) RemoveAll(ctx context.Context, orgId string) (err _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -268,7 +268,7 @@ func (_d telemetryMiddleware) Set(ctx context.Context, orgId string, userId stri _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } diff --git a/pkg/organizations/middleware/access_logging_middleware.go b/pkg/organizations/middleware/access_logging_middleware.go index be6e937d1dc76ba9a6d4d80acd5c6343e35eacd7..ec70800a168a325822c5b80139ab4f709901bd16 100644 --- a/pkg/organizations/middleware/access_logging_middleware.go +++ b/pkg/organizations/middleware/access_logging_middleware.go @@ -51,15 +51,15 @@ func (m *accessLoggingMiddleware) Create(ctx context.Context, org *organizations return created, err } -func (m *accessLoggingMiddleware) Delete(ctx context.Context, orgId string) (err error) { +func (m *accessLoggingMiddleware) Delete(ctx context.Context, id string) (err error) { begin := time.Now() m.logger.Debug("Delete.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), - zap.Reflect("orgId", orgId), + zap.Reflect("id", id), ) - err = m.next.Delete(ctx, orgId) + err = m.next.Delete(ctx, id) m.logger.Debug("Delete.Response", zap.Duration("time", time.Since(begin)), @@ -90,15 +90,15 @@ func (m *accessLoggingMiddleware) Find(ctx context.Context, filter *organization return orgs, total, err } -func (m *accessLoggingMiddleware) Get(ctx context.Context, orgId string) (org *organizations.Organization, err error) { +func (m *accessLoggingMiddleware) Get(ctx context.Context, id string) (org *organizations.Organization, err error) { begin := time.Now() m.logger.Debug("Get.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), - zap.Reflect("orgId", orgId), + zap.Reflect("id", id), ) - org, err = m.next.Get(ctx, orgId) + org, err = m.next.Get(ctx, id) m.logger.Debug("Get.Response", zap.Duration("time", time.Since(begin)), diff --git a/pkg/organizations/middleware/caching_middleware.go b/pkg/organizations/middleware/caching_middleware.go index c6503200cfbc47915475a95c154a253dec51e29c..7343b00006cd9a5ac1aa463d82a7f06e32b7c975 100644 --- a/pkg/organizations/middleware/caching_middleware.go +++ b/pkg/organizations/middleware/caching_middleware.go @@ -26,15 +26,15 @@ func (m cachingMiddleware) Create(ctx context.Context, org *service.Organization return m.next.Create(ctx, org) } -func (m cachingMiddleware) Get(ctx context.Context, orgId string) (organization *service.Organization, err error) { +func (m cachingMiddleware) Get(ctx context.Context, id string) (organization *service.Organization, err error) { - value, e := m.cache.Get(orgId) + value, e := m.cache.Get(id) if e == nil { return value.(*service.Organization).Clone(), nil } - organization, err = m.next.Get(ctx, orgId) + organization, err = m.next.Get(ctx, id) if err == nil { - _ = m.cache.Set(orgId, organization) + _ = m.cache.Set(id, organization) return organization.Clone(), nil } return nil, err @@ -49,11 +49,11 @@ func (m cachingMiddleware) Update(ctx context.Context, org *service.Organization return err } -func (m cachingMiddleware) Delete(ctx context.Context, orgId string) (err error) { +func (m cachingMiddleware) Delete(ctx context.Context, id string) (err error) { - err = m.next.Delete(ctx, orgId) + err = m.next.Delete(ctx, id) if err == nil { - _ = m.cache.Remove(orgId) + _ = m.cache.Remove(id) } return err } diff --git a/pkg/organizations/middleware/error_logging_middleware.go b/pkg/organizations/middleware/error_logging_middleware.go index 2d6db8198b885e157ba8ebcc855bb6d9dadb519c..145e15f0f49808efe333919b2006376ca169dff3 100644 --- a/pkg/organizations/middleware/error_logging_middleware.go +++ b/pkg/organizations/middleware/error_logging_middleware.go @@ -40,14 +40,14 @@ func (m *errorLoggingMiddleware) Create(ctx context.Context, org *organizations. return m.next.Create(ctx, org) } -func (m *errorLoggingMiddleware) Delete(ctx context.Context, orgId string) (err error) { +func (m *errorLoggingMiddleware) Delete(ctx context.Context, id string) (err error) { logger := m.logger defer func() { if err != nil { logger.Warn("response error", zap.Error(err)) } }() - return m.next.Delete(ctx, orgId) + return m.next.Delete(ctx, id) } func (m *errorLoggingMiddleware) Find(ctx context.Context, filter *organizations.Filter, opts *options.FindOptions) (orgs []*organizations.Organization, total int, err error) { @@ -60,14 +60,14 @@ func (m *errorLoggingMiddleware) Find(ctx context.Context, filter *organizations return m.next.Find(ctx, filter, opts) } -func (m *errorLoggingMiddleware) Get(ctx context.Context, orgId string) (org *organizations.Organization, err error) { +func (m *errorLoggingMiddleware) Get(ctx context.Context, id string) (org *organizations.Organization, err error) { logger := m.logger defer func() { if err != nil { logger.Warn("response error", zap.Error(err)) } }() - return m.next.Get(ctx, orgId) + return m.next.Get(ctx, id) } func (m *errorLoggingMiddleware) Update(ctx context.Context, org *organizations.Organization) (err error) { diff --git a/pkg/organizations/middleware/logging_middleware.go b/pkg/organizations/middleware/logging_middleware.go index bda7f54fb101777758978a393bf43b52b1532b28..ae3481aecde295102d6e9483c22c87e65b423592 100644 --- a/pkg/organizations/middleware/logging_middleware.go +++ b/pkg/organizations/middleware/logging_middleware.go @@ -3,7 +3,7 @@ package middleware import ( "context" - "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/organizations" "git.perx.ru/perxis/perxis-go/pkg/options" @@ -42,14 +42,14 @@ func (m *loggingMiddleware) Create(ctx context.Context, org *organizations.Organ return created, err } -func (m *loggingMiddleware) Delete(ctx context.Context, orgId string) (err error) { +func (m *loggingMiddleware) Delete(ctx context.Context, id string) (err error) { logger := m.logger.With( logzap.Caller(ctx), logzap.Event(organizations.EventDelete), - logzap.Object(id.NewOrganizationId(orgId)), + logzap.Object(pkgId.NewOrganizationId(id)), ) - err = m.next.Delete(ctx, orgId) + err = m.next.Delete(ctx, id) if err != nil { logger.Error("Failed to delete", zap.Error(err), logzap.Channels(logzap.Userlog, logzap.Syslog)) return @@ -74,13 +74,13 @@ func (m *loggingMiddleware) Find(ctx context.Context, filter *organizations.Filt return orgs, total, err } -func (m *loggingMiddleware) Get(ctx context.Context, orgId string) (org *organizations.Organization, err error) { +func (m *loggingMiddleware) Get(ctx context.Context, id string) (org *organizations.Organization, err error) { logger := m.logger.With( logzap.Caller(ctx), - logzap.Object(id.NewOrganizationId(orgId)), + logzap.Object(pkgId.NewOrganizationId(id)), ) - org, err = m.next.Get(ctx, orgId) + org, err = m.next.Get(ctx, id) if err != nil { logger.Error("Failed to get", zap.Error(err)) return diff --git a/pkg/organizations/middleware/recovering_middleware.go b/pkg/organizations/middleware/recovering_middleware.go index d598f1da65414b4088c712944bbad71083e0def8..88ff859213b0678f4634a7fd4fadcf5c624aef76 100644 --- a/pkg/organizations/middleware/recovering_middleware.go +++ b/pkg/organizations/middleware/recovering_middleware.go @@ -43,7 +43,7 @@ func (m *recoveringMiddleware) Create(ctx context.Context, org *organizations.Or return m.next.Create(ctx, org) } -func (m *recoveringMiddleware) Delete(ctx context.Context, orgId string) (err error) { +func (m *recoveringMiddleware) Delete(ctx context.Context, id string) (err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -52,7 +52,7 @@ func (m *recoveringMiddleware) Delete(ctx context.Context, orgId string) (err er } }() - return m.next.Delete(ctx, orgId) + return m.next.Delete(ctx, id) } func (m *recoveringMiddleware) Find(ctx context.Context, filter *organizations.Filter, opts *options.FindOptions) (orgs []*organizations.Organization, total int, err error) { @@ -67,7 +67,7 @@ func (m *recoveringMiddleware) Find(ctx context.Context, filter *organizations.F return m.next.Find(ctx, filter, opts) } -func (m *recoveringMiddleware) Get(ctx context.Context, orgId string) (org *organizations.Organization, err error) { +func (m *recoveringMiddleware) Get(ctx context.Context, id string) (org *organizations.Organization, err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -76,7 +76,7 @@ func (m *recoveringMiddleware) Get(ctx context.Context, orgId string) (org *orga } }() - return m.next.Get(ctx, orgId) + return m.next.Get(ctx, id) } func (m *recoveringMiddleware) Update(ctx context.Context, org *organizations.Organization) (err error) { diff --git a/pkg/organizations/middleware/telemetry_middleware.go b/pkg/organizations/middleware/telemetry_middleware.go index 1cb7932880080c617db6ccbf2f3d204682ca7c11..ae945b477f841e611f20b945d4ac387cd6b96a6b 100644 --- a/pkg/organizations/middleware/telemetry_middleware.go +++ b/pkg/organizations/middleware/telemetry_middleware.go @@ -10,7 +10,7 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/options" "git.perx.ru/perxis/perxis-go/pkg/organizations" @@ -69,7 +69,7 @@ func (_d telemetryMiddleware) Create(ctx context.Context, org *organizations.Org _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -94,7 +94,7 @@ func (_d telemetryMiddleware) Create(ctx context.Context, org *organizations.Org } // Delete implements organizations.Organizations -func (_d telemetryMiddleware) Delete(ctx context.Context, orgId string) (err error) { +func (_d telemetryMiddleware) Delete(ctx context.Context, id string) (err error) { var att = []attribute.KeyValue{ attribute.String("service", "Organizations"), attribute.String("method", "Delete"), @@ -105,11 +105,11 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, orgId string) (err err ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Organizations.Delete") defer _span.End() - err = _d.Organizations.Delete(ctx, orgId) + err = _d.Organizations.Delete(ctx, id) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -118,8 +118,8 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, orgId string) (err err if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ - "ctx": ctx, - "orgId": orgId}, map[string]interface{}{ + "ctx": ctx, + "id": id}, map[string]interface{}{ "err": err}) } else if err != nil { _d.requestMetrics.FailedTotal.Add(ctx, 1, attributes) @@ -148,7 +148,7 @@ func (_d telemetryMiddleware) Find(ctx context.Context, filter *organizations.Fi _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -175,7 +175,7 @@ func (_d telemetryMiddleware) Find(ctx context.Context, filter *organizations.Fi } // Get implements organizations.Organizations -func (_d telemetryMiddleware) Get(ctx context.Context, orgId string) (org *organizations.Organization, err error) { +func (_d telemetryMiddleware) Get(ctx context.Context, id string) (org *organizations.Organization, err error) { var att = []attribute.KeyValue{ attribute.String("service", "Organizations"), attribute.String("method", "Get"), @@ -186,11 +186,11 @@ func (_d telemetryMiddleware) Get(ctx context.Context, orgId string) (org *organ ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Organizations.Get") defer _span.End() - org, err = _d.Organizations.Get(ctx, orgId) + org, err = _d.Organizations.Get(ctx, id) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -199,8 +199,8 @@ func (_d telemetryMiddleware) Get(ctx context.Context, orgId string) (org *organ if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ - "ctx": ctx, - "orgId": orgId}, map[string]interface{}{ + "ctx": ctx, + "id": id}, map[string]interface{}{ "org": org, "err": err}) } else if err != nil { @@ -230,7 +230,7 @@ func (_d telemetryMiddleware) Update(ctx context.Context, org *organizations.Org _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } diff --git a/pkg/organizations/mocks/Middleware.go b/pkg/organizations/mocks/Middleware.go index 5ff2ac9d9bda88225394cdc0e3b80115e3078196..cb33c249f9bbd18f1781426367fe2d027e167540 100644 --- a/pkg/organizations/mocks/Middleware.go +++ b/pkg/organizations/mocks/Middleware.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.15.0. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -16,6 +16,10 @@ type Middleware struct { func (_m *Middleware) Execute(_a0 organizations.Organizations) organizations.Organizations { ret := _m.Called(_a0) + if len(ret) == 0 { + panic("no return value specified for Execute") + } + var r0 organizations.Organizations if rf, ok := ret.Get(0).(func(organizations.Organizations) organizations.Organizations); ok { r0 = rf(_a0) @@ -28,13 +32,12 @@ func (_m *Middleware) Execute(_a0 organizations.Organizations) organizations.Org return r0 } -type mockConstructorTestingTNewMiddleware interface { +// NewMiddleware creates a new instance of Middleware. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMiddleware(t interface { mock.TestingT Cleanup(func()) -} - -// NewMiddleware creates a new instance of Middleware. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewMiddleware(t mockConstructorTestingTNewMiddleware) *Middleware { +}) *Middleware { mock := &Middleware{} mock.Mock.Test(t) diff --git a/pkg/organizations/mocks/Organizations.go b/pkg/organizations/mocks/Organizations.go index ec0015ae2989bc8b090f95ba515fd0a09a2c45fe..d00bcf2f7b7b24ca66dc537ccb697335e12f41bb 100644 --- a/pkg/organizations/mocks/Organizations.go +++ b/pkg/organizations/mocks/Organizations.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.15.0. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -20,7 +20,15 @@ type Organizations struct { func (_m *Organizations) Create(ctx context.Context, org *organizations.Organization) (*organizations.Organization, error) { ret := _m.Called(ctx, org) + if len(ret) == 0 { + panic("no return value specified for Create") + } + var r0 *organizations.Organization + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *organizations.Organization) (*organizations.Organization, error)); ok { + return rf(ctx, org) + } if rf, ok := ret.Get(0).(func(context.Context, *organizations.Organization) *organizations.Organization); ok { r0 = rf(ctx, org) } else { @@ -29,7 +37,6 @@ func (_m *Organizations) Create(ctx context.Context, org *organizations.Organiza } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, *organizations.Organization) error); ok { r1 = rf(ctx, org) } else { @@ -39,13 +46,17 @@ func (_m *Organizations) Create(ctx context.Context, org *organizations.Organiza return r0, r1 } -// Delete provides a mock function with given fields: ctx, orgId -func (_m *Organizations) Delete(ctx context.Context, orgId string) error { - ret := _m.Called(ctx, orgId) +// Delete provides a mock function with given fields: ctx, id +func (_m *Organizations) Delete(ctx context.Context, id string) error { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } var r0 error if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { - r0 = rf(ctx, orgId) + r0 = rf(ctx, id) } else { r0 = ret.Error(0) } @@ -57,7 +68,16 @@ func (_m *Organizations) Delete(ctx context.Context, orgId string) error { func (_m *Organizations) Find(ctx context.Context, filter *organizations.Filter, opts *options.FindOptions) ([]*organizations.Organization, int, error) { ret := _m.Called(ctx, filter, opts) + if len(ret) == 0 { + panic("no return value specified for Find") + } + var r0 []*organizations.Organization + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *organizations.Filter, *options.FindOptions) ([]*organizations.Organization, int, error)); ok { + return rf(ctx, filter, opts) + } if rf, ok := ret.Get(0).(func(context.Context, *organizations.Filter, *options.FindOptions) []*organizations.Organization); ok { r0 = rf(ctx, filter, opts) } else { @@ -66,14 +86,12 @@ func (_m *Organizations) Find(ctx context.Context, filter *organizations.Filter, } } - var r1 int if rf, ok := ret.Get(1).(func(context.Context, *organizations.Filter, *options.FindOptions) int); ok { r1 = rf(ctx, filter, opts) } else { r1 = ret.Get(1).(int) } - var r2 error if rf, ok := ret.Get(2).(func(context.Context, *organizations.Filter, *options.FindOptions) error); ok { r2 = rf(ctx, filter, opts) } else { @@ -83,22 +101,29 @@ func (_m *Organizations) Find(ctx context.Context, filter *organizations.Filter, return r0, r1, r2 } -// Get provides a mock function with given fields: ctx, orgId -func (_m *Organizations) Get(ctx context.Context, orgId string) (*organizations.Organization, error) { - ret := _m.Called(ctx, orgId) +// Get provides a mock function with given fields: ctx, id +func (_m *Organizations) Get(ctx context.Context, id string) (*organizations.Organization, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for Get") + } var r0 *organizations.Organization + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*organizations.Organization, error)); ok { + return rf(ctx, id) + } if rf, ok := ret.Get(0).(func(context.Context, string) *organizations.Organization); ok { - r0 = rf(ctx, orgId) + r0 = rf(ctx, id) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*organizations.Organization) } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { - r1 = rf(ctx, orgId) + r1 = rf(ctx, id) } else { r1 = ret.Error(1) } @@ -110,6 +135,10 @@ func (_m *Organizations) Get(ctx context.Context, orgId string) (*organizations. func (_m *Organizations) Update(ctx context.Context, org *organizations.Organization) error { ret := _m.Called(ctx, org) + if len(ret) == 0 { + panic("no return value specified for Update") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, *organizations.Organization) error); ok { r0 = rf(ctx, org) @@ -120,13 +149,12 @@ func (_m *Organizations) Update(ctx context.Context, org *organizations.Organiza return r0 } -type mockConstructorTestingTNewOrganizations interface { +// NewOrganizations creates a new instance of Organizations. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewOrganizations(t interface { mock.TestingT Cleanup(func()) -} - -// NewOrganizations creates a new instance of Organizations. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewOrganizations(t mockConstructorTestingTNewOrganizations) *Organizations { +}) *Organizations { mock := &Organizations{} mock.Mock.Test(t) diff --git a/pkg/organizations/mocks/Storage.go b/pkg/organizations/mocks/Storage.go index 6b2b7176ff452b0e5935b352ccc3ee112182eb0b..fb12d461ae3d24f6217aceec36f96eb4f79d726c 100644 --- a/pkg/organizations/mocks/Storage.go +++ b/pkg/organizations/mocks/Storage.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.15.0. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -20,7 +20,15 @@ type Storage struct { func (_m *Storage) Create(ctx context.Context, org *organizations.Organization) (*organizations.Organization, error) { ret := _m.Called(ctx, org) + if len(ret) == 0 { + panic("no return value specified for Create") + } + var r0 *organizations.Organization + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *organizations.Organization) (*organizations.Organization, error)); ok { + return rf(ctx, org) + } if rf, ok := ret.Get(0).(func(context.Context, *organizations.Organization) *organizations.Organization); ok { r0 = rf(ctx, org) } else { @@ -29,7 +37,6 @@ func (_m *Storage) Create(ctx context.Context, org *organizations.Organization) } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, *organizations.Organization) error); ok { r1 = rf(ctx, org) } else { @@ -43,14 +50,21 @@ func (_m *Storage) Create(ctx context.Context, org *organizations.Organization) func (_m *Storage) Delete(ctx context.Context, filter *organizations.Filter) (int, error) { ret := _m.Called(ctx, filter) + if len(ret) == 0 { + panic("no return value specified for Delete") + } + var r0 int + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *organizations.Filter) (int, error)); ok { + return rf(ctx, filter) + } if rf, ok := ret.Get(0).(func(context.Context, *organizations.Filter) int); ok { r0 = rf(ctx, filter) } else { r0 = ret.Get(0).(int) } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, *organizations.Filter) error); ok { r1 = rf(ctx, filter) } else { @@ -64,7 +78,16 @@ func (_m *Storage) Delete(ctx context.Context, filter *organizations.Filter) (in func (_m *Storage) Find(ctx context.Context, filter *organizations.Filter, opts *options.FindOptions) ([]*organizations.Organization, int, error) { ret := _m.Called(ctx, filter, opts) + if len(ret) == 0 { + panic("no return value specified for Find") + } + var r0 []*organizations.Organization + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *organizations.Filter, *options.FindOptions) ([]*organizations.Organization, int, error)); ok { + return rf(ctx, filter, opts) + } if rf, ok := ret.Get(0).(func(context.Context, *organizations.Filter, *options.FindOptions) []*organizations.Organization); ok { r0 = rf(ctx, filter, opts) } else { @@ -73,14 +96,12 @@ func (_m *Storage) Find(ctx context.Context, filter *organizations.Filter, opts } } - var r1 int if rf, ok := ret.Get(1).(func(context.Context, *organizations.Filter, *options.FindOptions) int); ok { r1 = rf(ctx, filter, opts) } else { r1 = ret.Get(1).(int) } - var r2 error if rf, ok := ret.Get(2).(func(context.Context, *organizations.Filter, *options.FindOptions) error); ok { r2 = rf(ctx, filter, opts) } else { @@ -94,6 +115,10 @@ func (_m *Storage) Find(ctx context.Context, filter *organizations.Filter, opts func (_m *Storage) Init(ctx context.Context) error { ret := _m.Called(ctx) + if len(ret) == 0 { + panic("no return value specified for Init") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context) error); ok { r0 = rf(ctx) @@ -108,6 +133,10 @@ func (_m *Storage) Init(ctx context.Context) error { func (_m *Storage) Reset(ctx context.Context) error { ret := _m.Called(ctx) + if len(ret) == 0 { + panic("no return value specified for Reset") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context) error); ok { r0 = rf(ctx) @@ -122,21 +151,28 @@ func (_m *Storage) Reset(ctx context.Context) error { func (_m *Storage) Update(ctx context.Context, update *organizations.Organization, filter *organizations.Filter) (int, int, error) { ret := _m.Called(ctx, update, filter) + if len(ret) == 0 { + panic("no return value specified for Update") + } + var r0 int + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *organizations.Organization, *organizations.Filter) (int, int, error)); ok { + return rf(ctx, update, filter) + } if rf, ok := ret.Get(0).(func(context.Context, *organizations.Organization, *organizations.Filter) int); ok { r0 = rf(ctx, update, filter) } else { r0 = ret.Get(0).(int) } - var r1 int if rf, ok := ret.Get(1).(func(context.Context, *organizations.Organization, *organizations.Filter) int); ok { r1 = rf(ctx, update, filter) } else { r1 = ret.Get(1).(int) } - var r2 error if rf, ok := ret.Get(2).(func(context.Context, *organizations.Organization, *organizations.Filter) error); ok { r2 = rf(ctx, update, filter) } else { @@ -146,13 +182,12 @@ func (_m *Storage) Update(ctx context.Context, update *organizations.Organizatio return r0, r1, r2 } -type mockConstructorTestingTNewStorage interface { +// NewStorage creates a new instance of Storage. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewStorage(t interface { mock.TestingT Cleanup(func()) -} - -// NewStorage creates a new instance of Storage. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewStorage(t mockConstructorTestingTNewStorage) *Storage { +}) *Storage { mock := &Storage{} mock.Mock.Test(t) diff --git a/pkg/organizations/mocks/spaceGetter.go b/pkg/organizations/mocks/spaceGetter.go new file mode 100644 index 0000000000000000000000000000000000000000..0dfa462e8b1af6c8feeee2bed7cd7e4c1317d0b1 --- /dev/null +++ b/pkg/organizations/mocks/spaceGetter.go @@ -0,0 +1,42 @@ +// Code generated by mockery v2.46.3. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// spaceGetter is an autogenerated mock type for the spaceGetter type +type spaceGetter struct { + mock.Mock +} + +// GetSpaceID provides a mock function with given fields: +func (_m *spaceGetter) GetSpaceID() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetSpaceID") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// newSpaceGetter creates a new instance of spaceGetter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newSpaceGetter(t interface { + mock.TestingT + Cleanup(func()) +}) *spaceGetter { + mock := &spaceGetter{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/organizations/service.go b/pkg/organizations/service.go index 9ba3b9a91e6acd2353b1cebff342fa6a329547c9..2b058e4f66a1cbefb6633e001b7ca8564ca5cee4 100644 --- a/pkg/organizations/service.go +++ b/pkg/organizations/service.go @@ -12,9 +12,9 @@ import ( type Organizations interface { Create(ctx context.Context, org *Organization) (created *Organization, err error) - Get(ctx context.Context, orgId string) (org *Organization, err error) + Get(ctx context.Context, id string) (org *Organization, err error) Update(ctx context.Context, org *Organization) (err error) - Delete(ctx context.Context, orgId string) (err error) + Delete(ctx context.Context, id string) (err error) Find(ctx context.Context, filter *Filter, opts *options.FindOptions) (orgs []*Organization, total int, err error) } diff --git a/pkg/references/middleware/telemetry_middleware.go b/pkg/references/middleware/telemetry_middleware.go index 3e8fbb773fd9bc548eed3f34f78a4f5adcbe1128..76eab9b32b7ab10252c7af38e3fdfa6dfa0e9058 100644 --- a/pkg/references/middleware/telemetry_middleware.go +++ b/pkg/references/middleware/telemetry_middleware.go @@ -10,7 +10,7 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/items" "git.perx.ru/perxis/perxis-go/pkg/references" @@ -74,7 +74,7 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, envId str if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -123,7 +123,7 @@ func (_d telemetryMiddleware) Publish(ctx context.Context, spaceId string, envId if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } diff --git a/pkg/roles/middleware/access_logging_middleware.go b/pkg/roles/middleware/access_logging_middleware.go index 310cdeda7c585c571263bebb6c42739a8d3074de..e99ecd7b5cc47e1f4448124d9ec158f655917574 100644 --- a/pkg/roles/middleware/access_logging_middleware.go +++ b/pkg/roles/middleware/access_logging_middleware.go @@ -50,16 +50,16 @@ func (m *accessLoggingMiddleware) Create(ctx context.Context, role *roles.Role) return created, err } -func (m *accessLoggingMiddleware) Delete(ctx context.Context, spaceId string, roleId string) (err error) { +func (m *accessLoggingMiddleware) Delete(ctx context.Context, spaceId string, id string) (err error) { begin := time.Now() m.logger.Debug("Delete.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), zap.Reflect("spaceId", spaceId), - zap.Reflect("roleId", roleId), + zap.Reflect("id", id), ) - err = m.next.Delete(ctx, spaceId, roleId) + err = m.next.Delete(ctx, spaceId, id) m.logger.Debug("Delete.Response", zap.Duration("time", time.Since(begin)), @@ -69,16 +69,16 @@ func (m *accessLoggingMiddleware) Delete(ctx context.Context, spaceId string, ro return err } -func (m *accessLoggingMiddleware) Get(ctx context.Context, spaceId string, roleId string) (role *roles.Role, err error) { +func (m *accessLoggingMiddleware) Get(ctx context.Context, spaceId string, id string) (role *roles.Role, err error) { begin := time.Now() m.logger.Debug("Get.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), zap.Reflect("spaceId", spaceId), - zap.Reflect("roleId", roleId), + zap.Reflect("id", id), ) - role, err = m.next.Get(ctx, spaceId, roleId) + role, err = m.next.Get(ctx, spaceId, id) m.logger.Debug("Get.Response", zap.Duration("time", time.Since(begin)), diff --git a/pkg/roles/middleware/caching_middleware.go b/pkg/roles/middleware/caching_middleware.go index 2bcb04d3df7278d619fe80b2a6b02c48ea58f1fb..40108b39ceb7131069e489111b01fe29e7b4534d 100644 --- a/pkg/roles/middleware/caching_middleware.go +++ b/pkg/roles/middleware/caching_middleware.go @@ -35,13 +35,13 @@ func (m cachingMiddleware) Create(ctx context.Context, role *service.Role) (rl * return rl, err } -func (m cachingMiddleware) Get(ctx context.Context, spaceId string, roleId string) (rl *service.Role, err error) { - key := makeKey(spaceId, roleId) +func (m cachingMiddleware) Get(ctx context.Context, spaceId string, id string) (rl *service.Role, err error) { + key := makeKey(spaceId, id) value, e := m.cache.Get(key) if e == nil { return value.(*service.Role).Clone(), nil } - rl, err = m.next.Get(ctx, spaceId, roleId) + rl, err = m.next.Get(ctx, spaceId, id) if err == nil { _ = m.cache.Set(key, rl) return rl.Clone(), nil @@ -72,10 +72,10 @@ func (m cachingMiddleware) Update(ctx context.Context, role *service.Role) (err return err } -func (m cachingMiddleware) Delete(ctx context.Context, spaceId string, roleId string) (err error) { - err = m.next.Delete(ctx, spaceId, roleId) +func (m cachingMiddleware) Delete(ctx context.Context, spaceId string, id string) (err error) { + err = m.next.Delete(ctx, spaceId, id) if err == nil { - key := makeKey(spaceId, roleId) + key := makeKey(spaceId, id) _ = m.cache.Remove(key) _ = m.cache.Remove(spaceId) } diff --git a/pkg/roles/middleware/error_logging_middleware.go b/pkg/roles/middleware/error_logging_middleware.go index bb6073d11fef1d2763ca85855274edf4a8c71839..cd12049781967486aea31b6667ef6b61dc213493 100644 --- a/pkg/roles/middleware/error_logging_middleware.go +++ b/pkg/roles/middleware/error_logging_middleware.go @@ -39,24 +39,24 @@ func (m *errorLoggingMiddleware) Create(ctx context.Context, role *roles.Role) ( return m.next.Create(ctx, role) } -func (m *errorLoggingMiddleware) Delete(ctx context.Context, spaceId string, roleId string) (err error) { +func (m *errorLoggingMiddleware) Delete(ctx context.Context, spaceId string, id string) (err error) { logger := m.logger defer func() { if err != nil { logger.Warn("response error", zap.Error(err)) } }() - return m.next.Delete(ctx, spaceId, roleId) + return m.next.Delete(ctx, spaceId, id) } -func (m *errorLoggingMiddleware) Get(ctx context.Context, spaceId string, roleId string) (role *roles.Role, err error) { +func (m *errorLoggingMiddleware) Get(ctx context.Context, spaceId string, id string) (role *roles.Role, err error) { logger := m.logger defer func() { if err != nil { logger.Warn("response error", zap.Error(err)) } }() - return m.next.Get(ctx, spaceId, roleId) + return m.next.Get(ctx, spaceId, id) } func (m *errorLoggingMiddleware) List(ctx context.Context, spaceId string) (roles []*roles.Role, err error) { diff --git a/pkg/roles/middleware/logging_middleware.go b/pkg/roles/middleware/logging_middleware.go index 9221265df1603f93be2c344c8c559eb8811e60de..ed480ab756cbadaa8e2447698abc3f255e968618 100644 --- a/pkg/roles/middleware/logging_middleware.go +++ b/pkg/roles/middleware/logging_middleware.go @@ -3,7 +3,7 @@ package middleware import ( "context" - "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/roles" logzap "git.perx.ru/perxis/perxis-go/zap" "go.uber.org/zap" @@ -40,13 +40,13 @@ func (m *loggingMiddleware) Create(ctx context.Context, role *roles.Role) (creat return created, err } -func (m *loggingMiddleware) Get(ctx context.Context, spaceId, roleId string) (role *roles.Role, err error) { +func (m *loggingMiddleware) Get(ctx context.Context, spaceId, id string) (role *roles.Role, err error) { logger := m.logger.With( logzap.Caller(ctx), - logzap.Object(id.NewRoleId(spaceId, roleId)), + logzap.Object(pkgId.NewRoleId(spaceId, id)), ) - role, err = m.next.Get(ctx, spaceId, roleId) + role, err = m.next.Get(ctx, spaceId, id) if err != nil { logger.Error("Failed to get", zap.Error(err)) return @@ -87,14 +87,14 @@ func (m *loggingMiddleware) Update(ctx context.Context, role *roles.Role) (err e return err } -func (m *loggingMiddleware) Delete(ctx context.Context, spaceId, roleId string) (err error) { +func (m *loggingMiddleware) Delete(ctx context.Context, spaceId, id string) (err error) { logger := m.logger.With( logzap.Caller(ctx), logzap.Event(roles.EventDelete), - logzap.Object(id.NewRoleId(spaceId, roleId)), + logzap.Object(pkgId.NewRoleId(spaceId, id)), ) - err = m.next.Delete(ctx, spaceId, roleId) + err = m.next.Delete(ctx, spaceId, id) if err != nil { logger.Error("Failed to delete", zap.Error(err), logzap.Channels(logzap.Userlog, logzap.Syslog)) return diff --git a/pkg/roles/middleware/recovering_middleware.go b/pkg/roles/middleware/recovering_middleware.go index cb30a49b624712d6f37de4cd8c74ee65f9f71358..bb3909721a65f7b3a5295afbb8cb7a5bd2d84d91 100644 --- a/pkg/roles/middleware/recovering_middleware.go +++ b/pkg/roles/middleware/recovering_middleware.go @@ -42,7 +42,7 @@ func (m *recoveringMiddleware) Create(ctx context.Context, role *roles.Role) (cr return m.next.Create(ctx, role) } -func (m *recoveringMiddleware) Delete(ctx context.Context, spaceId string, roleId string) (err error) { +func (m *recoveringMiddleware) Delete(ctx context.Context, spaceId string, id string) (err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -51,10 +51,10 @@ func (m *recoveringMiddleware) Delete(ctx context.Context, spaceId string, roleI } }() - return m.next.Delete(ctx, spaceId, roleId) + return m.next.Delete(ctx, spaceId, id) } -func (m *recoveringMiddleware) Get(ctx context.Context, spaceId string, roleId string) (role *roles.Role, err error) { +func (m *recoveringMiddleware) Get(ctx context.Context, spaceId string, id string) (role *roles.Role, err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -63,7 +63,7 @@ func (m *recoveringMiddleware) Get(ctx context.Context, spaceId string, roleId s } }() - return m.next.Get(ctx, spaceId, roleId) + return m.next.Get(ctx, spaceId, id) } func (m *recoveringMiddleware) List(ctx context.Context, spaceId string) (roles []*roles.Role, err error) { diff --git a/pkg/roles/middleware/telemetry_middleware.go b/pkg/roles/middleware/telemetry_middleware.go index 7403575220d93fe24a00b0a8de749371e57904b0..cf5fe9516111e46ee07dd27c5dc1ae25b19e1829 100644 --- a/pkg/roles/middleware/telemetry_middleware.go +++ b/pkg/roles/middleware/telemetry_middleware.go @@ -10,7 +10,7 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/roles" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" @@ -84,7 +84,7 @@ func (_d telemetryMiddleware) Create(ctx context.Context, role *roles.Role) (cre if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -109,7 +109,7 @@ func (_d telemetryMiddleware) Create(ctx context.Context, role *roles.Role) (cre } // Delete implements roles.Roles -func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, roleId string) (err error) { +func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, id string) (err error) { var att = []attribute.KeyValue{ attribute.String("service", "Roles"), attribute.String("method", "Delete"), @@ -120,7 +120,7 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, roleId ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Roles.Delete") defer _span.End() - err = _d.Roles.Delete(ctx, spaceId, roleId) + err = _d.Roles.Delete(ctx, spaceId, id) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) @@ -129,7 +129,7 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, roleId if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -140,7 +140,7 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, roleId _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, "spaceId": spaceId, - "roleId": roleId}, map[string]interface{}{ + "id": id}, map[string]interface{}{ "err": err}) } else if err != nil { _d.requestMetrics.FailedTotal.Add(ctx, 1, attributes) @@ -154,7 +154,7 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string, roleId } // Get implements roles.Roles -func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, roleId string) (role *roles.Role, err error) { +func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, id string) (role *roles.Role, err error) { var att = []attribute.KeyValue{ attribute.String("service", "Roles"), attribute.String("method", "Get"), @@ -165,7 +165,7 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, roleId st ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Roles.Get") defer _span.End() - role, err = _d.Roles.Get(ctx, spaceId, roleId) + role, err = _d.Roles.Get(ctx, spaceId, id) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) @@ -174,7 +174,7 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, roleId st if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -185,7 +185,7 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string, roleId st _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, "spaceId": spaceId, - "roleId": roleId}, map[string]interface{}{ + "id": id}, map[string]interface{}{ "role": role, "err": err}) } else if err != nil { @@ -220,7 +220,7 @@ func (_d telemetryMiddleware) List(ctx context.Context, spaceId string) (roles [ if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -276,7 +276,7 @@ func (_d telemetryMiddleware) Update(ctx context.Context, role *roles.Role) (err if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } diff --git a/pkg/roles/mocks/Middleware.go b/pkg/roles/mocks/Middleware.go index 507b37154a40a1176a940bd29b6a6d23556a6bba..ed5837a49dee4ce01d9cbd28150de00722a0daf2 100644 --- a/pkg/roles/mocks/Middleware.go +++ b/pkg/roles/mocks/Middleware.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -16,6 +16,10 @@ type Middleware struct { func (_m *Middleware) Execute(_a0 roles.Roles) roles.Roles { ret := _m.Called(_a0) + if len(ret) == 0 { + panic("no return value specified for Execute") + } + var r0 roles.Roles if rf, ok := ret.Get(0).(func(roles.Roles) roles.Roles); ok { r0 = rf(_a0) diff --git a/pkg/roles/mocks/Roles.go b/pkg/roles/mocks/Roles.go index 08c523e06bc5082685ea1f7669a4b15849712222..d37c9a56dfddaec983869060c94c1c58d5cb36ce 100644 --- a/pkg/roles/mocks/Roles.go +++ b/pkg/roles/mocks/Roles.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -18,6 +18,10 @@ type Roles struct { func (_m *Roles) Create(ctx context.Context, role *roles.Role) (*roles.Role, error) { ret := _m.Called(ctx, role) + if len(ret) == 0 { + panic("no return value specified for Create") + } + var r0 *roles.Role var r1 error if rf, ok := ret.Get(0).(func(context.Context, *roles.Role) (*roles.Role, error)); ok { @@ -40,13 +44,17 @@ func (_m *Roles) Create(ctx context.Context, role *roles.Role) (*roles.Role, err return r0, r1 } -// Delete provides a mock function with given fields: ctx, spaceId, roleId -func (_m *Roles) Delete(ctx context.Context, spaceId string, roleId string) error { - ret := _m.Called(ctx, spaceId, roleId) +// Delete provides a mock function with given fields: ctx, spaceId, id +func (_m *Roles) Delete(ctx context.Context, spaceId string, id string) error { + ret := _m.Called(ctx, spaceId, id) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, string) error); ok { - r0 = rf(ctx, spaceId, roleId) + r0 = rf(ctx, spaceId, id) } else { r0 = ret.Error(0) } @@ -54,17 +62,21 @@ func (_m *Roles) Delete(ctx context.Context, spaceId string, roleId string) erro return r0 } -// Get provides a mock function with given fields: ctx, spaceId, roleId -func (_m *Roles) Get(ctx context.Context, spaceId string, roleId string) (*roles.Role, error) { - ret := _m.Called(ctx, spaceId, roleId) +// Get provides a mock function with given fields: ctx, spaceId, id +func (_m *Roles) Get(ctx context.Context, spaceId string, id string) (*roles.Role, error) { + ret := _m.Called(ctx, spaceId, id) + + if len(ret) == 0 { + panic("no return value specified for Get") + } var r0 *roles.Role var r1 error if rf, ok := ret.Get(0).(func(context.Context, string, string) (*roles.Role, error)); ok { - return rf(ctx, spaceId, roleId) + return rf(ctx, spaceId, id) } if rf, ok := ret.Get(0).(func(context.Context, string, string) *roles.Role); ok { - r0 = rf(ctx, spaceId, roleId) + r0 = rf(ctx, spaceId, id) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*roles.Role) @@ -72,7 +84,7 @@ func (_m *Roles) Get(ctx context.Context, spaceId string, roleId string) (*roles } if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { - r1 = rf(ctx, spaceId, roleId) + r1 = rf(ctx, spaceId, id) } else { r1 = ret.Error(1) } @@ -84,6 +96,10 @@ func (_m *Roles) Get(ctx context.Context, spaceId string, roleId string) (*roles func (_m *Roles) List(ctx context.Context, spaceId string) ([]*roles.Role, error) { ret := _m.Called(ctx, spaceId) + if len(ret) == 0 { + panic("no return value specified for List") + } + var r0 []*roles.Role var r1 error if rf, ok := ret.Get(0).(func(context.Context, string) ([]*roles.Role, error)); ok { @@ -110,6 +126,10 @@ func (_m *Roles) List(ctx context.Context, spaceId string) ([]*roles.Role, error func (_m *Roles) Update(ctx context.Context, role *roles.Role) error { ret := _m.Called(ctx, role) + if len(ret) == 0 { + panic("no return value specified for Update") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, *roles.Role) error); ok { r0 = rf(ctx, role) diff --git a/pkg/roles/mocks/Storage.go b/pkg/roles/mocks/Storage.go index dc01f165aa37163cf23f28302e9f90f72420171e..e1a73b7c4d080f454743757ae67ab0058cc21a2a 100644 --- a/pkg/roles/mocks/Storage.go +++ b/pkg/roles/mocks/Storage.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -20,6 +20,10 @@ type Storage struct { func (_m *Storage) Create(ctx context.Context, role *roles.Role) (*roles.Role, error) { ret := _m.Called(ctx, role) + if len(ret) == 0 { + panic("no return value specified for Create") + } + var r0 *roles.Role var r1 error if rf, ok := ret.Get(0).(func(context.Context, *roles.Role) (*roles.Role, error)); ok { @@ -46,6 +50,10 @@ func (_m *Storage) Create(ctx context.Context, role *roles.Role) (*roles.Role, e func (_m *Storage) Delete(ctx context.Context, spaceID string, roleID string) error { ret := _m.Called(ctx, spaceID, roleID) + if len(ret) == 0 { + panic("no return value specified for Delete") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, string) error); ok { r0 = rf(ctx, spaceID, roleID) @@ -60,6 +68,10 @@ func (_m *Storage) Delete(ctx context.Context, spaceID string, roleID string) er func (_m *Storage) Find(ctx context.Context, spaceID string, f *roles.Filter, opts *options.FindOptions) ([]*roles.Role, int, error) { ret := _m.Called(ctx, spaceID, f, opts) + if len(ret) == 0 { + panic("no return value specified for Find") + } + var r0 []*roles.Role var r1 int var r2 error @@ -93,6 +105,10 @@ func (_m *Storage) Find(ctx context.Context, spaceID string, f *roles.Filter, op func (_m *Storage) Reset(ctx context.Context, spaceID string) error { ret := _m.Called(ctx, spaceID) + if len(ret) == 0 { + panic("no return value specified for Reset") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { r0 = rf(ctx, spaceID) @@ -107,6 +123,10 @@ func (_m *Storage) Reset(ctx context.Context, spaceID string) error { func (_m *Storage) Update(ctx context.Context, role *roles.Role) (int, int, error) { ret := _m.Called(ctx, role) + if len(ret) == 0 { + panic("no return value specified for Update") + } + var r0 int var r1 int var r2 error diff --git a/pkg/roles/mocks/spaceGetter.go b/pkg/roles/mocks/spaceGetter.go new file mode 100644 index 0000000000000000000000000000000000000000..0dfa462e8b1af6c8feeee2bed7cd7e4c1317d0b1 --- /dev/null +++ b/pkg/roles/mocks/spaceGetter.go @@ -0,0 +1,42 @@ +// Code generated by mockery v2.46.3. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// spaceGetter is an autogenerated mock type for the spaceGetter type +type spaceGetter struct { + mock.Mock +} + +// GetSpaceID provides a mock function with given fields: +func (_m *spaceGetter) GetSpaceID() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetSpaceID") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// newSpaceGetter creates a new instance of spaceGetter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newSpaceGetter(t interface { + mock.TestingT + Cleanup(func()) +}) *spaceGetter { + mock := &spaceGetter{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/roles/service.go b/pkg/roles/service.go index b003008b10c7c0a0de6549c60262741fdf441f65..17d04aa857882cd0c5d8c66eaf93ebef400a1fad 100644 --- a/pkg/roles/service.go +++ b/pkg/roles/service.go @@ -9,8 +9,8 @@ import ( // @grpc-addr content.roles.Roles type Roles interface { Create(ctx context.Context, role *Role) (created *Role, err error) - Get(ctx context.Context, spaceId, roleId string) (role *Role, err error) + Get(ctx context.Context, spaceId, id string) (role *Role, err error) List(ctx context.Context, spaceId string) (roles []*Role, err error) Update(ctx context.Context, role *Role) (err error) - Delete(ctx context.Context, spaceId, roleId string) (err error) + Delete(ctx context.Context, spaceId, id string) (err error) } diff --git a/pkg/spaces/middleware/access_logging_middleware.go b/pkg/spaces/middleware/access_logging_middleware.go index d155ee1f0d95daad6b29c5961604cdc8b466fcd9..bfcc12f7f69f137a9327f95508b0b209a31411f6 100644 --- a/pkg/spaces/middleware/access_logging_middleware.go +++ b/pkg/spaces/middleware/access_logging_middleware.go @@ -32,15 +32,15 @@ func AccessLoggingMiddleware(logger *zap.Logger) Middleware { } } -func (m *accessLoggingMiddleware) AbortTransfer(ctx context.Context, spaceID string) (err error) { +func (m *accessLoggingMiddleware) AbortTransfer(ctx context.Context, id string) (err error) { begin := time.Now() m.logger.Debug("AbortTransfer.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), - zap.Reflect("spaceID", spaceID), + zap.Reflect("id", id), ) - err = m.next.AbortTransfer(ctx, spaceID) + err = m.next.AbortTransfer(ctx, id) m.logger.Debug("AbortTransfer.Response", zap.Duration("time", time.Since(begin)), @@ -69,15 +69,15 @@ func (m *accessLoggingMiddleware) Create(ctx context.Context, space *spaces.Spac return created, err } -func (m *accessLoggingMiddleware) Delete(ctx context.Context, spaceId string) (err error) { +func (m *accessLoggingMiddleware) Delete(ctx context.Context, id string) (err error) { begin := time.Now() m.logger.Debug("Delete.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), - zap.Reflect("spaceId", spaceId), + zap.Reflect("id", id), ) - err = m.next.Delete(ctx, spaceId) + err = m.next.Delete(ctx, id) m.logger.Debug("Delete.Response", zap.Duration("time", time.Since(begin)), @@ -108,15 +108,15 @@ func (m *accessLoggingMiddleware) Find(ctx context.Context, filter *spaces.Filte return spaces, total, err } -func (m *accessLoggingMiddleware) Get(ctx context.Context, spaceId string) (space *spaces.Space, err error) { +func (m *accessLoggingMiddleware) Get(ctx context.Context, id string) (space *spaces.Space, err error) { begin := time.Now() m.logger.Debug("Get.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), - zap.Reflect("spaceId", spaceId), + zap.Reflect("id", id), ) - space, err = m.next.Get(ctx, spaceId) + space, err = m.next.Get(ctx, id) m.logger.Debug("Get.Response", zap.Duration("time", time.Since(begin)), @@ -165,16 +165,16 @@ func (m *accessLoggingMiddleware) ListTransfers(ctx context.Context, orgID strin return spaces, err } -func (m *accessLoggingMiddleware) Move(ctx context.Context, spaceID string, orgID string) (err error) { +func (m *accessLoggingMiddleware) Move(ctx context.Context, id string, orgID string) (err error) { begin := time.Now() m.logger.Debug("Move.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), - zap.Reflect("spaceID", spaceID), + zap.Reflect("id", id), zap.Reflect("orgID", orgID), ) - err = m.next.Move(ctx, spaceID, orgID) + err = m.next.Move(ctx, id, orgID) m.logger.Debug("Move.Response", zap.Duration("time", time.Since(begin)), @@ -184,16 +184,16 @@ func (m *accessLoggingMiddleware) Move(ctx context.Context, spaceID string, orgI return err } -func (m *accessLoggingMiddleware) SetState(ctx context.Context, spaceID string, state *spaces.StateInfo) (err error) { +func (m *accessLoggingMiddleware) SetState(ctx context.Context, id string, state *spaces.StateInfo) (err error) { begin := time.Now() m.logger.Debug("SetState.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), - zap.Reflect("spaceID", spaceID), + zap.Reflect("id", id), zap.Reflect("state", state), ) - err = m.next.SetState(ctx, spaceID, state) + err = m.next.SetState(ctx, id, state) m.logger.Debug("SetState.Response", zap.Duration("time", time.Since(begin)), @@ -203,16 +203,16 @@ func (m *accessLoggingMiddleware) SetState(ctx context.Context, spaceID string, return err } -func (m *accessLoggingMiddleware) Transfer(ctx context.Context, spaceID string, transferToOrg string) (err error) { +func (m *accessLoggingMiddleware) Transfer(ctx context.Context, id string, transferToOrg string) (err error) { begin := time.Now() m.logger.Debug("Transfer.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), - zap.Reflect("spaceID", spaceID), + zap.Reflect("id", id), zap.Reflect("transferToOrg", transferToOrg), ) - err = m.next.Transfer(ctx, spaceID, transferToOrg) + err = m.next.Transfer(ctx, id, transferToOrg) m.logger.Debug("Transfer.Response", zap.Duration("time", time.Since(begin)), @@ -240,16 +240,16 @@ func (m *accessLoggingMiddleware) Update(ctx context.Context, space *spaces.Spac return err } -func (m *accessLoggingMiddleware) UpdateConfig(ctx context.Context, spaceId string, config *spaces.Config) (err error) { +func (m *accessLoggingMiddleware) UpdateConfig(ctx context.Context, id string, config *spaces.Config) (err error) { begin := time.Now() m.logger.Debug("UpdateConfig.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), - zap.Reflect("spaceId", spaceId), + zap.Reflect("id", id), zap.Reflect("config", config), ) - err = m.next.UpdateConfig(ctx, spaceId, config) + err = m.next.UpdateConfig(ctx, id, config) m.logger.Debug("UpdateConfig.Response", zap.Duration("time", time.Since(begin)), diff --git a/pkg/spaces/middleware/caching_middleware.go b/pkg/spaces/middleware/caching_middleware.go index c7f35de12106e9aa828e56ebd6f6ec4361c70da7..f87ba81d26a266608a4e090c57a28ebf151f8825 100644 --- a/pkg/spaces/middleware/caching_middleware.go +++ b/pkg/spaces/middleware/caching_middleware.go @@ -36,15 +36,15 @@ func (m cachingMiddleware) Create(ctx context.Context, space *service.Space) (sp return sp, err } -func (m cachingMiddleware) Get(ctx context.Context, spaceId string) (sp *service.Space, err error) { +func (m cachingMiddleware) Get(ctx context.Context, id string) (sp *service.Space, err error) { - value, e := m.cache.Get(spaceId) + value, e := m.cache.Get(id) if e == nil { return value.(*service.Space).Clone(), nil } - sp, err = m.next.Get(ctx, spaceId) + sp, err = m.next.Get(ctx, id) if err == nil { - _ = m.cache.Set(spaceId, sp) + _ = m.cache.Set(id, sp) return sp.Clone(), nil } return nil, err @@ -85,73 +85,73 @@ func (m cachingMiddleware) Update(ctx context.Context, space *service.Space) (er return err } -func (m cachingMiddleware) UpdateConfig(ctx context.Context, spaceId string, config *service.Config) (err error) { +func (m cachingMiddleware) UpdateConfig(ctx context.Context, id string, config *service.Config) (err error) { - err = m.next.UpdateConfig(ctx, spaceId, config) + err = m.next.UpdateConfig(ctx, id, config) if err == nil { - value, e := m.cache.Get(spaceId) + value, e := m.cache.Get(id) if e == nil { space := value.(*service.Space) _ = m.cache.Remove(orgKey(space.OrgID)) } - _ = m.cache.Remove(spaceId) + _ = m.cache.Remove(id) } return err } -func (m cachingMiddleware) SetState(ctx context.Context, spaceID string, state *service.StateInfo) (err error) { +func (m cachingMiddleware) SetState(ctx context.Context, id string, state *service.StateInfo) (err error) { - err = m.next.SetState(ctx, spaceID, state) + err = m.next.SetState(ctx, id, state) if err == nil { - value, e := m.cache.Get(spaceID) + value, e := m.cache.Get(id) if e == nil { space := value.(*service.Space) _ = m.cache.Remove(orgKey(space.OrgID)) } - _ = m.cache.Remove(spaceID) + _ = m.cache.Remove(id) } return err } -func (m cachingMiddleware) Delete(ctx context.Context, spaceId string) (err error) { +func (m cachingMiddleware) Delete(ctx context.Context, id string) (err error) { - err = m.next.Delete(ctx, spaceId) + err = m.next.Delete(ctx, id) if err == nil { - value, e := m.cache.Get(spaceId) + value, e := m.cache.Get(id) if e == nil { space := value.(*service.Space) _ = m.cache.Remove(orgKey(space.OrgID)) } - _ = m.cache.Remove(spaceId) + _ = m.cache.Remove(id) } return err } -func (m cachingMiddleware) Transfer(ctx context.Context, spaceID, transferToOrg string) error { - err := m.next.Transfer(ctx, spaceID, transferToOrg) +func (m cachingMiddleware) Transfer(ctx context.Context, id, transferToOrg string) error { + err := m.next.Transfer(ctx, id, transferToOrg) if err == nil { - value, e := m.cache.Get(spaceID) + value, e := m.cache.Get(id) if e == nil { space := value.(*service.Space) _ = m.cache.Remove(orgKey(space.OrgID)) _ = m.cache.Remove(orgKey(space.TransferToOrg)) } - _ = m.cache.Remove(spaceID) + _ = m.cache.Remove(id) _ = m.cache.Remove(transferToOrg) } return err } -func (m cachingMiddleware) AbortTransfer(ctx context.Context, spaceID string) error { - err := m.next.AbortTransfer(ctx, spaceID) +func (m cachingMiddleware) AbortTransfer(ctx context.Context, id string) error { + err := m.next.AbortTransfer(ctx, id) if err == nil { - value, e := m.cache.Get(spaceID) + value, e := m.cache.Get(id) if e == nil { space := value.(*service.Space) _ = m.cache.Remove(orgKey(space.OrgID)) _ = m.cache.Remove(orgKey(space.TransferToOrg)) } - _ = m.cache.Remove(spaceID) + _ = m.cache.Remove(id) } return err } @@ -160,16 +160,16 @@ func (m cachingMiddleware) ListTransfers(ctx context.Context, orgID string) (spa return m.next.ListTransfers(ctx, orgID) } -func (m cachingMiddleware) Move(ctx context.Context, spaceID, orgID string) error { - err := m.next.Move(ctx, spaceID, orgID) +func (m cachingMiddleware) Move(ctx context.Context, id, orgID string) error { + err := m.next.Move(ctx, id, orgID) if err == nil { - value, e := m.cache.Get(spaceID) + value, e := m.cache.Get(id) if e == nil { space := value.(*service.Space) _ = m.cache.Remove(orgKey(space.OrgID)) _ = m.cache.Remove(orgKey(space.TransferToOrg)) } - _ = m.cache.Remove(spaceID) + _ = m.cache.Remove(id) _ = m.cache.Remove(orgID) } return err diff --git a/pkg/spaces/middleware/error_logging_middleware.go b/pkg/spaces/middleware/error_logging_middleware.go index 677b48366b6304e47988578bcb694ad758ba3ab0..7e26fcc14d5a1d9c3446725b69b141f881efab10 100644 --- a/pkg/spaces/middleware/error_logging_middleware.go +++ b/pkg/spaces/middleware/error_logging_middleware.go @@ -30,14 +30,14 @@ func ErrorLoggingMiddleware(logger *zap.Logger) Middleware { } } -func (m *errorLoggingMiddleware) AbortTransfer(ctx context.Context, spaceID string) (err error) { +func (m *errorLoggingMiddleware) AbortTransfer(ctx context.Context, id string) (err error) { logger := m.logger defer func() { if err != nil { logger.Warn("response error", zap.Error(err)) } }() - return m.next.AbortTransfer(ctx, spaceID) + return m.next.AbortTransfer(ctx, id) } func (m *errorLoggingMiddleware) Create(ctx context.Context, space *spaces.Space) (created *spaces.Space, err error) { @@ -50,14 +50,14 @@ func (m *errorLoggingMiddleware) Create(ctx context.Context, space *spaces.Space return m.next.Create(ctx, space) } -func (m *errorLoggingMiddleware) Delete(ctx context.Context, spaceId string) (err error) { +func (m *errorLoggingMiddleware) Delete(ctx context.Context, id string) (err error) { logger := m.logger defer func() { if err != nil { logger.Warn("response error", zap.Error(err)) } }() - return m.next.Delete(ctx, spaceId) + return m.next.Delete(ctx, id) } func (m *errorLoggingMiddleware) Find(ctx context.Context, filter *spaces.Filter, fo *options.FindOptions) (spaces []*spaces.Space, total int, err error) { @@ -70,14 +70,14 @@ func (m *errorLoggingMiddleware) Find(ctx context.Context, filter *spaces.Filter return m.next.Find(ctx, filter, fo) } -func (m *errorLoggingMiddleware) Get(ctx context.Context, spaceId string) (space *spaces.Space, err error) { +func (m *errorLoggingMiddleware) Get(ctx context.Context, id string) (space *spaces.Space, err error) { logger := m.logger defer func() { if err != nil { logger.Warn("response error", zap.Error(err)) } }() - return m.next.Get(ctx, spaceId) + return m.next.Get(ctx, id) } func (m *errorLoggingMiddleware) List(ctx context.Context, orgId string) (spaces []*spaces.Space, err error) { @@ -100,34 +100,34 @@ func (m *errorLoggingMiddleware) ListTransfers(ctx context.Context, orgID string return m.next.ListTransfers(ctx, orgID) } -func (m *errorLoggingMiddleware) Move(ctx context.Context, spaceID string, orgID string) (err error) { +func (m *errorLoggingMiddleware) Move(ctx context.Context, id string, orgID string) (err error) { logger := m.logger defer func() { if err != nil { logger.Warn("response error", zap.Error(err)) } }() - return m.next.Move(ctx, spaceID, orgID) + return m.next.Move(ctx, id, orgID) } -func (m *errorLoggingMiddleware) SetState(ctx context.Context, spaceID string, state *spaces.StateInfo) (err error) { +func (m *errorLoggingMiddleware) SetState(ctx context.Context, id string, state *spaces.StateInfo) (err error) { logger := m.logger defer func() { if err != nil { logger.Warn("response error", zap.Error(err)) } }() - return m.next.SetState(ctx, spaceID, state) + return m.next.SetState(ctx, id, state) } -func (m *errorLoggingMiddleware) Transfer(ctx context.Context, spaceID string, transferToOrg string) (err error) { +func (m *errorLoggingMiddleware) Transfer(ctx context.Context, id string, transferToOrg string) (err error) { logger := m.logger defer func() { if err != nil { logger.Warn("response error", zap.Error(err)) } }() - return m.next.Transfer(ctx, spaceID, transferToOrg) + return m.next.Transfer(ctx, id, transferToOrg) } func (m *errorLoggingMiddleware) Update(ctx context.Context, space *spaces.Space) (err error) { @@ -140,12 +140,12 @@ func (m *errorLoggingMiddleware) Update(ctx context.Context, space *spaces.Space return m.next.Update(ctx, space) } -func (m *errorLoggingMiddleware) UpdateConfig(ctx context.Context, spaceId string, config *spaces.Config) (err error) { +func (m *errorLoggingMiddleware) UpdateConfig(ctx context.Context, id string, config *spaces.Config) (err error) { logger := m.logger defer func() { if err != nil { logger.Warn("response error", zap.Error(err)) } }() - return m.next.UpdateConfig(ctx, spaceId, config) + return m.next.UpdateConfig(ctx, id, config) } diff --git a/pkg/spaces/middleware/logging_middleware.go b/pkg/spaces/middleware/logging_middleware.go index a45ec2df50923d480f9c94f3c2f26bf266121aff..b21676272cd80fbf3298de84f9d4283b5db71d5e 100644 --- a/pkg/spaces/middleware/logging_middleware.go +++ b/pkg/spaces/middleware/logging_middleware.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/options" "git.perx.ru/perxis/perxis-go/pkg/spaces" @@ -26,14 +26,14 @@ func LoggingMiddleware(logger *zap.Logger) Middleware { } } -func (m *loggingMiddleware) AbortTransfer(ctx context.Context, spaceID string) (err error) { +func (m *loggingMiddleware) AbortTransfer(ctx context.Context, id string) (err error) { logger := m.logger.With( logzap.Caller(ctx), logzap.Event(spaces.EventAbortTransfer), - logzap.Object(id.NewSpaceId(spaceID)), + logzap.Object(pkgId.NewSpaceId(id)), ) - err = m.next.AbortTransfer(ctx, spaceID) + err = m.next.AbortTransfer(ctx, id) if err != nil { logger.Error("Failed to abort transfer", zap.Error(err), logzap.Channels(logzap.Userlog, logzap.Syslog)) return @@ -61,8 +61,8 @@ func (m *loggingMiddleware) Create(ctx context.Context, space *spaces.Space) (cr return created, err } -func (m *loggingMiddleware) Delete(ctx context.Context, spaceId string) (err error) { - space, err := m.Get(ctx, spaceId) +func (m *loggingMiddleware) Delete(ctx context.Context, id string) (err error) { + space, err := m.Get(ctx, id) if err != nil { return err } @@ -70,27 +70,27 @@ func (m *loggingMiddleware) Delete(ctx context.Context, spaceId string) (err err logger := m.logger.With( logzap.Caller(ctx), logzap.Event(spaces.EventDelete), - logzap.Object(id.NewOrganizationId(space.OrgID)), + logzap.Object(pkgId.NewOrganizationId(space.OrgID)), ) - err = m.next.Delete(ctx, spaceId) + err = m.next.Delete(ctx, id) if err != nil { - logger.Error(fmt.Sprintf("Failed to delete space '%s'", spaceId), zap.Error(err), logzap.Channels(logzap.Userlog, logzap.Syslog)) + logger.Error(fmt.Sprintf("Failed to delete space '%s'", id), zap.Error(err), logzap.Channels(logzap.Userlog, logzap.Syslog)) return } - logger.Info(fmt.Sprintf("Space '%s' deleted", spaceId), logzap.Channels(logzap.Userlog)) + logger.Info(fmt.Sprintf("Space '%s' deleted", id), logzap.Channels(logzap.Userlog)) return err } -func (m *loggingMiddleware) Get(ctx context.Context, spaceId string) (space *spaces.Space, err error) { +func (m *loggingMiddleware) Get(ctx context.Context, id string) (space *spaces.Space, err error) { logger := m.logger.With( logzap.Caller(ctx), - logzap.Object(id.NewSpaceId(spaceId)), + logzap.Object(pkgId.NewSpaceId(id)), ) - space, err = m.next.Get(ctx, spaceId) + space, err = m.next.Get(ctx, id) if err != nil { logger.Error("Failed to get", zap.Error(err)) return @@ -141,14 +141,14 @@ func (m *loggingMiddleware) ListTransfers(ctx context.Context, orgID string) (sp return spaces, err } -func (m *loggingMiddleware) Move(ctx context.Context, spaceID string, orgID string) (err error) { +func (m *loggingMiddleware) Move(ctx context.Context, id string, orgID string) (err error) { logger := m.logger.With( logzap.Caller(ctx), logzap.Event(spaces.EventMove), - logzap.Object(id.NewSpaceId(spaceID)), + logzap.Object(pkgId.NewSpaceId(id)), ) - err = m.next.Move(ctx, spaceID, orgID) + err = m.next.Move(ctx, id, orgID) if err != nil { logger.Error("Failed to move", zap.Error(err), logzap.Channels(logzap.Userlog, logzap.Syslog)) return @@ -159,14 +159,14 @@ func (m *loggingMiddleware) Move(ctx context.Context, spaceID string, orgID stri return err } -func (m *loggingMiddleware) Transfer(ctx context.Context, spaceID string, transferToOrg string) (err error) { +func (m *loggingMiddleware) Transfer(ctx context.Context, id string, transferToOrg string) (err error) { logger := m.logger.With( logzap.Caller(ctx), logzap.Event(spaces.EventTransfer), - logzap.Object(id.NewSpaceId(spaceID)), + logzap.Object(pkgId.NewSpaceId(id)), ) - err = m.next.Transfer(ctx, spaceID, transferToOrg) + err = m.next.Transfer(ctx, id, transferToOrg) if err != nil { logger.Error("Failed to transfer", zap.Error(err), logzap.Channels(logzap.Userlog, logzap.Syslog)) return @@ -195,11 +195,11 @@ func (m *loggingMiddleware) Update(ctx context.Context, space *spaces.Space) (er return err } -func (m *loggingMiddleware) SetState(ctx context.Context, spaceID string, state *spaces.StateInfo) (err error) { +func (m *loggingMiddleware) SetState(ctx context.Context, id string, state *spaces.StateInfo) (err error) { logger := m.logger.With( logzap.Caller(ctx), logzap.Event(spaces.EventUpdate), - logzap.Object(id.NewSpaceId(spaceID)), + logzap.Object(pkgId.NewSpaceId(id)), ) var st spaces.State @@ -207,7 +207,7 @@ func (m *loggingMiddleware) SetState(ctx context.Context, spaceID string, state st = state.State } - err = m.next.SetState(ctx, spaceID, state) + err = m.next.SetState(ctx, id, state) if err != nil { logger.Error(fmt.Sprintf("Failed to set state '%s' to space", st), zap.Error(err)) return @@ -217,14 +217,14 @@ func (m *loggingMiddleware) SetState(ctx context.Context, spaceID string, state return err } -func (m *loggingMiddleware) UpdateConfig(ctx context.Context, spaceId string, config *spaces.Config) (err error) { +func (m *loggingMiddleware) UpdateConfig(ctx context.Context, id string, config *spaces.Config) (err error) { logger := m.logger.With( logzap.Caller(ctx), logzap.Event(spaces.EventUpdateConfig), - logzap.Object(id.NewSpaceId(spaceId)), + logzap.Object(pkgId.NewSpaceId(id)), ) - err = m.next.UpdateConfig(ctx, spaceId, config) + err = m.next.UpdateConfig(ctx, id, config) if err != nil { logger.Error("Failed to update config", zap.Error(err), logzap.Channels(logzap.Userlog, logzap.Syslog)) return diff --git a/pkg/spaces/middleware/recovering_middleware.go b/pkg/spaces/middleware/recovering_middleware.go index cca581b6643b32bf21f31964aac200bb9613515d..3ad5b9c334cf992a5c8fc644e54caa3057040e72 100644 --- a/pkg/spaces/middleware/recovering_middleware.go +++ b/pkg/spaces/middleware/recovering_middleware.go @@ -31,7 +31,7 @@ func RecoveringMiddleware(logger *zap.Logger) Middleware { } } -func (m *recoveringMiddleware) AbortTransfer(ctx context.Context, spaceID string) (err error) { +func (m *recoveringMiddleware) AbortTransfer(ctx context.Context, id string) (err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -40,7 +40,7 @@ func (m *recoveringMiddleware) AbortTransfer(ctx context.Context, spaceID string } }() - return m.next.AbortTransfer(ctx, spaceID) + return m.next.AbortTransfer(ctx, id) } func (m *recoveringMiddleware) Create(ctx context.Context, space *spaces.Space) (created *spaces.Space, err error) { @@ -55,7 +55,7 @@ func (m *recoveringMiddleware) Create(ctx context.Context, space *spaces.Space) return m.next.Create(ctx, space) } -func (m *recoveringMiddleware) Delete(ctx context.Context, spaceId string) (err error) { +func (m *recoveringMiddleware) Delete(ctx context.Context, id string) (err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -64,7 +64,7 @@ func (m *recoveringMiddleware) Delete(ctx context.Context, spaceId string) (err } }() - return m.next.Delete(ctx, spaceId) + return m.next.Delete(ctx, id) } func (m *recoveringMiddleware) Find(ctx context.Context, filter *spaces.Filter, fo *options.FindOptions) (spaces []*spaces.Space, total int, err error) { @@ -79,7 +79,7 @@ func (m *recoveringMiddleware) Find(ctx context.Context, filter *spaces.Filter, return m.next.Find(ctx, filter, fo) } -func (m *recoveringMiddleware) Get(ctx context.Context, spaceId string) (space *spaces.Space, err error) { +func (m *recoveringMiddleware) Get(ctx context.Context, id string) (space *spaces.Space, err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -88,7 +88,7 @@ func (m *recoveringMiddleware) Get(ctx context.Context, spaceId string) (space * } }() - return m.next.Get(ctx, spaceId) + return m.next.Get(ctx, id) } func (m *recoveringMiddleware) List(ctx context.Context, orgId string) (spaces []*spaces.Space, err error) { @@ -115,7 +115,7 @@ func (m *recoveringMiddleware) ListTransfers(ctx context.Context, orgID string) return m.next.ListTransfers(ctx, orgID) } -func (m *recoveringMiddleware) Move(ctx context.Context, spaceID string, orgID string) (err error) { +func (m *recoveringMiddleware) Move(ctx context.Context, id string, orgID string) (err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -124,10 +124,10 @@ func (m *recoveringMiddleware) Move(ctx context.Context, spaceID string, orgID s } }() - return m.next.Move(ctx, spaceID, orgID) + return m.next.Move(ctx, id, orgID) } -func (m *recoveringMiddleware) SetState(ctx context.Context, spaceID string, state *spaces.StateInfo) (err error) { +func (m *recoveringMiddleware) SetState(ctx context.Context, id string, state *spaces.StateInfo) (err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -136,10 +136,10 @@ func (m *recoveringMiddleware) SetState(ctx context.Context, spaceID string, sta } }() - return m.next.SetState(ctx, spaceID, state) + return m.next.SetState(ctx, id, state) } -func (m *recoveringMiddleware) Transfer(ctx context.Context, spaceID string, transferToOrg string) (err error) { +func (m *recoveringMiddleware) Transfer(ctx context.Context, id string, transferToOrg string) (err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -148,7 +148,7 @@ func (m *recoveringMiddleware) Transfer(ctx context.Context, spaceID string, tra } }() - return m.next.Transfer(ctx, spaceID, transferToOrg) + return m.next.Transfer(ctx, id, transferToOrg) } func (m *recoveringMiddleware) Update(ctx context.Context, space *spaces.Space) (err error) { @@ -163,7 +163,7 @@ func (m *recoveringMiddleware) Update(ctx context.Context, space *spaces.Space) return m.next.Update(ctx, space) } -func (m *recoveringMiddleware) UpdateConfig(ctx context.Context, spaceId string, config *spaces.Config) (err error) { +func (m *recoveringMiddleware) UpdateConfig(ctx context.Context, id string, config *spaces.Config) (err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -172,5 +172,5 @@ func (m *recoveringMiddleware) UpdateConfig(ctx context.Context, spaceId string, } }() - return m.next.UpdateConfig(ctx, spaceId, config) + return m.next.UpdateConfig(ctx, id, config) } diff --git a/pkg/spaces/middleware/telemetry_middleware.go b/pkg/spaces/middleware/telemetry_middleware.go index 84c90bd6a74bd9bdce5479ae6d100e306916355d..0901e3b3e91786565f3e8fced4e3bb4170764b9e 100644 --- a/pkg/spaces/middleware/telemetry_middleware.go +++ b/pkg/spaces/middleware/telemetry_middleware.go @@ -10,7 +10,7 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/options" "git.perx.ru/perxis/perxis-go/pkg/spaces" @@ -54,7 +54,7 @@ func TelemetryMiddleware(base spaces.Spaces, instance string, spanDecorator ...f } // AbortTransfer implements spaces.Spaces -func (_d telemetryMiddleware) AbortTransfer(ctx context.Context, spaceID string) (err error) { +func (_d telemetryMiddleware) AbortTransfer(ctx context.Context, id string) (err error) { var att = []attribute.KeyValue{ attribute.String("service", "Spaces"), attribute.String("method", "AbortTransfer"), @@ -65,12 +65,12 @@ func (_d telemetryMiddleware) AbortTransfer(ctx context.Context, spaceID string) ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Spaces.AbortTransfer") defer _span.End() - err = _d.Spaces.AbortTransfer(ctx, spaceID) + err = _d.Spaces.AbortTransfer(ctx, id) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) var spID string - params := []interface{}{ctx, spaceID, err} + params := []interface{}{ctx, id, err} for _, p := range params { if p == nil { continue @@ -85,7 +85,7 @@ func (_d telemetryMiddleware) AbortTransfer(ctx context.Context, spaceID string) if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -94,8 +94,8 @@ func (_d telemetryMiddleware) AbortTransfer(ctx context.Context, spaceID string) if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ - "ctx": ctx, - "spaceID": spaceID}, map[string]interface{}{ + "ctx": ctx, + "id": id}, map[string]interface{}{ "err": err}) } else if err != nil { _d.requestMetrics.FailedTotal.Add(ctx, 1, attributes) @@ -140,7 +140,7 @@ func (_d telemetryMiddleware) Create(ctx context.Context, space *spaces.Space) ( if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -165,7 +165,7 @@ func (_d telemetryMiddleware) Create(ctx context.Context, space *spaces.Space) ( } // Delete implements spaces.Spaces -func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string) (err error) { +func (_d telemetryMiddleware) Delete(ctx context.Context, id string) (err error) { var att = []attribute.KeyValue{ attribute.String("service", "Spaces"), attribute.String("method", "Delete"), @@ -176,16 +176,27 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string) (err e ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Spaces.Delete") defer _span.End() - err = _d.Spaces.Delete(ctx, spaceId) + err = _d.Spaces.Delete(ctx, id) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) var spID string - spID = spaceId + params := []interface{}{ctx, id, err} + for _, p := range params { + if p == nil { + continue + } + if sg, ok := p.(spaceGetter); ok { + spID = sg.GetSpaceID() + if spID != "" { + break + } + } + } if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -194,8 +205,8 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, spaceId string) (err e if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ - "ctx": ctx, - "spaceId": spaceId}, map[string]interface{}{ + "ctx": ctx, + "id": id}, map[string]interface{}{ "err": err}) } else if err != nil { _d.requestMetrics.FailedTotal.Add(ctx, 1, attributes) @@ -240,7 +251,7 @@ func (_d telemetryMiddleware) Find(ctx context.Context, filter *spaces.Filter, f if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -267,7 +278,7 @@ func (_d telemetryMiddleware) Find(ctx context.Context, filter *spaces.Filter, f } // Get implements spaces.Spaces -func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string) (space *spaces.Space, err error) { +func (_d telemetryMiddleware) Get(ctx context.Context, id string) (space *spaces.Space, err error) { var att = []attribute.KeyValue{ attribute.String("service", "Spaces"), attribute.String("method", "Get"), @@ -278,16 +289,27 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string) (space *s ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Spaces.Get") defer _span.End() - space, err = _d.Spaces.Get(ctx, spaceId) + space, err = _d.Spaces.Get(ctx, id) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) var spID string - spID = spaceId + params := []interface{}{ctx, id, space, err} + for _, p := range params { + if p == nil { + continue + } + if sg, ok := p.(spaceGetter); ok { + spID = sg.GetSpaceID() + if spID != "" { + break + } + } + } if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -296,8 +318,8 @@ func (_d telemetryMiddleware) Get(ctx context.Context, spaceId string) (space *s if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ - "ctx": ctx, - "spaceId": spaceId}, map[string]interface{}{ + "ctx": ctx, + "id": id}, map[string]interface{}{ "space": space, "err": err}) } else if err != nil { @@ -343,7 +365,7 @@ func (_d telemetryMiddleware) List(ctx context.Context, orgId string) (spaces [] if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -399,7 +421,7 @@ func (_d telemetryMiddleware) ListTransfers(ctx context.Context, orgID string) ( if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -424,7 +446,7 @@ func (_d telemetryMiddleware) ListTransfers(ctx context.Context, orgID string) ( } // Move implements spaces.Spaces -func (_d telemetryMiddleware) Move(ctx context.Context, spaceID string, orgID string) (err error) { +func (_d telemetryMiddleware) Move(ctx context.Context, id string, orgID string) (err error) { var att = []attribute.KeyValue{ attribute.String("service", "Spaces"), attribute.String("method", "Move"), @@ -435,12 +457,12 @@ func (_d telemetryMiddleware) Move(ctx context.Context, spaceID string, orgID st ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Spaces.Move") defer _span.End() - err = _d.Spaces.Move(ctx, spaceID, orgID) + err = _d.Spaces.Move(ctx, id, orgID) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) var spID string - params := []interface{}{ctx, spaceID, orgID, err} + params := []interface{}{ctx, id, orgID, err} for _, p := range params { if p == nil { continue @@ -455,7 +477,7 @@ func (_d telemetryMiddleware) Move(ctx context.Context, spaceID string, orgID st if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -464,9 +486,9 @@ func (_d telemetryMiddleware) Move(ctx context.Context, spaceID string, orgID st if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ - "ctx": ctx, - "spaceID": spaceID, - "orgID": orgID}, map[string]interface{}{ + "ctx": ctx, + "id": id, + "orgID": orgID}, map[string]interface{}{ "err": err}) } else if err != nil { _d.requestMetrics.FailedTotal.Add(ctx, 1, attributes) @@ -480,7 +502,7 @@ func (_d telemetryMiddleware) Move(ctx context.Context, spaceID string, orgID st } // SetState implements spaces.Spaces -func (_d telemetryMiddleware) SetState(ctx context.Context, spaceID string, state *spaces.StateInfo) (err error) { +func (_d telemetryMiddleware) SetState(ctx context.Context, id string, state *spaces.StateInfo) (err error) { var att = []attribute.KeyValue{ attribute.String("service", "Spaces"), attribute.String("method", "SetState"), @@ -491,12 +513,12 @@ func (_d telemetryMiddleware) SetState(ctx context.Context, spaceID string, stat ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Spaces.SetState") defer _span.End() - err = _d.Spaces.SetState(ctx, spaceID, state) + err = _d.Spaces.SetState(ctx, id, state) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) var spID string - params := []interface{}{ctx, spaceID, state, err} + params := []interface{}{ctx, id, state, err} for _, p := range params { if p == nil { continue @@ -511,7 +533,7 @@ func (_d telemetryMiddleware) SetState(ctx context.Context, spaceID string, stat if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -520,9 +542,9 @@ func (_d telemetryMiddleware) SetState(ctx context.Context, spaceID string, stat if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ - "ctx": ctx, - "spaceID": spaceID, - "state": state}, map[string]interface{}{ + "ctx": ctx, + "id": id, + "state": state}, map[string]interface{}{ "err": err}) } else if err != nil { _d.requestMetrics.FailedTotal.Add(ctx, 1, attributes) @@ -536,7 +558,7 @@ func (_d telemetryMiddleware) SetState(ctx context.Context, spaceID string, stat } // Transfer implements spaces.Spaces -func (_d telemetryMiddleware) Transfer(ctx context.Context, spaceID string, transferToOrg string) (err error) { +func (_d telemetryMiddleware) Transfer(ctx context.Context, id string, transferToOrg string) (err error) { var att = []attribute.KeyValue{ attribute.String("service", "Spaces"), attribute.String("method", "Transfer"), @@ -547,12 +569,12 @@ func (_d telemetryMiddleware) Transfer(ctx context.Context, spaceID string, tran ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Spaces.Transfer") defer _span.End() - err = _d.Spaces.Transfer(ctx, spaceID, transferToOrg) + err = _d.Spaces.Transfer(ctx, id, transferToOrg) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) var spID string - params := []interface{}{ctx, spaceID, transferToOrg, err} + params := []interface{}{ctx, id, transferToOrg, err} for _, p := range params { if p == nil { continue @@ -567,7 +589,7 @@ func (_d telemetryMiddleware) Transfer(ctx context.Context, spaceID string, tran if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -577,7 +599,7 @@ func (_d telemetryMiddleware) Transfer(ctx context.Context, spaceID string, tran if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ "ctx": ctx, - "spaceID": spaceID, + "id": id, "transferToOrg": transferToOrg}, map[string]interface{}{ "err": err}) } else if err != nil { @@ -623,7 +645,7 @@ func (_d telemetryMiddleware) Update(ctx context.Context, space *spaces.Space) ( if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -647,7 +669,7 @@ func (_d telemetryMiddleware) Update(ctx context.Context, space *spaces.Space) ( } // UpdateConfig implements spaces.Spaces -func (_d telemetryMiddleware) UpdateConfig(ctx context.Context, spaceId string, config *spaces.Config) (err error) { +func (_d telemetryMiddleware) UpdateConfig(ctx context.Context, id string, config *spaces.Config) (err error) { var att = []attribute.KeyValue{ attribute.String("service", "Spaces"), attribute.String("method", "UpdateConfig"), @@ -658,16 +680,27 @@ func (_d telemetryMiddleware) UpdateConfig(ctx context.Context, spaceId string, ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Spaces.UpdateConfig") defer _span.End() - err = _d.Spaces.UpdateConfig(ctx, spaceId, config) + err = _d.Spaces.UpdateConfig(ctx, id, config) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) var spID string - spID = spaceId + params := []interface{}{ctx, id, config, err} + for _, p := range params { + if p == nil { + continue + } + if sg, ok := p.(spaceGetter); ok { + spID = sg.GetSpaceID() + if spID != "" { + break + } + } + } if spID != "" { att = append(att, attribute.String("spaceID", spID)) } - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -676,9 +709,9 @@ func (_d telemetryMiddleware) UpdateConfig(ctx context.Context, spaceId string, if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ - "ctx": ctx, - "spaceId": spaceId, - "config": config}, map[string]interface{}{ + "ctx": ctx, + "id": id, + "config": config}, map[string]interface{}{ "err": err}) } else if err != nil { _d.requestMetrics.FailedTotal.Add(ctx, 1, attributes) diff --git a/pkg/spaces/mocks/Middleware.go b/pkg/spaces/mocks/Middleware.go index 0979e72e453c18aafb52448768f6f78fa54495c4..d3d69efcc722a342578ac1293823ea858ac97b77 100644 --- a/pkg/spaces/mocks/Middleware.go +++ b/pkg/spaces/mocks/Middleware.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.15.0. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -16,6 +16,10 @@ type Middleware struct { func (_m *Middleware) Execute(_a0 spaces.Spaces) spaces.Spaces { ret := _m.Called(_a0) + if len(ret) == 0 { + panic("no return value specified for Execute") + } + var r0 spaces.Spaces if rf, ok := ret.Get(0).(func(spaces.Spaces) spaces.Spaces); ok { r0 = rf(_a0) @@ -28,13 +32,12 @@ func (_m *Middleware) Execute(_a0 spaces.Spaces) spaces.Spaces { return r0 } -type mockConstructorTestingTNewMiddleware interface { +// NewMiddleware creates a new instance of Middleware. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMiddleware(t interface { mock.TestingT Cleanup(func()) -} - -// NewMiddleware creates a new instance of Middleware. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewMiddleware(t mockConstructorTestingTNewMiddleware) *Middleware { +}) *Middleware { mock := &Middleware{} mock.Mock.Test(t) diff --git a/pkg/spaces/mocks/Spaces.go b/pkg/spaces/mocks/Spaces.go index 76121895f428dbcd8aa8117f4a8e376845d81e0b..85a8c35b4c6d040bd247179dc8df0b282f483474 100644 --- a/pkg/spaces/mocks/Spaces.go +++ b/pkg/spaces/mocks/Spaces.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.40.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -16,9 +16,9 @@ type Spaces struct { mock.Mock } -// AbortTransfer provides a mock function with given fields: ctx, spaceID -func (_m *Spaces) AbortTransfer(ctx context.Context, spaceID string) error { - ret := _m.Called(ctx, spaceID) +// AbortTransfer provides a mock function with given fields: ctx, id +func (_m *Spaces) AbortTransfer(ctx context.Context, id string) error { + ret := _m.Called(ctx, id) if len(ret) == 0 { panic("no return value specified for AbortTransfer") @@ -26,7 +26,7 @@ func (_m *Spaces) AbortTransfer(ctx context.Context, spaceID string) error { var r0 error if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { - r0 = rf(ctx, spaceID) + r0 = rf(ctx, id) } else { r0 = ret.Error(0) } @@ -64,9 +64,9 @@ func (_m *Spaces) Create(ctx context.Context, space *spaces.Space) (*spaces.Spac return r0, r1 } -// Delete provides a mock function with given fields: ctx, spaceId -func (_m *Spaces) Delete(ctx context.Context, spaceId string) error { - ret := _m.Called(ctx, spaceId) +// Delete provides a mock function with given fields: ctx, id +func (_m *Spaces) Delete(ctx context.Context, id string) error { + ret := _m.Called(ctx, id) if len(ret) == 0 { panic("no return value specified for Delete") @@ -74,7 +74,7 @@ func (_m *Spaces) Delete(ctx context.Context, spaceId string) error { var r0 error if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { - r0 = rf(ctx, spaceId) + r0 = rf(ctx, id) } else { r0 = ret.Error(0) } @@ -119,9 +119,9 @@ func (_m *Spaces) Find(ctx context.Context, filter *spaces.Filter, fo *options.F return r0, r1, r2 } -// Get provides a mock function with given fields: ctx, spaceId -func (_m *Spaces) Get(ctx context.Context, spaceId string) (*spaces.Space, error) { - ret := _m.Called(ctx, spaceId) +// Get provides a mock function with given fields: ctx, id +func (_m *Spaces) Get(ctx context.Context, id string) (*spaces.Space, error) { + ret := _m.Called(ctx, id) if len(ret) == 0 { panic("no return value specified for Get") @@ -130,10 +130,10 @@ func (_m *Spaces) Get(ctx context.Context, spaceId string) (*spaces.Space, error var r0 *spaces.Space var r1 error if rf, ok := ret.Get(0).(func(context.Context, string) (*spaces.Space, error)); ok { - return rf(ctx, spaceId) + return rf(ctx, id) } if rf, ok := ret.Get(0).(func(context.Context, string) *spaces.Space); ok { - r0 = rf(ctx, spaceId) + r0 = rf(ctx, id) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*spaces.Space) @@ -141,7 +141,7 @@ func (_m *Spaces) Get(ctx context.Context, spaceId string) (*spaces.Space, error } if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { - r1 = rf(ctx, spaceId) + r1 = rf(ctx, id) } else { r1 = ret.Error(1) } @@ -209,9 +209,9 @@ func (_m *Spaces) ListTransfers(ctx context.Context, orgID string) ([]*spaces.Sp return r0, r1 } -// Move provides a mock function with given fields: ctx, spaceID, orgID -func (_m *Spaces) Move(ctx context.Context, spaceID string, orgID string) error { - ret := _m.Called(ctx, spaceID, orgID) +// Move provides a mock function with given fields: ctx, id, orgID +func (_m *Spaces) Move(ctx context.Context, id string, orgID string) error { + ret := _m.Called(ctx, id, orgID) if len(ret) == 0 { panic("no return value specified for Move") @@ -219,7 +219,7 @@ func (_m *Spaces) Move(ctx context.Context, spaceID string, orgID string) error var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, string) error); ok { - r0 = rf(ctx, spaceID, orgID) + r0 = rf(ctx, id, orgID) } else { r0 = ret.Error(0) } @@ -227,9 +227,9 @@ func (_m *Spaces) Move(ctx context.Context, spaceID string, orgID string) error return r0 } -// SetState provides a mock function with given fields: ctx, spaceID, state -func (_m *Spaces) SetState(ctx context.Context, spaceID string, state *spaces.StateInfo) error { - ret := _m.Called(ctx, spaceID, state) +// SetState provides a mock function with given fields: ctx, id, state +func (_m *Spaces) SetState(ctx context.Context, id string, state *spaces.StateInfo) error { + ret := _m.Called(ctx, id, state) if len(ret) == 0 { panic("no return value specified for SetState") @@ -237,7 +237,7 @@ func (_m *Spaces) SetState(ctx context.Context, spaceID string, state *spaces.St var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, *spaces.StateInfo) error); ok { - r0 = rf(ctx, spaceID, state) + r0 = rf(ctx, id, state) } else { r0 = ret.Error(0) } @@ -245,9 +245,9 @@ func (_m *Spaces) SetState(ctx context.Context, spaceID string, state *spaces.St return r0 } -// Transfer provides a mock function with given fields: ctx, spaceID, transferToOrg -func (_m *Spaces) Transfer(ctx context.Context, spaceID string, transferToOrg string) error { - ret := _m.Called(ctx, spaceID, transferToOrg) +// Transfer provides a mock function with given fields: ctx, id, transferToOrg +func (_m *Spaces) Transfer(ctx context.Context, id string, transferToOrg string) error { + ret := _m.Called(ctx, id, transferToOrg) if len(ret) == 0 { panic("no return value specified for Transfer") @@ -255,7 +255,7 @@ func (_m *Spaces) Transfer(ctx context.Context, spaceID string, transferToOrg st var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, string) error); ok { - r0 = rf(ctx, spaceID, transferToOrg) + r0 = rf(ctx, id, transferToOrg) } else { r0 = ret.Error(0) } @@ -281,9 +281,9 @@ func (_m *Spaces) Update(ctx context.Context, space *spaces.Space) error { return r0 } -// UpdateConfig provides a mock function with given fields: ctx, spaceId, config -func (_m *Spaces) UpdateConfig(ctx context.Context, spaceId string, config *spaces.Config) error { - ret := _m.Called(ctx, spaceId, config) +// UpdateConfig provides a mock function with given fields: ctx, id, config +func (_m *Spaces) UpdateConfig(ctx context.Context, id string, config *spaces.Config) error { + ret := _m.Called(ctx, id, config) if len(ret) == 0 { panic("no return value specified for UpdateConfig") @@ -291,7 +291,7 @@ func (_m *Spaces) UpdateConfig(ctx context.Context, spaceId string, config *spac var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, *spaces.Config) error); ok { - r0 = rf(ctx, spaceId, config) + r0 = rf(ctx, id, config) } else { r0 = ret.Error(0) } diff --git a/pkg/spaces/mocks/Storage.go b/pkg/spaces/mocks/Storage.go index 078993cebec0cb2a5748c0d5bf1c50fb68d4def0..8435ef984e9bf8bcdd24174298a8f9f87c68a50c 100644 --- a/pkg/spaces/mocks/Storage.go +++ b/pkg/spaces/mocks/Storage.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.40.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks diff --git a/pkg/spaces/mocks/spaceGetter.go b/pkg/spaces/mocks/spaceGetter.go new file mode 100644 index 0000000000000000000000000000000000000000..0dfa462e8b1af6c8feeee2bed7cd7e4c1317d0b1 --- /dev/null +++ b/pkg/spaces/mocks/spaceGetter.go @@ -0,0 +1,42 @@ +// Code generated by mockery v2.46.3. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// spaceGetter is an autogenerated mock type for the spaceGetter type +type spaceGetter struct { + mock.Mock +} + +// GetSpaceID provides a mock function with given fields: +func (_m *spaceGetter) GetSpaceID() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetSpaceID") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// newSpaceGetter creates a new instance of spaceGetter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newSpaceGetter(t interface { + mock.TestingT + Cleanup(func()) +}) *spaceGetter { + mock := &spaceGetter{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/spaces/service.go b/pkg/spaces/service.go index 249221692684110e96c62fce37d70fc650d06945..833d7142ea0c091de2412f6702a342b7ab61233e 100644 --- a/pkg/spaces/service.go +++ b/pkg/spaces/service.go @@ -26,26 +26,26 @@ type Spaces interface { // ErrUnavailable Create(ctx context.Context, space *Space) (created *Space, err error) - Get(ctx context.Context, spaceId string) (space *Space, err error) + Get(ctx context.Context, id string) (space *Space, err error) List(ctx context.Context, orgId string) (spaces []*Space, err error) Find(ctx context.Context, filter *Filter, fo *options.FindOptions) (spaces []*Space, total int, err error) Update(ctx context.Context, space *Space) (err error) - UpdateConfig(ctx context.Context, spaceId string, config *Config) (err error) + UpdateConfig(ctx context.Context, id string, config *Config) (err error) // @microgen - - SetState(ctx context.Context, spaceID string, state *StateInfo) (err error) - Delete(ctx context.Context, spaceId string) (err error) + SetState(ctx context.Context, id string, state *StateInfo) (err error) + Delete(ctx context.Context, id string) (err error) // Transfer уÑтанавливает Ð´Ð»Ñ Ð¿Ñ€Ð¾ÑтранÑтва значение Ð¿Ð¾Ð»Ñ RequestedMoveTo. ПоÑле Ñтого проÑтранÑтво // будет отображатьÑÑ Ð² ÑпиÑке входÑщих запроÑов на перемещение в организации `orgID` (Ð·Ð°Ð¿Ñ€Ð¾Ñ ListIncoming) // С проÑтранÑтвом можно продолжать работу в текущей организации, пока Ð·Ð°Ð¿Ñ€Ð¾Ñ Ð½Ð° перемещение не будет // принÑÑ‚ в целевой организации // ÐŸÐµÑ€ÐµÐ½Ð¾Ñ Ð¼Ð¾Ð¶ÐµÑ‚ быть инициирован только владельцем организации, которой принадлежит проÑтранÑтво - Transfer(ctx context.Context, spaceID, transferToOrg string) (err error) + Transfer(ctx context.Context, id, transferToOrg string) (err error) // AbortTransfer - отменить перемещение проÑтранÑтва в другую организацию. Может быть вызван как // владельцем проÑтранÑтва-инициатора, там и владельцем принимающего проÑтранÑтва - AbortTransfer(ctx context.Context, spaceID string) (err error) + AbortTransfer(ctx context.Context, id string) (err error) // ListTransfers возвращает ÑпиÑок проÑтранÑтв, перемещение которых было запрошено в текущую организацию ListTransfers(ctx context.Context, orgID string) (spaces []*Space, err error) @@ -55,7 +55,7 @@ type Spaces interface { // иÑходной организации. // Ð’ Ñлучае, еÑли Ð·Ð°Ð¿Ñ€Ð¾Ñ Ð¾ÑущеÑтвлÑетÑÑ Ñ ÑиÑтемным уровнем доÑтупа и передан параметр `orgID`, то Ð¿ÐµÑ€ÐµÐ½Ð¾Ñ Ð±ÑƒÐ´ÐµÑ‚ // оÑущеÑтвлен вне завиÑимоÑти от того, был он инициирован через метод `Transfer` или нет - Move(ctx context.Context, spaceID, orgID string) (err error) + Move(ctx context.Context, id, orgID string) (err error) } const ( diff --git a/pkg/users/middleware/access_logging_middleware.go b/pkg/users/middleware/access_logging_middleware.go index dd8d4a14c73915d553381b239770fcf05c02aca5..fa83027280cfc95fb86f0bbe6051f5d3844310ff 100644 --- a/pkg/users/middleware/access_logging_middleware.go +++ b/pkg/users/middleware/access_logging_middleware.go @@ -32,34 +32,34 @@ func AccessLoggingMiddleware(logger *zap.Logger) Middleware { } } -func (m *accessLoggingMiddleware) Create(ctx context.Context, create *users.User) (user *users.User, err error) { +func (m *accessLoggingMiddleware) Create(ctx context.Context, user *users.User) (created *users.User, err error) { begin := time.Now() m.logger.Debug("Create.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), - zap.Reflect("create", create), + zap.Reflect("user", user), ) - user, err = m.next.Create(ctx, create) + created, err = m.next.Create(ctx, user) m.logger.Debug("Create.Response", zap.Duration("time", time.Since(begin)), - zap.Reflect("user", user), + zap.Reflect("created", created), zap.Error(err), ) - return user, err + return created, err } -func (m *accessLoggingMiddleware) Delete(ctx context.Context, userId string) (err error) { +func (m *accessLoggingMiddleware) Delete(ctx context.Context, id string) (err error) { begin := time.Now() m.logger.Debug("Delete.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), - zap.Reflect("userId", userId), + zap.Reflect("id", id), ) - err = m.next.Delete(ctx, userId) + err = m.next.Delete(ctx, id) m.logger.Debug("Delete.Response", zap.Duration("time", time.Since(begin)), @@ -90,15 +90,15 @@ func (m *accessLoggingMiddleware) Find(ctx context.Context, filter *users.Filter return users, total, err } -func (m *accessLoggingMiddleware) Get(ctx context.Context, userId string) (user *users.User, err error) { +func (m *accessLoggingMiddleware) Get(ctx context.Context, id string) (user *users.User, err error) { begin := time.Now() m.logger.Debug("Get.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), - zap.Reflect("userId", userId), + zap.Reflect("id", id), ) - user, err = m.next.Get(ctx, userId) + user, err = m.next.Get(ctx, id) m.logger.Debug("Get.Response", zap.Duration("time", time.Since(begin)), @@ -128,15 +128,15 @@ func (m *accessLoggingMiddleware) GetByIdentity(ctx context.Context, identity st return user, err } -func (m *accessLoggingMiddleware) Update(ctx context.Context, update *users.User) (err error) { +func (m *accessLoggingMiddleware) Update(ctx context.Context, user *users.User) (err error) { begin := time.Now() m.logger.Debug("Update.Request", zap.Reflect("principal", auth.GetPrincipal(ctx)), - zap.Reflect("update", update), + zap.Reflect("user", user), ) - err = m.next.Update(ctx, update) + err = m.next.Update(ctx, user) m.logger.Debug("Update.Response", zap.Duration("time", time.Since(begin)), diff --git a/pkg/users/middleware/caching_middleware.go b/pkg/users/middleware/caching_middleware.go index 825da6a28caabeee0f71d9030b60c8152e884570..966da731feef900ac7ad0a852c108fbc536af5d7 100644 --- a/pkg/users/middleware/caching_middleware.go +++ b/pkg/users/middleware/caching_middleware.go @@ -26,13 +26,13 @@ func (m cachingMiddleware) Create(ctx context.Context, create *service.User) (us return m.next.Create(ctx, create) } -func (m cachingMiddleware) Get(ctx context.Context, userId string) (user *service.User, err error) { +func (m cachingMiddleware) Get(ctx context.Context, id string) (user *service.User, err error) { - value, e := m.cache.Get(userId) + value, e := m.cache.Get(id) if e == nil { return value.(*service.User).Clone(), nil } - user, err = m.next.Get(ctx, userId) + user, err = m.next.Get(ctx, id) if err == nil { _ = m.cache.Set(user.ID, user) for _, i := range user.Identities { @@ -61,10 +61,10 @@ func (m cachingMiddleware) Update(ctx context.Context, update *service.User) (er return err } -func (m cachingMiddleware) Delete(ctx context.Context, userId string) (err error) { +func (m cachingMiddleware) Delete(ctx context.Context, id string) (err error) { - err = m.next.Delete(ctx, userId) - value, e := m.cache.Get(userId) + err = m.next.Delete(ctx, id) + value, e := m.cache.Get(id) if err == nil && e == nil { usr := value.(*service.User) _ = m.cache.Remove(usr.ID) diff --git a/pkg/users/middleware/error_logging_middleware.go b/pkg/users/middleware/error_logging_middleware.go index c499b9f3bf60726a10d30ced82e24bced6702236..b8abb51a5aa7684f68f1d97fc0cdf9077a0d6087 100644 --- a/pkg/users/middleware/error_logging_middleware.go +++ b/pkg/users/middleware/error_logging_middleware.go @@ -30,24 +30,24 @@ func ErrorLoggingMiddleware(logger *zap.Logger) Middleware { } } -func (m *errorLoggingMiddleware) Create(ctx context.Context, create *users.User) (user *users.User, err error) { +func (m *errorLoggingMiddleware) Create(ctx context.Context, user *users.User) (created *users.User, err error) { logger := m.logger defer func() { if err != nil { logger.Warn("response error", zap.Error(err)) } }() - return m.next.Create(ctx, create) + return m.next.Create(ctx, user) } -func (m *errorLoggingMiddleware) Delete(ctx context.Context, userId string) (err error) { +func (m *errorLoggingMiddleware) Delete(ctx context.Context, id string) (err error) { logger := m.logger defer func() { if err != nil { logger.Warn("response error", zap.Error(err)) } }() - return m.next.Delete(ctx, userId) + return m.next.Delete(ctx, id) } func (m *errorLoggingMiddleware) Find(ctx context.Context, filter *users.Filter, options *options.FindOptions) (users []*users.User, total int, err error) { @@ -60,14 +60,14 @@ func (m *errorLoggingMiddleware) Find(ctx context.Context, filter *users.Filter, return m.next.Find(ctx, filter, options) } -func (m *errorLoggingMiddleware) Get(ctx context.Context, userId string) (user *users.User, err error) { +func (m *errorLoggingMiddleware) Get(ctx context.Context, id string) (user *users.User, err error) { logger := m.logger defer func() { if err != nil { logger.Warn("response error", zap.Error(err)) } }() - return m.next.Get(ctx, userId) + return m.next.Get(ctx, id) } func (m *errorLoggingMiddleware) GetByIdentity(ctx context.Context, identity string) (user *users.User, err error) { @@ -80,12 +80,12 @@ func (m *errorLoggingMiddleware) GetByIdentity(ctx context.Context, identity str return m.next.GetByIdentity(ctx, identity) } -func (m *errorLoggingMiddleware) Update(ctx context.Context, update *users.User) (err error) { +func (m *errorLoggingMiddleware) Update(ctx context.Context, user *users.User) (err error) { logger := m.logger defer func() { if err != nil { logger.Warn("response error", zap.Error(err)) } }() - return m.next.Update(ctx, update) + return m.next.Update(ctx, user) } diff --git a/pkg/users/middleware/logging_middleware.go b/pkg/users/middleware/logging_middleware.go index 3350d36d87b5715c043455428cc6e4aa0c0f981d..f6a0b9b697e6832ea8fb6eaaa97c882ec43bdc78 100644 --- a/pkg/users/middleware/logging_middleware.go +++ b/pkg/users/middleware/logging_middleware.go @@ -3,7 +3,7 @@ package middleware import ( "context" - "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/options" "git.perx.ru/perxis/perxis-go/pkg/users" logzap "git.perx.ru/perxis/perxis-go/zap" @@ -41,13 +41,13 @@ func (m *loggingMiddleware) Create(ctx context.Context, create *users.User) (use return user, err } -func (m *loggingMiddleware) Get(ctx context.Context, userId string) (user *users.User, err error) { +func (m *loggingMiddleware) Get(ctx context.Context, id string) (user *users.User, err error) { logger := m.logger.With( logzap.Caller(ctx), - logzap.Object(id.NewUserId(userId)), + logzap.Object(pkgId.NewUserId(id)), ) - user, err = m.next.Get(ctx, userId) + user, err = m.next.Get(ctx, id) if err != nil { logger.Error("Failed to get", zap.Error(err)) return @@ -88,14 +88,14 @@ func (m *loggingMiddleware) Update(ctx context.Context, update *users.User) (err return err } -func (m *loggingMiddleware) Delete(ctx context.Context, userId string) (err error) { +func (m *loggingMiddleware) Delete(ctx context.Context, id string) (err error) { logger := m.logger.With( logzap.Caller(ctx), logzap.Event(users.EventDelete), - logzap.Object(id.NewUserId(userId)), + logzap.Object(pkgId.NewUserId(id)), ) - err = m.next.Delete(ctx, userId) + err = m.next.Delete(ctx, id) if err != nil { logger.Error("Failed to delete", zap.Error(err), logzap.Channels(logzap.Userlog, logzap.Syslog)) return @@ -109,7 +109,7 @@ func (m *loggingMiddleware) Delete(ctx context.Context, userId string) (err erro func (m *loggingMiddleware) GetByIdentity(ctx context.Context, identity string) (user *users.User, err error) { logger := m.logger.With( logzap.Caller(ctx), - logzap.Object(id.NewUserId(identity)), + logzap.Object(pkgId.NewUserId(identity)), ) user, err = m.next.GetByIdentity(ctx, identity) diff --git a/pkg/users/middleware/recovering_middleware.go b/pkg/users/middleware/recovering_middleware.go index 7dac51f0c84fca93e796fc79fe7facb6872d0df1..e58c5b911f4106268f81136545677df1666e9bd0 100644 --- a/pkg/users/middleware/recovering_middleware.go +++ b/pkg/users/middleware/recovering_middleware.go @@ -31,7 +31,7 @@ func RecoveringMiddleware(logger *zap.Logger) Middleware { } } -func (m *recoveringMiddleware) Create(ctx context.Context, create *users.User) (user *users.User, err error) { +func (m *recoveringMiddleware) Create(ctx context.Context, user *users.User) (created *users.User, err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -40,10 +40,10 @@ func (m *recoveringMiddleware) Create(ctx context.Context, create *users.User) ( } }() - return m.next.Create(ctx, create) + return m.next.Create(ctx, user) } -func (m *recoveringMiddleware) Delete(ctx context.Context, userId string) (err error) { +func (m *recoveringMiddleware) Delete(ctx context.Context, id string) (err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -52,7 +52,7 @@ func (m *recoveringMiddleware) Delete(ctx context.Context, userId string) (err e } }() - return m.next.Delete(ctx, userId) + return m.next.Delete(ctx, id) } func (m *recoveringMiddleware) Find(ctx context.Context, filter *users.Filter, options *options.FindOptions) (users []*users.User, total int, err error) { @@ -67,7 +67,7 @@ func (m *recoveringMiddleware) Find(ctx context.Context, filter *users.Filter, o return m.next.Find(ctx, filter, options) } -func (m *recoveringMiddleware) Get(ctx context.Context, userId string) (user *users.User, err error) { +func (m *recoveringMiddleware) Get(ctx context.Context, id string) (user *users.User, err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -76,7 +76,7 @@ func (m *recoveringMiddleware) Get(ctx context.Context, userId string) (user *us } }() - return m.next.Get(ctx, userId) + return m.next.Get(ctx, id) } func (m *recoveringMiddleware) GetByIdentity(ctx context.Context, identity string) (user *users.User, err error) { @@ -91,7 +91,7 @@ func (m *recoveringMiddleware) GetByIdentity(ctx context.Context, identity strin return m.next.GetByIdentity(ctx, identity) } -func (m *recoveringMiddleware) Update(ctx context.Context, update *users.User) (err error) { +func (m *recoveringMiddleware) Update(ctx context.Context, user *users.User) (err error) { logger := m.logger defer func() { if r := recover(); r != nil { @@ -100,5 +100,5 @@ func (m *recoveringMiddleware) Update(ctx context.Context, update *users.User) ( } }() - return m.next.Update(ctx, update) + return m.next.Update(ctx, user) } diff --git a/pkg/users/middleware/telemetry_middleware.go b/pkg/users/middleware/telemetry_middleware.go index 8ad677e704656503e246943bf12d30e133d4c11f..25088bfd631d5b2dd23c58d861c6051098d01907 100644 --- a/pkg/users/middleware/telemetry_middleware.go +++ b/pkg/users/middleware/telemetry_middleware.go @@ -10,7 +10,7 @@ import ( "context" "time" - oid "git.perx.ru/perxis/perxis-go/id" + pkgId "git.perx.ru/perxis/perxis-go/id" "git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/options" "git.perx.ru/perxis/perxis-go/pkg/telemetry/metrics" @@ -54,7 +54,7 @@ func TelemetryMiddleware(base users.Users, instance string, spanDecorator ...fun } // Create implements users.Users -func (_d telemetryMiddleware) Create(ctx context.Context, create *users.User) (user *users.User, err error) { +func (_d telemetryMiddleware) Create(ctx context.Context, user *users.User) (created *users.User, err error) { var att = []attribute.KeyValue{ attribute.String("service", "Users"), attribute.String("method", "Create"), @@ -65,11 +65,11 @@ func (_d telemetryMiddleware) Create(ctx context.Context, create *users.User) (u ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Users.Create") defer _span.End() - user, err = _d.Users.Create(ctx, create) + created, err = _d.Users.Create(ctx, user) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -78,10 +78,10 @@ func (_d telemetryMiddleware) Create(ctx context.Context, create *users.User) (u if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ - "ctx": ctx, - "create": create}, map[string]interface{}{ - "user": user, - "err": err}) + "ctx": ctx, + "user": user}, map[string]interface{}{ + "created": created, + "err": err}) } else if err != nil { _d.requestMetrics.FailedTotal.Add(ctx, 1, attributes) @@ -90,11 +90,11 @@ func (_d telemetryMiddleware) Create(ctx context.Context, create *users.User) (u _span.SetAttributes(attribute.String("message", err.Error())) } - return user, err + return created, err } // Delete implements users.Users -func (_d telemetryMiddleware) Delete(ctx context.Context, userId string) (err error) { +func (_d telemetryMiddleware) Delete(ctx context.Context, id string) (err error) { var att = []attribute.KeyValue{ attribute.String("service", "Users"), attribute.String("method", "Delete"), @@ -105,11 +105,11 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, userId string) (err er ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Users.Delete") defer _span.End() - err = _d.Users.Delete(ctx, userId) + err = _d.Users.Delete(ctx, id) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -118,8 +118,8 @@ func (_d telemetryMiddleware) Delete(ctx context.Context, userId string) (err er if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ - "ctx": ctx, - "userId": userId}, map[string]interface{}{ + "ctx": ctx, + "id": id}, map[string]interface{}{ "err": err}) } else if err != nil { _d.requestMetrics.FailedTotal.Add(ctx, 1, attributes) @@ -148,7 +148,7 @@ func (_d telemetryMiddleware) Find(ctx context.Context, filter *users.Filter, op _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -175,7 +175,7 @@ func (_d telemetryMiddleware) Find(ctx context.Context, filter *users.Filter, op } // Get implements users.Users -func (_d telemetryMiddleware) Get(ctx context.Context, userId string) (user *users.User, err error) { +func (_d telemetryMiddleware) Get(ctx context.Context, id string) (user *users.User, err error) { var att = []attribute.KeyValue{ attribute.String("service", "Users"), attribute.String("method", "Get"), @@ -186,11 +186,11 @@ func (_d telemetryMiddleware) Get(ctx context.Context, userId string) (user *use ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Users.Get") defer _span.End() - user, err = _d.Users.Get(ctx, userId) + user, err = _d.Users.Get(ctx, id) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -199,8 +199,8 @@ func (_d telemetryMiddleware) Get(ctx context.Context, userId string) (user *use if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ - "ctx": ctx, - "userId": userId}, map[string]interface{}{ + "ctx": ctx, + "id": id}, map[string]interface{}{ "user": user, "err": err}) } else if err != nil { @@ -230,7 +230,7 @@ func (_d telemetryMiddleware) GetByIdentity(ctx context.Context, identity string _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -255,7 +255,7 @@ func (_d telemetryMiddleware) GetByIdentity(ctx context.Context, identity string } // Update implements users.Users -func (_d telemetryMiddleware) Update(ctx context.Context, update *users.User) (err error) { +func (_d telemetryMiddleware) Update(ctx context.Context, user *users.User) (err error) { var att = []attribute.KeyValue{ attribute.String("service", "Users"), attribute.String("method", "Update"), @@ -266,11 +266,11 @@ func (_d telemetryMiddleware) Update(ctx context.Context, update *users.User) (e ctx, _span := otel.Tracer(_d._instance).Start(ctx, "Users.Update") defer _span.End() - err = _d.Users.Update(ctx, update) + err = _d.Users.Update(ctx, user) _d.requestMetrics.DurationMilliseconds.Record(ctx, time.Since(start).Milliseconds(), attributes) - caller, _ := oid.NewObjectId(auth.GetPrincipal(ctx)) + caller, _ := pkgId.NewObjectId(auth.GetPrincipal(ctx)) if caller != nil { att = append(att, attribute.String("caller", caller.String())) } @@ -279,8 +279,8 @@ func (_d telemetryMiddleware) Update(ctx context.Context, update *users.User) (e if _d._spanDecorator != nil { _d._spanDecorator(_span, map[string]interface{}{ - "ctx": ctx, - "update": update}, map[string]interface{}{ + "ctx": ctx, + "user": user}, map[string]interface{}{ "err": err}) } else if err != nil { _d.requestMetrics.FailedTotal.Add(ctx, 1, attributes) diff --git a/pkg/users/mocks/Middleware.go b/pkg/users/mocks/Middleware.go index 63d457eb9c26bfa2b297a44ba994cc2be35e2055..4e544b865a8020a346be82a4bcb2c212aa21104d 100644 --- a/pkg/users/mocks/Middleware.go +++ b/pkg/users/mocks/Middleware.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -16,6 +16,10 @@ type Middleware struct { func (_m *Middleware) Execute(_a0 users.Users) users.Users { ret := _m.Called(_a0) + if len(ret) == 0 { + panic("no return value specified for Execute") + } + var r0 users.Users if rf, ok := ret.Get(0).(func(users.Users) users.Users); ok { r0 = rf(_a0) diff --git a/pkg/users/mocks/Storage.go b/pkg/users/mocks/Storage.go index a1001d78cacac9825e7a5cfdfc7f0a712a661d8a..2f21f0861c363e75e2cbc1823e29b4a3a7220822 100644 --- a/pkg/users/mocks/Storage.go +++ b/pkg/users/mocks/Storage.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -20,6 +20,10 @@ type Storage struct { func (_m *Storage) Create(ctx context.Context, create *users.User) (*users.User, error) { ret := _m.Called(ctx, create) + if len(ret) == 0 { + panic("no return value specified for Create") + } + var r0 *users.User var r1 error if rf, ok := ret.Get(0).(func(context.Context, *users.User) (*users.User, error)); ok { @@ -46,6 +50,10 @@ func (_m *Storage) Create(ctx context.Context, create *users.User) (*users.User, func (_m *Storage) Delete(ctx context.Context, filter *users.Filter) (int, error) { ret := _m.Called(ctx, filter) + if len(ret) == 0 { + panic("no return value specified for Delete") + } + var r0 int var r1 error if rf, ok := ret.Get(0).(func(context.Context, *users.Filter) (int, error)); ok { @@ -70,6 +78,10 @@ func (_m *Storage) Delete(ctx context.Context, filter *users.Filter) (int, error func (_m *Storage) Find(ctx context.Context, filter *users.Filter, opts *options.FindOptions) ([]*users.User, int, error) { ret := _m.Called(ctx, filter, opts) + if len(ret) == 0 { + panic("no return value specified for Find") + } + var r0 []*users.User var r1 int var r2 error @@ -103,6 +115,10 @@ func (_m *Storage) Find(ctx context.Context, filter *users.Filter, opts *options func (_m *Storage) Init(ctx context.Context) error { ret := _m.Called(ctx) + if len(ret) == 0 { + panic("no return value specified for Init") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context) error); ok { r0 = rf(ctx) @@ -117,6 +133,10 @@ func (_m *Storage) Init(ctx context.Context) error { func (_m *Storage) Reset(ctx context.Context) error { ret := _m.Called(ctx) + if len(ret) == 0 { + panic("no return value specified for Reset") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context) error); ok { r0 = rf(ctx) @@ -131,6 +151,10 @@ func (_m *Storage) Reset(ctx context.Context) error { func (_m *Storage) Update(ctx context.Context, update *users.User, filter *users.Filter) (int, int, error) { ret := _m.Called(ctx, update, filter) + if len(ret) == 0 { + panic("no return value specified for Update") + } + var r0 int var r1 int var r2 error diff --git a/pkg/users/mocks/Users.go b/pkg/users/mocks/Users.go index 4db80b6d31f883092ab690f2d4ffe1616a339d35..989c6e68158ef3b397d345fbe08b55012eec60a8 100644 --- a/pkg/users/mocks/Users.go +++ b/pkg/users/mocks/Users.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.33.3. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package mocks @@ -16,17 +16,21 @@ type Users struct { mock.Mock } -// Create provides a mock function with given fields: ctx, create -func (_m *Users) Create(ctx context.Context, create *users.User) (*users.User, error) { - ret := _m.Called(ctx, create) +// Create provides a mock function with given fields: ctx, user +func (_m *Users) Create(ctx context.Context, user *users.User) (*users.User, error) { + ret := _m.Called(ctx, user) + + if len(ret) == 0 { + panic("no return value specified for Create") + } var r0 *users.User var r1 error if rf, ok := ret.Get(0).(func(context.Context, *users.User) (*users.User, error)); ok { - return rf(ctx, create) + return rf(ctx, user) } if rf, ok := ret.Get(0).(func(context.Context, *users.User) *users.User); ok { - r0 = rf(ctx, create) + r0 = rf(ctx, user) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*users.User) @@ -34,7 +38,7 @@ func (_m *Users) Create(ctx context.Context, create *users.User) (*users.User, e } if rf, ok := ret.Get(1).(func(context.Context, *users.User) error); ok { - r1 = rf(ctx, create) + r1 = rf(ctx, user) } else { r1 = ret.Error(1) } @@ -42,13 +46,17 @@ func (_m *Users) Create(ctx context.Context, create *users.User) (*users.User, e return r0, r1 } -// Delete provides a mock function with given fields: ctx, userId -func (_m *Users) Delete(ctx context.Context, userId string) error { - ret := _m.Called(ctx, userId) +// Delete provides a mock function with given fields: ctx, id +func (_m *Users) Delete(ctx context.Context, id string) error { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } var r0 error if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { - r0 = rf(ctx, userId) + r0 = rf(ctx, id) } else { r0 = ret.Error(0) } @@ -60,6 +68,10 @@ func (_m *Users) Delete(ctx context.Context, userId string) error { func (_m *Users) Find(ctx context.Context, filter *users.Filter, _a2 *options.FindOptions) ([]*users.User, int, error) { ret := _m.Called(ctx, filter, _a2) + if len(ret) == 0 { + panic("no return value specified for Find") + } + var r0 []*users.User var r1 int var r2 error @@ -89,17 +101,21 @@ func (_m *Users) Find(ctx context.Context, filter *users.Filter, _a2 *options.Fi return r0, r1, r2 } -// Get provides a mock function with given fields: ctx, userId -func (_m *Users) Get(ctx context.Context, userId string) (*users.User, error) { - ret := _m.Called(ctx, userId) +// Get provides a mock function with given fields: ctx, id +func (_m *Users) Get(ctx context.Context, id string) (*users.User, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for Get") + } var r0 *users.User var r1 error if rf, ok := ret.Get(0).(func(context.Context, string) (*users.User, error)); ok { - return rf(ctx, userId) + return rf(ctx, id) } if rf, ok := ret.Get(0).(func(context.Context, string) *users.User); ok { - r0 = rf(ctx, userId) + r0 = rf(ctx, id) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*users.User) @@ -107,7 +123,7 @@ func (_m *Users) Get(ctx context.Context, userId string) (*users.User, error) { } if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { - r1 = rf(ctx, userId) + r1 = rf(ctx, id) } else { r1 = ret.Error(1) } @@ -119,6 +135,10 @@ func (_m *Users) Get(ctx context.Context, userId string) (*users.User, error) { func (_m *Users) GetByIdentity(ctx context.Context, identity string) (*users.User, error) { ret := _m.Called(ctx, identity) + if len(ret) == 0 { + panic("no return value specified for GetByIdentity") + } + var r0 *users.User var r1 error if rf, ok := ret.Get(0).(func(context.Context, string) (*users.User, error)); ok { @@ -141,13 +161,17 @@ func (_m *Users) GetByIdentity(ctx context.Context, identity string) (*users.Use return r0, r1 } -// Update provides a mock function with given fields: ctx, update -func (_m *Users) Update(ctx context.Context, update *users.User) error { - ret := _m.Called(ctx, update) +// Update provides a mock function with given fields: ctx, user +func (_m *Users) Update(ctx context.Context, user *users.User) error { + ret := _m.Called(ctx, user) + + if len(ret) == 0 { + panic("no return value specified for Update") + } var r0 error if rf, ok := ret.Get(0).(func(context.Context, *users.User) error); ok { - r0 = rf(ctx, update) + r0 = rf(ctx, user) } else { r0 = ret.Error(0) } diff --git a/pkg/users/mocks/spaceGetter.go b/pkg/users/mocks/spaceGetter.go new file mode 100644 index 0000000000000000000000000000000000000000..0dfa462e8b1af6c8feeee2bed7cd7e4c1317d0b1 --- /dev/null +++ b/pkg/users/mocks/spaceGetter.go @@ -0,0 +1,42 @@ +// Code generated by mockery v2.46.3. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// spaceGetter is an autogenerated mock type for the spaceGetter type +type spaceGetter struct { + mock.Mock +} + +// GetSpaceID provides a mock function with given fields: +func (_m *spaceGetter) GetSpaceID() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetSpaceID") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// newSpaceGetter creates a new instance of spaceGetter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newSpaceGetter(t interface { + mock.TestingT + Cleanup(func()) +}) *spaceGetter { + mock := &spaceGetter{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/users/service.go b/pkg/users/service.go index d64a5ceceed51d3731eaa6641baf64409cc7389d..a244c5171f61263293094b40344537a3fc3117fe 100644 --- a/pkg/users/service.go +++ b/pkg/users/service.go @@ -10,11 +10,11 @@ import ( // @protobuf git.perx.ru/perxis/perxis-go/proto/users // @grpc-addr account.users.Users type Users interface { - Create(ctx context.Context, create *User) (user *User, err error) - Get(ctx context.Context, userId string) (user *User, err error) + Create(ctx context.Context, user *User) (created *User, err error) + Get(ctx context.Context, id string) (user *User, err error) Find(ctx context.Context, filter *Filter, options *options.FindOptions) (users []*User, total int, err error) - Update(ctx context.Context, update *User) (err error) - Delete(ctx context.Context, userId string) (err error) + Update(ctx context.Context, user *User) (err error) + Delete(ctx context.Context, id string) (err error) GetByIdentity(ctx context.Context, identity string) (user *User, err error) }