Skip to content

Commit

Permalink
🐛 fix handling of aws filters (ensure filters are copied in cfg clone) (
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeffrey authored Jan 28, 2025
1 parent 985236b commit b3c787a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions providers-sdk/v1/inventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,22 @@ func (p *Platform) PrettyTitle() string {
type cloneSettings struct {
noDiscovery bool
parentConnectionId *uint32
withFilters bool
}

type CloneOption interface {
Apply(*cloneSettings)
}

// WithFilters ensures the discovery filters still get copied over
func WithFilters() CloneOption {
return withFilters{}
}

type withFilters struct{}

func (w withFilters) Apply(o *cloneSettings) { o.withFilters = true }

// WithoutDiscovery removes the discovery flags in the opts to ensure the same discovery does not run again
func WithoutDiscovery() CloneOption {
return withoutDiscovery{}
Expand Down Expand Up @@ -433,6 +443,15 @@ func (cfg *Config) Clone(opts ...CloneOption) *Config {
if cloneSettings.parentConnectionId != nil {
clonedObject.ParentConnectionId = *cloneSettings.parentConnectionId
}
if cloneSettings.withFilters {
if clonedObject.Discover == nil {
clonedObject.Discover = &Discovery{}
}
clonedObject.Discover.Filter = make(map[string]string)
for k, v := range cfg.Discover.Filter {
clonedObject.Discover.Filter[k] = v
}
}

return clonedObject
}
Expand Down
2 changes: 1 addition & 1 deletion providers/aws/resources/discovery_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func accountAsset(conn *connection.AwsConnection, awsAccount *mqlAwsAccount) *in
PlatformIds: []string{id, accountArn},
Name: name,
Platform: connection.GetPlatformForObject("", accountId),
Connections: []*inventory.Config{conn.Conf.Clone(inventory.WithoutDiscovery(), inventory.WithParentConnectionId(conn.Conf.Id))},
Connections: []*inventory.Config{conn.Conf.Clone(inventory.WithoutDiscovery(), inventory.WithParentConnectionId(conn.Conf.Id), inventory.WithFilters())},
Options: conn.ConnectionOptions(),
}
}
Expand Down

0 comments on commit b3c787a

Please sign in to comment.