From a46f10308ab99e9d408fcfbde8b55cb28d02b80a Mon Sep 17 00:00:00 2001 From: Adam O'Brien Date: Fri, 29 Nov 2024 13:02:06 +0000 Subject: [PATCH] Revert "Move eventing code" --- Dockerfile | 1 - cmd/serve/serve.go | 4 ++-- internal/biz/common.go | 10 +++++----- internal/biz/relationships/relationships.go | 12 ++++++------ internal/biz/resources/resources.go | 12 ++++++------ internal/config/config.go | 2 +- internal/data/relationships/relationships.go | 2 +- {eventing => internal/eventing}/README.md | 0 {eventing => internal/eventing}/api/event.go | 0 {eventing => internal/eventing}/api/manager.go | 0 {eventing => internal/eventing}/api/producer.go | 0 {eventing => internal/eventing}/config.go | 2 +- {eventing => internal/eventing}/factory.go | 7 ++++--- {eventing => internal/eventing}/kafka/config.go | 0 {eventing => internal/eventing}/kafka/manager.go | 2 +- {eventing => internal/eventing}/kafka/options.go | 0 {eventing => internal/eventing}/options.go | 2 +- {eventing => internal/eventing}/stdout/manager.go | 2 +- 18 files changed, 29 insertions(+), 29 deletions(-) rename {eventing => internal/eventing}/README.md (100%) rename {eventing => internal/eventing}/api/event.go (100%) rename {eventing => internal/eventing}/api/manager.go (100%) rename {eventing => internal/eventing}/api/producer.go (100%) rename {eventing => internal/eventing}/config.go (91%) rename {eventing => internal/eventing}/factory.go (70%) rename {eventing => internal/eventing}/kafka/config.go (100%) rename {eventing => internal/eventing}/kafka/manager.go (98%) rename {eventing => internal/eventing}/kafka/options.go (100%) rename {eventing => internal/eventing}/options.go (93%) rename {eventing => internal/eventing}/stdout/manager.go (93%) diff --git a/Dockerfile b/Dockerfile index 4216d676..a8141f08 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,7 +19,6 @@ RUN go mod download COPY api ./api COPY cmd ./cmd COPY internal ./internal -COPY eventing ./eventing COPY main.go Makefile ./ ARG VERSION diff --git a/cmd/serve/serve.go b/cmd/serve/serve.go index 0be885fe..b0c40185 100644 --- a/cmd/serve/serve.go +++ b/cmd/serve/serve.go @@ -23,11 +23,11 @@ import ( "github.com/go-kratos/kratos/v2/log" - eventing "github.com/project-kessel/inventory-api/eventing" - eventingapi "github.com/project-kessel/inventory-api/eventing/api" "github.com/project-kessel/inventory-api/internal/authn" "github.com/project-kessel/inventory-api/internal/authz" "github.com/project-kessel/inventory-api/internal/errors" + "github.com/project-kessel/inventory-api/internal/eventing" + eventingapi "github.com/project-kessel/inventory-api/internal/eventing/api" "github.com/project-kessel/inventory-api/internal/middleware" "github.com/project-kessel/inventory-api/internal/server" "github.com/project-kessel/inventory-api/internal/storage" diff --git a/internal/biz/common.go b/internal/biz/common.go index 9b070eb0..11513b06 100644 --- a/internal/biz/common.go +++ b/internal/biz/common.go @@ -2,21 +2,21 @@ package biz import ( "context" - "github.com/project-kessel/inventory-api/eventing/api" authzapi "github.com/project-kessel/inventory-api/internal/authz/api" "github.com/project-kessel/inventory-api/internal/biz/model" + eventingapi "github.com/project-kessel/inventory-api/internal/eventing/api" "github.com/project-kessel/inventory-api/internal/middleware" "time" ) -func DefaultResourceSendEvent(ctx context.Context, model *model.Resource, eventer api.Manager, reportedTime time.Time, operationType api.OperationType) error { +func DefaultResourceSendEvent(ctx context.Context, model *model.Resource, eventer eventingapi.Manager, reportedTime time.Time, operationType eventingapi.OperationType) error { identity, err := middleware.GetIdentity(ctx) if err != nil { return err } producer, _ := eventer.Lookup(identity, model.ResourceType, model.ID) - evt, err := api.NewResourceEvent(operationType, model, reportedTime) + evt, err := eventingapi.NewResourceEvent(operationType, model, reportedTime) if err != nil { return err } @@ -29,14 +29,14 @@ func DefaultResourceSendEvent(ctx context.Context, model *model.Resource, evente return nil } -func DefaultRelationshipSendEvent(ctx context.Context, m *model.Relationship, eventer api.Manager, reportedTime time.Time, operationType api.OperationType) error { +func DefaultRelationshipSendEvent(ctx context.Context, m *model.Relationship, eventer eventingapi.Manager, reportedTime time.Time, operationType eventingapi.OperationType) error { identity, err := middleware.GetIdentity(ctx) if err != nil { return err } producer, _ := eventer.Lookup(identity, m.RelationshipType, m.ID) - evt, err := api.NewRelationshipEvent(operationType, m, reportedTime) + evt, err := eventingapi.NewRelationshipEvent(operationType, m, reportedTime) if err != nil { return err } diff --git a/internal/biz/relationships/relationships.go b/internal/biz/relationships/relationships.go index 84bda279..b1c52867 100644 --- a/internal/biz/relationships/relationships.go +++ b/internal/biz/relationships/relationships.go @@ -3,13 +3,13 @@ package resources import ( "context" "errors" - "github.com/project-kessel/inventory-api/eventing/api" "time" "github.com/go-kratos/kratos/v2/log" "github.com/google/uuid" "github.com/project-kessel/inventory-api/internal/biz" "github.com/project-kessel/inventory-api/internal/biz/model" + eventingapi "github.com/project-kessel/inventory-api/internal/eventing/api" "gorm.io/gorm" ) @@ -25,7 +25,7 @@ type ResourceRepository interface { type Usecase struct { repository ResourceRepository - eventer api.Manager + eventer eventingapi.Manager log *log.Helper DisablePersistence bool } @@ -37,7 +37,7 @@ var ( ErrRelationshipNotFound = errors.New("relationship not found") ) -func New(repository ResourceRepository, eventer api.Manager, logger log.Logger, disablePersistence bool) *Usecase { +func New(repository ResourceRepository, eventer eventingapi.Manager, logger log.Logger, disablePersistence bool) *Usecase { return &Usecase{ repository: repository, eventer: eventer, @@ -84,7 +84,7 @@ func (uc *Usecase) Create(ctx context.Context, m *model.Relationship) (*model.Re } if uc.eventer != nil { - err := biz.DefaultRelationshipSendEvent(ctx, m, uc.eventer, *m.CreatedAt, api.OperationTypeCreated) + err := biz.DefaultRelationshipSendEvent(ctx, m, uc.eventer, *m.CreatedAt, eventingapi.OperationTypeCreated) if err != nil { return nil, err @@ -131,7 +131,7 @@ func (uc *Usecase) Update(ctx context.Context, m *model.Relationship, id model.R } if uc.eventer != nil { - err := biz.DefaultRelationshipSendEvent(ctx, m, uc.eventer, *m.UpdatedAt, api.OperationTypeUpdated) + err := biz.DefaultRelationshipSendEvent(ctx, m, uc.eventer, *m.UpdatedAt, eventingapi.OperationTypeUpdated) if err != nil { return nil, err @@ -172,7 +172,7 @@ func (uc *Usecase) Delete(ctx context.Context, id model.ReporterRelationshipId) } if uc.eventer != nil { - err := biz.DefaultRelationshipSendEvent(ctx, m, uc.eventer, time.Now(), api.OperationTypeDeleted) + err := biz.DefaultRelationshipSendEvent(ctx, m, uc.eventer, time.Now(), eventingapi.OperationTypeDeleted) if err != nil { return err diff --git a/internal/biz/resources/resources.go b/internal/biz/resources/resources.go index e0cc0ba3..b0f1b35d 100644 --- a/internal/biz/resources/resources.go +++ b/internal/biz/resources/resources.go @@ -4,13 +4,13 @@ import ( "context" "errors" "github.com/google/uuid" - "github.com/project-kessel/inventory-api/eventing/api" "time" "github.com/go-kratos/kratos/v2/log" authzapi "github.com/project-kessel/inventory-api/internal/authz/api" "github.com/project-kessel/inventory-api/internal/biz" "github.com/project-kessel/inventory-api/internal/biz/model" + eventingapi "github.com/project-kessel/inventory-api/internal/eventing/api" "github.com/project-kessel/inventory-api/internal/server" "gorm.io/gorm" ) @@ -33,14 +33,14 @@ var ( type Usecase struct { repository ResourceRepository Authz authzapi.Authorizer - Eventer api.Manager + Eventer eventingapi.Manager Namespace string log *log.Helper Server server.Server DisablePersistence bool } -func New(repository ResourceRepository, authz authzapi.Authorizer, eventer api.Manager, namespace string, logger log.Logger, disablePersistence bool) *Usecase { +func New(repository ResourceRepository, authz authzapi.Authorizer, eventer eventingapi.Manager, namespace string, logger log.Logger, disablePersistence bool) *Usecase { return &Usecase{ repository: repository, Authz: authz, @@ -76,7 +76,7 @@ func (uc *Usecase) Create(ctx context.Context, m *model.Resource) (*model.Resour } if uc.Eventer != nil { - err := biz.DefaultResourceSendEvent(ctx, m, uc.Eventer, *m.CreatedAt, api.OperationTypeCreated) + err := biz.DefaultResourceSendEvent(ctx, m, uc.Eventer, *m.CreatedAt, eventingapi.OperationTypeCreated) if err != nil { return nil, err @@ -122,7 +122,7 @@ func (uc *Usecase) Update(ctx context.Context, m *model.Resource, id model.Repor } if uc.Eventer != nil { - err := biz.DefaultResourceSendEvent(ctx, m, uc.Eventer, *m.UpdatedAt, api.OperationTypeUpdated) + err := biz.DefaultResourceSendEvent(ctx, m, uc.Eventer, *m.UpdatedAt, eventingapi.OperationTypeUpdated) if err != nil { return nil, err @@ -167,7 +167,7 @@ func (uc *Usecase) Delete(ctx context.Context, id model.ReporterResourceId) erro } if uc.Eventer != nil { - err := biz.DefaultResourceSendEvent(ctx, m, uc.Eventer, time.Now(), api.OperationTypeDeleted) + err := biz.DefaultResourceSendEvent(ctx, m, uc.Eventer, time.Now(), eventingapi.OperationTypeDeleted) if err != nil { return err diff --git a/internal/config/config.go b/internal/config/config.go index b48ed6eb..c0ebcb8a 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -3,9 +3,9 @@ package config import ( "fmt" "github.com/go-kratos/kratos/v2/log" - "github.com/project-kessel/inventory-api/eventing" "github.com/project-kessel/inventory-api/internal/authn" "github.com/project-kessel/inventory-api/internal/authz" + "github.com/project-kessel/inventory-api/internal/eventing" "github.com/project-kessel/inventory-api/internal/server" "github.com/project-kessel/inventory-api/internal/storage" clowder "github.com/redhatinsights/app-common-go/pkg/api/v1" diff --git a/internal/data/relationships/relationships.go b/internal/data/relationships/relationships.go index 5ce3b8db..73a23858 100644 --- a/internal/data/relationships/relationships.go +++ b/internal/data/relationships/relationships.go @@ -3,9 +3,9 @@ package resources import ( "context" "github.com/google/uuid" - eventingapi "github.com/project-kessel/inventory-api/eventing/api" "github.com/project-kessel/inventory-api/internal/biz/model" "github.com/project-kessel/inventory-api/internal/data" + eventingapi "github.com/project-kessel/inventory-api/internal/eventing/api" "gorm.io/gorm" ) diff --git a/eventing/README.md b/internal/eventing/README.md similarity index 100% rename from eventing/README.md rename to internal/eventing/README.md diff --git a/eventing/api/event.go b/internal/eventing/api/event.go similarity index 100% rename from eventing/api/event.go rename to internal/eventing/api/event.go diff --git a/eventing/api/manager.go b/internal/eventing/api/manager.go similarity index 100% rename from eventing/api/manager.go rename to internal/eventing/api/manager.go diff --git a/eventing/api/producer.go b/internal/eventing/api/producer.go similarity index 100% rename from eventing/api/producer.go rename to internal/eventing/api/producer.go diff --git a/eventing/config.go b/internal/eventing/config.go similarity index 91% rename from eventing/config.go rename to internal/eventing/config.go index 1db6fbfb..4ee1bb72 100644 --- a/eventing/config.go +++ b/internal/eventing/config.go @@ -1,7 +1,7 @@ package eventing import ( - "github.com/project-kessel/inventory-api/eventing/kafka" + "github.com/project-kessel/inventory-api/internal/eventing/kafka" ) type Config struct { diff --git a/eventing/factory.go b/internal/eventing/factory.go similarity index 70% rename from eventing/factory.go rename to internal/eventing/factory.go index 836c5bd6..f8c33fad 100644 --- a/eventing/factory.go +++ b/internal/eventing/factory.go @@ -2,11 +2,12 @@ package eventing import ( "fmt" - "github.com/project-kessel/inventory-api/eventing/api" - "github.com/project-kessel/inventory-api/eventing/kafka" - "github.com/project-kessel/inventory-api/eventing/stdout" "github.com/go-kratos/kratos/v2/log" + + "github.com/project-kessel/inventory-api/internal/eventing/api" + "github.com/project-kessel/inventory-api/internal/eventing/kafka" + "github.com/project-kessel/inventory-api/internal/eventing/stdout" ) func New(c CompletedConfig, source string, logger *log.Helper) (api.Manager, error) { diff --git a/eventing/kafka/config.go b/internal/eventing/kafka/config.go similarity index 100% rename from eventing/kafka/config.go rename to internal/eventing/kafka/config.go diff --git a/eventing/kafka/manager.go b/internal/eventing/kafka/manager.go similarity index 98% rename from eventing/kafka/manager.go rename to internal/eventing/kafka/manager.go index d2afdae6..dbfae779 100644 --- a/eventing/kafka/manager.go +++ b/internal/eventing/kafka/manager.go @@ -8,12 +8,12 @@ import ( "github.com/confluentinc/confluent-kafka-go/v2/kafka" "github.com/go-kratos/kratos/v2/log" "github.com/google/uuid" - api "github.com/project-kessel/inventory-api/eventing/api" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" authnapi "github.com/project-kessel/inventory-api/internal/authn/api" + "github.com/project-kessel/inventory-api/internal/eventing/api" ) type KafkaManager struct { diff --git a/eventing/kafka/options.go b/internal/eventing/kafka/options.go similarity index 100% rename from eventing/kafka/options.go rename to internal/eventing/kafka/options.go diff --git a/eventing/options.go b/internal/eventing/options.go similarity index 93% rename from eventing/options.go rename to internal/eventing/options.go index 63401b09..192503e5 100644 --- a/eventing/options.go +++ b/internal/eventing/options.go @@ -2,8 +2,8 @@ package eventing import ( "errors" - "github.com/project-kessel/inventory-api/eventing/kafka" + "github.com/project-kessel/inventory-api/internal/eventing/kafka" "github.com/spf13/pflag" ) diff --git a/eventing/stdout/manager.go b/internal/eventing/stdout/manager.go similarity index 93% rename from eventing/stdout/manager.go rename to internal/eventing/stdout/manager.go index ea9b32f8..812700f3 100644 --- a/eventing/stdout/manager.go +++ b/internal/eventing/stdout/manager.go @@ -4,11 +4,11 @@ import ( "context" "encoding/json" "github.com/google/uuid" - api "github.com/project-kessel/inventory-api/eventing/api" "os" "github.com/go-kratos/kratos/v2/log" authnapi "github.com/project-kessel/inventory-api/internal/authn/api" + "github.com/project-kessel/inventory-api/internal/eventing/api" ) type StdOutManager struct {