Skip to content

Commit

Permalink
Add entities.metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
romulets committed Nov 25, 2024
1 parent fa1dc29 commit 15f39b6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
23 changes: 23 additions & 0 deletions internal/inventory/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,32 @@ type AssetResourcePolicy struct {
Condition map[string]any `json:"condition,omitempty"`
}

// EntityMetadata maps metadata required to use Entity Store
type entityMetadata struct {
Category string `json:"category"`
Type string `json:"type"`
}

// AssetEnricher functional builder function
type AssetEnricher func(asset *AssetEvent)

func (a *AssetEvent) getEntityMetadata() map[string]entityMetadata {
ids := a.Asset.Id

if len(ids) == 0 {
return nil
}

// Picking up only first id, we need to make a decision on if we
// have a "primary" id or if we duplicate data
return map[string]entityMetadata{
ids[0]: {
Category: string(a.Asset.Category),
Type: string(a.Asset.Type),
},
}
}

func NewAssetEvent(c AssetClassification, ids []string, name string, enrichers ...AssetEnricher) AssetEvent {
a := AssetEvent{
Asset: Asset{
Expand Down
1 change: 1 addition & 0 deletions internal/inventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (a *AssetInventory) publish(assets []AssetEvent) {
"iam": e.IAM,
"resource_policies": e.ResourcePolicies,
"related.entity": e.Asset.Id,
"entities": map[string]any{"metadata": e.getEntityMetadata()},
},
}
})
Expand Down
8 changes: 8 additions & 0 deletions internal/inventory/inventory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ func TestAssetInventory_Run(t *testing.T) {
},
},
"related.entity": []string{"arn:aws:ec2:us-east::ec2/234567890"},
"entities": map[string]any{
"metadata": map[string]entityMetadata{
"arn:aws:ec2:us-east::ec2/234567890": {
Category: string(CategoryInfrastructure),
Type: string(TypeVirtualMachine),
},
},
},
},
},
}
Expand Down

0 comments on commit 15f39b6

Please sign in to comment.