-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathartifact_registry_location_list.go
55 lines (44 loc) · 1.45 KB
/
artifact_registry_location_list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package gcp
import (
"context"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"google.golang.org/api/artifactregistry/v1"
)
// BuildregionList :: return a list of matrix items, one per region specified
func BuildArtifactRegistryLocationList(ctx context.Context, d *plugin.QueryData) []map[string]interface{} {
// have we already created and cached the locations?
locationCacheKey := "ArtifactRegistry"
if cachedData, ok := d.ConnectionManager.Cache.Get(locationCacheKey); ok {
plugin.Logger(ctx).Trace("listlocationDetails:", cachedData.([]map[string]interface{}))
return cachedData.([]map[string]interface{})
}
// Create Service Connection
service, err := ArtifactRegistryService(ctx, d)
if err != nil {
return nil
}
// Get project details
projectData, err := activeProject(ctx, d)
if err != nil {
return nil
}
project := projectData.Project
resp := service.Projects.Locations.List("projects/" + project)
if err != nil {
return nil
}
var locations []*artifactregistry.Location
if err := resp.Pages(ctx, func(page *artifactregistry.ListLocationsResponse) error {
locations = append(locations, page.Locations...)
return nil
}); err != nil {
return nil
}
// validate location list
matrix := make([]map[string]interface{}, len(locations))
for i, location := range locations {
matrix[i] = map[string]interface{}{matrixKeyLocation: location.LocationId}
}
d.ConnectionManager.Cache.Set(locationCacheKey, matrix)
return matrix
}