Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Move eventing code" #7

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmd/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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 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
}
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 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
}
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 api.Manager
eventer eventingapi.Manager
log *log.Helper
DisablePersistence bool
}
Expand All @@ -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,
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, api.OperationTypeCreated)
err := biz.DefaultRelationshipSendEvent(ctx, m, uc.eventer, *m.CreatedAt, eventingapi.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, api.OperationTypeUpdated)
err := biz.DefaultRelationshipSendEvent(ctx, m, uc.eventer, *m.UpdatedAt, eventingapi.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(), api.OperationTypeDeleted)
err := biz.DefaultRelationshipSendEvent(ctx, m, uc.eventer, time.Now(), eventingapi.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 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,
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, api.OperationTypeCreated)
err := biz.DefaultResourceSendEvent(ctx, m, uc.Eventer, *m.CreatedAt, eventingapi.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, api.OperationTypeUpdated)
err := biz.DefaultResourceSendEvent(ctx, m, uc.Eventer, *m.UpdatedAt, eventingapi.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(), api.OperationTypeDeleted)
err := biz.DefaultResourceSendEvent(ctx, m, uc.Eventer, time.Now(), eventingapi.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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion eventing/config.go → internal/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/eventing/kafka"
"github.com/project-kessel/inventory-api/internal/eventing/kafka"
)

type Config struct {
Expand Down
7 changes: 4 additions & 3 deletions eventing/factory.go → internal/eventing/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
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 eventing/options.go → internal/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
Loading