From 1695a98bd9281f26fbbf9b8b71a6713141c7e1d6 Mon Sep 17 00:00:00 2001 From: vj Date: Mon, 27 Jan 2025 18:14:45 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20handling=20of=20aws=20filt?= =?UTF-8?q?ers=20(ensure=20filters=20are=20copied=20in=20cfg=20clone)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- providers-sdk/v1/inventory/inventory.go | 19 +++++++++++++++++++ .../aws/resources/discovery_conversion.go | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/providers-sdk/v1/inventory/inventory.go b/providers-sdk/v1/inventory/inventory.go index c276a47c0b..e90333338f 100644 --- a/providers-sdk/v1/inventory/inventory.go +++ b/providers-sdk/v1/inventory/inventory.go @@ -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{} @@ -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 } diff --git a/providers/aws/resources/discovery_conversion.go b/providers/aws/resources/discovery_conversion.go index cfa2a8dbb2..27176c02a5 100644 --- a/providers/aws/resources/discovery_conversion.go +++ b/providers/aws/resources/discovery_conversion.go @@ -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(), } }