Skip to content

Commit

Permalink
🧹 add labels to gcp discovered assets
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeffrey committed Jan 29, 2025
1 parent b3c787a commit 2010989
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions providers/gcp/resources/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand Down Expand Up @@ -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
})
}
Expand Down Expand Up @@ -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
})
}
Expand Down Expand Up @@ -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
})
}
Expand Down Expand Up @@ -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
})
}
Expand Down Expand Up @@ -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
}

0 comments on commit 2010989

Please sign in to comment.