Skip to content

Commit

Permalink
Move eventing outside of internal
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam0Brien committed Nov 29, 2024
1 parent edd8f22 commit d6f82f0
Show file tree
Hide file tree
Showing 17 changed files with 29 additions and 29 deletions.
5 changes: 3 additions & 2 deletions cmd/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package serve
import (
"context"
"fmt"

"os"
"os/signal"
"syscall"
Expand All @@ -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"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/eventing/config.go → eventing/config.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions internal/eventing/factory.go → eventing/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/eventing/options.go → eventing/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions internal/biz/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
12 changes: 6 additions & 6 deletions internal/biz/relationships/relationships.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -25,7 +25,7 @@ type ResourceRepository interface {

type Usecase struct {
repository ResourceRepository
eventer eventingapi.Manager
eventer api.Manager
log *log.Helper
DisablePersistence bool
}
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions internal/biz/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion internal/data/relationships/relationships.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down

0 comments on commit d6f82f0

Please sign in to comment.