From d6f82f00ba0da2101182988a485b230768eca0b3 Mon Sep 17 00:00:00 2001 From: Adam0Brien Date: Fri, 29 Nov 2024 15:11:02 +0000 Subject: [PATCH] Move eventing outside of internal --- cmd/serve/serve.go | 5 +++-- {internal/eventing => eventing}/README.md | 0 {internal/eventing => eventing}/api/event.go | 0 {internal/eventing => eventing}/api/manager.go | 0 {internal/eventing => eventing}/api/producer.go | 0 {internal/eventing => eventing}/config.go | 2 +- {internal/eventing => eventing}/factory.go | 7 +++---- {internal/eventing => eventing}/kafka/config.go | 0 {internal/eventing => eventing}/kafka/manager.go | 2 +- {internal/eventing => eventing}/kafka/options.go | 0 {internal/eventing => eventing}/options.go | 2 +- {internal/eventing => eventing}/stdout/manager.go | 2 +- 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 +- 17 files changed, 29 insertions(+), 29 deletions(-) rename {internal/eventing => eventing}/README.md (100%) rename {internal/eventing => eventing}/api/event.go (100%) rename {internal/eventing => eventing}/api/manager.go (100%) rename {internal/eventing => eventing}/api/producer.go (100%) rename {internal/eventing => eventing}/config.go (91%) rename {internal/eventing => eventing}/factory.go (70%) rename {internal/eventing => eventing}/kafka/config.go (100%) rename {internal/eventing => eventing}/kafka/manager.go (98%) rename {internal/eventing => eventing}/kafka/options.go (100%) rename {internal/eventing => eventing}/options.go (93%) rename {internal/eventing => eventing}/stdout/manager.go (93%) diff --git a/cmd/serve/serve.go b/cmd/serve/serve.go index b0c40185..027763ef 100644 --- a/cmd/serve/serve.go +++ b/cmd/serve/serve.go @@ -3,6 +3,7 @@ package serve import ( "context" "fmt" + "os" "os/signal" "syscall" @@ -23,11 +24,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/eventing/README.md b/eventing/README.md similarity index 100% rename from internal/eventing/README.md rename to eventing/README.md diff --git a/internal/eventing/api/event.go b/eventing/api/event.go similarity index 100% rename from internal/eventing/api/event.go rename to eventing/api/event.go diff --git a/internal/eventing/api/manager.go b/eventing/api/manager.go similarity index 100% rename from internal/eventing/api/manager.go rename to eventing/api/manager.go diff --git a/internal/eventing/api/producer.go b/eventing/api/producer.go similarity index 100% rename from internal/eventing/api/producer.go rename to eventing/api/producer.go diff --git a/internal/eventing/config.go b/eventing/config.go similarity index 91% rename from internal/eventing/config.go rename to eventing/config.go index 4ee1bb72..1db6fbfb 100644 --- a/internal/eventing/config.go +++ b/eventing/config.go @@ -1,7 +1,7 @@ package eventing import ( - "github.com/project-kessel/inventory-api/internal/eventing/kafka" + "github.com/project-kessel/inventory-api/eventing/kafka" ) type Config struct { diff --git a/internal/eventing/factory.go b/eventing/factory.go similarity index 70% rename from internal/eventing/factory.go rename to eventing/factory.go index f8c33fad..836c5bd6 100644 --- a/internal/eventing/factory.go +++ b/eventing/factory.go @@ -2,12 +2,11 @@ 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/internal/eventing/kafka/config.go b/eventing/kafka/config.go similarity index 100% rename from internal/eventing/kafka/config.go rename to eventing/kafka/config.go diff --git a/internal/eventing/kafka/manager.go b/eventing/kafka/manager.go similarity index 98% rename from internal/eventing/kafka/manager.go rename to eventing/kafka/manager.go index dbfae779..d2afdae6 100644 --- a/internal/eventing/kafka/manager.go +++ b/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/internal/eventing/kafka/options.go b/eventing/kafka/options.go similarity index 100% rename from internal/eventing/kafka/options.go rename to eventing/kafka/options.go diff --git a/internal/eventing/options.go b/eventing/options.go similarity index 93% rename from internal/eventing/options.go rename to eventing/options.go index 192503e5..63401b09 100644 --- a/internal/eventing/options.go +++ b/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/internal/eventing/stdout/manager.go b/eventing/stdout/manager.go similarity index 93% rename from internal/eventing/stdout/manager.go rename to eventing/stdout/manager.go index 812700f3..ea9b32f8 100644 --- a/internal/eventing/stdout/manager.go +++ b/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 { diff --git a/internal/biz/common.go b/internal/biz/common.go index 11513b06..9b070eb0 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 eventingapi.Manager, reportedTime time.Time, operationType eventingapi.OperationType) error { +func DefaultResourceSendEvent(ctx context.Context, model *model.Resource, eventer api.Manager, reportedTime time.Time, operationType api.OperationType) error { identity, err := middleware.GetIdentity(ctx) if err != nil { return err } producer, _ := eventer.Lookup(identity, model.ResourceType, model.ID) - evt, err := eventingapi.NewResourceEvent(operationType, model, reportedTime) + evt, err := api.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 eventingapi.Manager, reportedTime time.Time, operationType eventingapi.OperationType) error { +func DefaultRelationshipSendEvent(ctx context.Context, m *model.Relationship, eventer api.Manager, reportedTime time.Time, operationType api.OperationType) error { identity, err := middleware.GetIdentity(ctx) if err != nil { return err } producer, _ := eventer.Lookup(identity, m.RelationshipType, m.ID) - evt, err := eventingapi.NewRelationshipEvent(operationType, m, reportedTime) + evt, err := api.NewRelationshipEvent(operationType, m, reportedTime) if err != nil { return err } diff --git a/internal/biz/relationships/relationships.go b/internal/biz/relationships/relationships.go index b1c52867..84bda279 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 eventingapi.Manager + eventer api.Manager log *log.Helper DisablePersistence bool } @@ -37,7 +37,7 @@ var ( ErrRelationshipNotFound = errors.New("relationship not found") ) -func New(repository ResourceRepository, eventer eventingapi.Manager, logger log.Logger, disablePersistence bool) *Usecase { +func New(repository ResourceRepository, eventer api.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, eventingapi.OperationTypeCreated) + err := biz.DefaultRelationshipSendEvent(ctx, m, uc.eventer, *m.CreatedAt, api.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, eventingapi.OperationTypeUpdated) + err := biz.DefaultRelationshipSendEvent(ctx, m, uc.eventer, *m.UpdatedAt, api.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(), eventingapi.OperationTypeDeleted) + err := biz.DefaultRelationshipSendEvent(ctx, m, uc.eventer, time.Now(), api.OperationTypeDeleted) if err != nil { return err diff --git a/internal/biz/resources/resources.go b/internal/biz/resources/resources.go index b0f1b35d..e0cc0ba3 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 eventingapi.Manager + Eventer api.Manager Namespace string log *log.Helper Server server.Server DisablePersistence bool } -func New(repository ResourceRepository, authz authzapi.Authorizer, eventer eventingapi.Manager, namespace string, logger log.Logger, disablePersistence bool) *Usecase { +func New(repository ResourceRepository, authz authzapi.Authorizer, eventer api.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, eventingapi.OperationTypeCreated) + err := biz.DefaultResourceSendEvent(ctx, m, uc.Eventer, *m.CreatedAt, api.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, eventingapi.OperationTypeUpdated) + err := biz.DefaultResourceSendEvent(ctx, m, uc.Eventer, *m.UpdatedAt, api.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(), eventingapi.OperationTypeDeleted) + err := biz.DefaultResourceSendEvent(ctx, m, uc.Eventer, time.Now(), api.OperationTypeDeleted) if err != nil { return err diff --git a/internal/config/config.go b/internal/config/config.go index c0ebcb8a..b48ed6eb 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 73a23858..5ce3b8db 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" )