/
kms_multi_location.go
54 lines (43 loc) · 1.36 KB
/
kms_multi_location.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
package gcp
import (
"context"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
)
// var pluginQueryData *plugin.QueryData
// func init() {
// pluginQueryData = &plugin.QueryData{
// ConnectionManager: connection.NewManager(),
// }
// }
const matrixKeyLocation = "location"
// BuildregionList :: return a list of matrix items, one per region specified
func BuildLocationList(ctx context.Context, d *plugin.QueryData) []map[string]interface{} {
// have we already created and cached the locations?
locationCacheKey := "KMSLocation"
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 := KMSService(ctx, d)
if err != nil {
return nil
}
// Get project details
projectData, err := activeProject(ctx, d)
if err != nil {
return nil
}
project := projectData.Project
resp, err := service.Projects.Locations.List("projects/" + project).Do()
if err != nil {
return nil
}
// validate location list
matrix := make([]map[string]interface{}, len(resp.Locations))
for i, location := range resp.Locations {
matrix[i] = map[string]interface{}{matrixKeyLocation: location.LocationId}
}
d.ConnectionManager.Cache.Set(locationCacheKey, matrix)
return matrix
}