Skip to content

Commit

Permalink
🧹 Remove scope from gcp urls (#3727)
Browse files Browse the repository at this point in the history
The format is now "/gcp/projectid/servicename/...".
Project resources get a special "servicename" call "project"
  • Loading branch information
jaym authored Apr 8, 2024
1 parent 6c69a57 commit b0ec569
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 85 deletions.
101 changes: 43 additions & 58 deletions providers/gcp/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,81 +77,66 @@ var Config = plugin.Provider{
AssetUrlTrees: []*inventory.AssetUrlBranch{
{
PathSegments: []string{"technology=gcp"},
Key: "scope",
Title: "Scope",
Key: "project",
Title: "Project",
Values: map[string]*inventory.AssetUrlBranch{
"other": nil,
"resource manager": {
Key: "object",
Title: "Resource Manager Object Type",
"*": {
Key: "service",
Title: "Service",
Values: map[string]*inventory.AssetUrlBranch{
"organization": nil,
"folder": nil,
"project": nil,
},
},
"project": {
Key: "project",
Title: "Project",
Values: map[string]*inventory.AssetUrlBranch{
"*": {
Key: "service",
Title: "Service",
"project": nil,
"compute": {
Key: "region",
Title: "Region",
Values: map[string]*inventory.AssetUrlBranch{
"compute": {
Key: "region",
Title: "Region",
"*": {
Key: "object",
Title: "Compute Object",
Values: map[string]*inventory.AssetUrlBranch{
"*": {
Key: "object",
Title: "Compute Object",
"instance": {
Key: "type",
Values: map[string]*inventory.AssetUrlBranch{
"instance": {
Key: "type",
Values: map[string]*inventory.AssetUrlBranch{
"resource": nil,
// os ... references the os asset tree
},
},
"image": nil,
"network": nil,
"subnetwork": nil,
"other": nil,
"resource": nil,
// os ... references the os asset tree
},
},
"image": nil,
"network": nil,
"subnetwork": nil,
"other": nil,
},
},
"storage": {
Key: "region",
Title: "Region",
},
},
"storage": {
Key: "region",
Title: "Region",
Values: map[string]*inventory.AssetUrlBranch{
"*": {
Key: "object",
Title: "Storage Object",
Values: map[string]*inventory.AssetUrlBranch{
"*": {
Key: "object",
Title: "Storage Object",
Values: map[string]*inventory.AssetUrlBranch{
"bucket": nil,
"other": nil,
},
},
"bucket": nil,
"other": nil,
},
},
"gke": {
Key: "region",
Title: "Region",
},
},
"gke": {
Key: "region",
Title: "Region",
Values: map[string]*inventory.AssetUrlBranch{
"*": {
Key: "object",
Title: "GKE Object",
Values: map[string]*inventory.AssetUrlBranch{
"*": {
Key: "object",
Title: "GKE Object",
Values: map[string]*inventory.AssetUrlBranch{
"cluster": nil,
"other": nil,
},
},
"cluster": nil,
"other": nil,
},
},
"other": nil,
},
},
"other": nil,
},
},
},
Expand Down
16 changes: 8 additions & 8 deletions providers/gcp/connection/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,27 +120,27 @@ func ResourceTechnologyUrl(service, project, region, objectType, name string) []
case "compute":
switch objectType {
case "instance":
return []string{"gcp", "project", project, "compute", region, "instance", "resource"}
return []string{"gcp", project, "compute", region, "instance", "resource"}
case "image", "network", "subnetwork":
return []string{"gcp", "project", project, "compute", region, objectType}
return []string{"gcp", project, "compute", region, objectType}
default:
return []string{"gcp", "project", project, "compute", region, "other"}
return []string{"gcp", project, "compute", region, "other"}
}
case "storage":
switch objectType {
case "bucket":
return []string{"gcp", "project", project, "storage", region, objectType}
return []string{"gcp", project, "storage", region, objectType}
default:
return []string{"gcp", "project", project, "storage", region, "other"}
return []string{"gcp", project, "storage", region, "other"}
}
case "gke":
switch objectType {
case "cluster":
return []string{"gcp", "project", project, "gke", region, objectType}
return []string{"gcp", project, "gke", region, objectType}
default:
return []string{"gcp", "project", project, "gke", region, "other"}
return []string{"gcp", project, "gke", region, "other"}
}
default:
return []string{"gcp", "project", project, "other"}
return []string{"gcp", project, "other"}
}
}
37 changes: 18 additions & 19 deletions providers/gcp/resources/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ func Discover(runtime *plugin.Runtime) (*inventory.Inventory, error) {
},
Name: "GCP Folder " + gcpFolder.Id.Data,
Platform: &inventory.Platform{
Name: "gcp-folder",
Title: "GCP Folder",
Runtime: "gcp",
Kind: "gcp-object",
Family: []string{"google"},
TechnologyUrlSegments: []string{"gcp", "resource manager", "folder"},
Name: "gcp-folder",
Title: "GCP Folder",
Runtime: "gcp",
Kind: "gcp-object",
Family: []string{"google"},
},
Labels: map[string]string{},
// NOTE: we explicitly do not exclude discovery here, as we want to discover the projects for the folder
Expand Down Expand Up @@ -108,7 +107,7 @@ func Discover(runtime *plugin.Runtime) (*inventory.Inventory, error) {
Runtime: "gcp",
Kind: "gcp-object",
Family: []string{"google"},
TechnologyUrlSegments: []string{"gcp", "resource manager", "project"},
TechnologyUrlSegments: []string{"gcp", gcpProject.Id.Data, "project"},
},
Labels: map[string]string{},
Connections: []*inventory.Config{conn.Conf.Clone(inventory.WithoutDiscovery(), inventory.WithParentConnectionId(conn.Conf.Id))},
Expand Down Expand Up @@ -177,7 +176,7 @@ func discoverOrganization(conn *connection.GcpConnection, gcpOrg *mqlGcpOrganiza
Runtime: "gcp",
Kind: "gcp-object",
Family: []string{"google"},
TechnologyUrlSegments: []string{"gcp", "resource manager", "project"},
TechnologyUrlSegments: []string{"gcp", project.Id.Data, "project"},
},
Labels: map[string]string{},
Connections: []*inventory.Config{projectConf}, // pass-in the parent connection config
Expand Down Expand Up @@ -210,12 +209,11 @@ func discoverOrganization(conn *connection.GcpConnection, gcpOrg *mqlGcpOrganiza
},
Name: "GCP Folder " + folder.Id.Data,
Platform: &inventory.Platform{
Name: "gcp-folder",
Title: "GCP Folder",
Runtime: "gcp",
Kind: "gcp-object",
Family: []string{"google"},
TechnologyUrlSegments: []string{"gcp", "resource manager", "folder"},
Name: "gcp-folder",
Title: "GCP Folder",
Runtime: "gcp",
Kind: "gcp-object",
Family: []string{"google"},
},
Labels: map[string]string{},
// NOTE: we explicitly do not exclude discovery here, as we want to discover the projects for the folder
Expand Down Expand Up @@ -256,11 +254,12 @@ func discoverFolder(conn *connection.GcpConnection, gcpFolder *mqlGcpFolder) ([]
},
Name: project.Name.Data,
Platform: &inventory.Platform{
Name: "gcp-project",
Title: "GCP Project " + project.Name.Data,
Runtime: "gcp",
Kind: "gcp-object",
Family: []string{"google"},
Name: "gcp-project",
Title: "GCP Project " + project.Name.Data,
Runtime: "gcp",
Kind: "gcp-object",
Family: []string{"google"},
TechnologyUrlSegments: []string{"gcp", project.Id.Data, "project"},
},
Labels: map[string]string{},
Connections: []*inventory.Config{projectConf}, // pass-in the parent connection config
Expand Down

0 comments on commit b0ec569

Please sign in to comment.