Skip to content

Commit

Permalink
Mock delete event
Browse files Browse the repository at this point in the history
  • Loading branch information
josejulio committed Sep 18, 2024
1 parent cd0e25d commit 73c457d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
21 changes: 19 additions & 2 deletions internal/data/relationships/k8spolicy/ispropagatedto_k8scluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package k8spolicy

import (
"context"
"github.com/project-kessel/inventory-api/internal/biz/common"
biz "github.com/project-kessel/inventory-api/internal/biz/relationships/k8spolicy"
eventingapi "github.com/project-kessel/inventory-api/internal/eventing/api"
"github.com/project-kessel/inventory-api/internal/middleware"
Expand Down Expand Up @@ -67,9 +68,12 @@ func (r *K8SPolicyIsPropagatedToK8SClusterRepo) Update(ctx context.Context, mode

if r.Eventer != nil {
producer, _ := r.Eventer.Lookup(identity, biz.RelationType, model.ID)
evt := eventingapi.NewUpdatedResourcesRelationshipEvent(biz.RelationType, model.Metadata.Reporters[0].SubjectLocalResourceId, model.Metadata.UpdatedAt, &eventingapi.EventRelationship[struct{}]{
evt := eventingapi.NewUpdatedResourcesRelationshipEvent(biz.RelationType, model.Metadata.Reporters[0].SubjectLocalResourceId, model.Metadata.UpdatedAt, &eventingapi.EventRelationship[K8SPolicyIsPropagatedToK8SClusterDetail]{
Metadata: &model.Metadata,
ReporterData: model.Metadata.Reporters[0],
RelationshipData: &K8SPolicyIsPropagatedToK8SClusterDetail{
Status: model.Status,
},
})
err = producer.Produce(ctx, evt)
if err != nil {
Expand All @@ -93,7 +97,20 @@ func (r *K8SPolicyIsPropagatedToK8SClusterRepo) Delete(ctx context.Context, id s
var dummyId int64 = 0
producer, _ := r.Eventer.Lookup(identity, biz.RelationType, dummyId)
// Todo: Load the model to fetch the (subject|object)_local_resource_id to fill in the model
evt := eventingapi.NewDeletedResourcesRelationshipEvent(biz.RelationType, id, id, time.Now().UTC(), identity)
evt := eventingapi.NewDeletedResourcesRelationshipEvent(biz.RelationType, id, time.Now().UTC(), &eventingapi.EventRelationship[K8SPolicyIsPropagatedToK8SClusterDetail]{
Metadata: &common.RelationshipMetadata{},
ReporterData: &common.RelationshipReporter{
ReporterID: identity.Principal,
ReporterType: identity.Type,
SubjectLocalResourceId: "local-id",
ObjectLocalResourceId: "local-id",
},
RelationshipData: &K8SPolicyIsPropagatedToK8SClusterDetail{
Status: "COMPLIANT",
K8SClusterId: 0,
K8SPolicyId: 0,
},
})
err = producer.Produce(ctx, evt)
if err != nil {
return err
Expand Down
13 changes: 2 additions & 11 deletions internal/eventing/api/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,13 @@ func NewUpdatedResourcesRelationshipEvent[Detail any](relationshipType, subjectR
}
}

func NewDeletedResourcesRelationshipEvent(relationshipType, subjectResourceId string, objectResourceId string, lastReportedTime time.Time, requester *authnapi.Identity) *Event {
func NewDeletedResourcesRelationshipEvent[Detail any](relationshipType, subjectResourceId string, lastReportedTime time.Time, obj *EventRelationship[Detail]) *Event {
return &Event{
EventType: EventTypeResourcesRelationship,
OperationType: operationTypeDeleted,
EventTime: lastReportedTime,
ResourceType: relationshipType,
ResourceId: subjectResourceId,
Resource: &EventRelationship[struct{}]{
Metadata: &biz.RelationshipMetadata{},
ReporterData: &biz.RelationshipReporter{
ReporterID: requester.Principal,
ReporterType: requester.Type,
SubjectLocalResourceId: subjectResourceId,
ObjectLocalResourceId: objectResourceId,
},
RelationshipData: nil,
},
Resource: obj,
}
}

0 comments on commit 73c457d

Please sign in to comment.