From 201098973b9b35c183bbf1e1f391af0a3995eab2 Mon Sep 17 00:00:00 2001 From: vj Date: Tue, 28 Jan 2025 17:29:11 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20add=20labels=20to=20gcp=20discov?= =?UTF-8?q?ered=20assets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- providers/gcp/resources/discovery.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/providers/gcp/resources/discovery.go b/providers/gcp/resources/discovery.go index 72df9a73b7..f43b65cf04 100644 --- a/providers/gcp/resources/discovery.go +++ b/providers/gcp/resources/discovery.go @@ -184,7 +184,7 @@ func discoverOrganization(conn *connection.GcpConnection, gcpOrg *mqlGcpOrganiza Family: []string{"google"}, TechnologyUrlSegments: []string{"gcp", project.Id.Data, "project"}, }, - Labels: map[string]string{}, + Labels: mapStrInterfaceToMapStrStr(project.GetLabels().Data), Connections: []*inventory.Config{projectConf}, // pass-in the parent connection config }) @@ -273,7 +273,7 @@ func discoverFolder(conn *connection.GcpConnection, gcpFolder *mqlGcpFolder) ([] Family: []string{"google"}, TechnologyUrlSegments: []string{"gcp", project.Id.Data, "project"}, }, - Labels: map[string]string{}, + Labels: mapStrInterfaceToMapStrStr(project.GetLabels().Data), Connections: []*inventory.Config{projectConf}, // pass-in the parent connection config }) } @@ -484,7 +484,7 @@ func discoverProject(conn *connection.GcpConnection, gcpProject *mqlGcpProject) Family: []string{"google"}, TechnologyUrlSegments: connection.ResourceTechnologyUrl("gke", gcpProject.Id.Data, cluster.GetLocation().Data, "cluster", cluster.Name.Data), }, - Labels: map[string]string{}, + Labels: mapStrInterfaceToMapStrStr(cluster.GetResourceLabels().Data), Connections: []*inventory.Config{conn.Conf.Clone(inventory.WithoutDiscovery(), inventory.WithParentConnectionId(conn.Conf.Id))}, // pass-in the parent connection config }) } @@ -513,7 +513,7 @@ func discoverProject(conn *connection.GcpConnection, gcpProject *mqlGcpProject) Family: []string{"google"}, TechnologyUrlSegments: connection.ResourceTechnologyUrl("storage", gcpProject.Id.Data, bucket.GetLocation().Data, "bucket", bucket.Name.Data), }, - Labels: map[string]string{}, + Labels: mapStrInterfaceToMapStrStr(bucket.GetLabels().Data), Connections: []*inventory.Config{conn.Conf.Clone(inventory.WithoutDiscovery(), inventory.WithParentConnectionId(conn.Conf.Id))}, // pass-in the parent connection config }) } @@ -542,7 +542,7 @@ func discoverProject(conn *connection.GcpConnection, gcpProject *mqlGcpProject) Family: []string{"google"}, TechnologyUrlSegments: connection.ResourceTechnologyUrl("bigquery", gcpProject.Id.Data, dataset.GetLocation().Data, "dataset", dataset.Id.Data), }, - Labels: map[string]string{}, + Labels: mapStrInterfaceToMapStrStr(dataset.GetLabels().Data), Connections: []*inventory.Config{conn.Conf.Clone(inventory.WithoutDiscovery(), inventory.WithParentConnectionId(conn.Conf.Id))}, // pass-in the parent connection config }) } @@ -674,3 +674,13 @@ func (a *GcrImages) List() ([]*inventory.Asset, error) { wg.Wait() return assets, nil } + +func mapStrInterfaceToMapStrStr(m map[string]interface{}) map[string]string { + strMap := make(map[string]string) + for k, v := range m { + if v != nil { + strMap[k] = v.(string) + } + } + return strMap +}