Skip to content

Commit 6164f2d

Browse files
fix: key detectors by config ID to support multiple resources of same type (#21)
## Problem `aurora-postgresql` and `aurora-mysql` both have `type: aurora` in `config/resources.yaml`. The detectors map was keyed by resource type, so the second entry overwrote the first — only 4 detectors were initialized instead of 5. ## Fix Key `invSources`, `eolProviders`, and `detectors` maps by **config ID** (e.g., `aurora-mysql`) instead of resource type (e.g., `aurora`). Update the orchestrator's default resource list to use config IDs. Remove the now-unnecessary type verification check in `ListResources`. ## Changes - `cmd/server/main.go` — key maps by `resourceCfg.ID` instead of `resourceCfg.Type` - `pkg/workflow/orchestrator/workflow.go` — default fan-out uses config IDs - `pkg/inventory/wiz/generic.go` — remove type check in `ListResources` (source knows its own type) - `pkg/inventory/wiz/generic_test.go` — remove obsolete test ## Result Before: `✓ Total detectors initialized: 4` (aurora collision) After: `✓ Total detectors initialized: 5` (aurora-postgresql + aurora-mysql) Co-authored-by: Amp <amp@ampcode.com>
1 parent 563473f commit 6164f2d

4 files changed

Lines changed: 17 additions & 31 deletions

File tree

cmd/server/main.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ func (s *ServerCLI) Run(_ *kong.Context) error {
238238
var registryClient registry.Client
239239

240240
// Initialize detectors from config
241+
// Keyed by config ID (not resource type) to support multiple resources
242+
// of the same type (e.g., aurora-postgresql and aurora-mysql both type "aurora")
241243
fmt.Println("\nInitializing detectors from configuration...")
242244
detectors := make(map[types.ResourceType]interface{})
243245
invSources := make(map[types.ResourceType]inventory.InventorySource)
@@ -274,14 +276,14 @@ func (s *ServerCLI) Run(_ *kong.Context) error {
274276
continue
275277
}
276278

277-
// Store in maps for Temporal activities
278-
resourceType := types.ResourceType(resourceCfg.Type)
279-
invSources[resourceType] = invSource
280-
eolProviders[resourceType] = eolProvider
279+
// Store in maps for Temporal activities, keyed by config ID
280+
configID := types.ResourceType(resourceCfg.ID)
281+
invSources[configID] = invSource
282+
eolProviders[configID] = eolProvider
281283

282284
// Create generic detector
283285
detector := generic.NewDetector(resourceCfg, invSource, eolProvider, policyEngine, logger)
284-
detectors[resourceType] = detector
286+
detectors[configID] = detector
285287
fmt.Printf(" ✓ Generic detector initialized for %s\n", resourceCfg.ID)
286288
}
287289

pkg/inventory/wiz/generic.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,10 @@ func (s *GenericInventorySource) CloudProvider() types.CloudProvider {
7171
}
7272
}
7373

74-
// ListResources fetches resources from Wiz using the configured report
74+
// ListResources fetches resources from Wiz using the configured report.
75+
// The resourceType parameter is accepted for interface compatibility but
76+
// the source uses its own config type internally.
7577
func (s *GenericInventorySource) ListResources(ctx context.Context, resourceType types.ResourceType) ([]*types.Resource, error) {
76-
// Verify resource type matches config
77-
if string(resourceType) != s.config.Type {
78-
return nil, errors.Errorf("unsupported resource type: %s (expected: %s)", resourceType, s.config.Type)
79-
}
80-
8178
// Get report ID from WIZ_REPORT_IDS map
8279
reportID, err := getReportIDFromMap(s.config.ID)
8380
if err != nil {
@@ -266,7 +263,7 @@ func (s *GenericInventorySource) parseResourceRow(
266263
resource := &types.Resource{
267264
ID: externalID,
268265
Name: name,
269-
Type: types.ResourceType(s.config.Type),
266+
Type: types.ResourceType(s.config.ID),
270267
CloudProvider: s.CloudProvider(),
271268
CloudAccountID: accountID,
272269
CloudRegion: region,

pkg/inventory/wiz/generic_test.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ func TestParseResourceRow(t *testing.T) {
318318
require.NoError(t, err)
319319
assert.Equal(t, "arn:aws:rds:us-west-2:123456789012:cluster:my-cluster", resource.ID)
320320
assert.Equal(t, "my-cluster", resource.Name)
321-
assert.Equal(t, types.ResourceType("aurora"), resource.Type)
321+
assert.Equal(t, types.ResourceType("aurora-postgresql"), resource.Type)
322322
assert.Equal(t, types.CloudProviderAWS, resource.CloudProvider)
323323
assert.Equal(t, "123456789012", resource.CloudAccountID)
324324
assert.Equal(t, "us-west-2", resource.CloudRegion)
@@ -424,21 +424,6 @@ func TestGetRequiredColumns_NoMappings(t *testing.T) {
424424
assert.Len(t, columns, 6) // Only the 6 base columns
425425
}
426426

427-
func TestListResources_UnsupportedResourceType(t *testing.T) {
428-
cfg := config.ResourceConfig{
429-
ID: "aurora-postgresql",
430-
Type: "aurora",
431-
}
432-
433-
source := NewGenericInventorySource(&Client{}, &cfg, nil, nil)
434-
435-
ctx := context.Background()
436-
_, err := source.ListResources(ctx, types.ResourceType("eks"))
437-
438-
assert.Error(t, err)
439-
assert.Contains(t, err.Error(), "unsupported resource type")
440-
}
441-
442427
func TestListResources_NoReportID(t *testing.T) {
443428
// Ensure WIZ_REPORT_IDS is not set
444429
os.Unsetenv("WIZ_REPORT_IDS")

pkg/workflow/orchestrator/workflow.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ func OrchestratorWorkflow(ctx workflow.Context, input WorkflowInput) (*WorkflowO
6666
// Default to all supported resource types if none specified
6767
resourceTypes := input.ResourceTypes
6868
if len(resourceTypes) == 0 {
69-
// Use lowercase resource types that match config file
69+
// Use config IDs from resources.yaml (not resource types)
70+
// to support multiple resources of the same type
7071
resourceTypes = []types.ResourceType{
71-
"aurora",
72-
"elasticache",
72+
"aurora-postgresql",
73+
"aurora-mysql",
7374
"eks",
75+
"elasticache-redis",
7476
"opensearch",
7577
}
7678
}

0 commit comments

Comments
 (0)