-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcp.go
47 lines (36 loc) · 1.21 KB
/
gcp.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
package internal
import (
"context"
"fmt"
"golang.org/x/oauth2/google"
"google.golang.org/api/container/v1"
"google.golang.org/api/option"
)
func GetGoogleCloudClusters(ctx context.Context, project, location string) ([]*container.Cluster, error) {
client, err := google.DefaultClient(ctx, container.CloudPlatformScope)
if err != nil {
return nil, err
}
containerService, err := container.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
return nil, err
}
parent := fmt.Sprintf("projects/%s/locations/%s", project, location)
resp, err := containerService.Projects.Locations.Clusters.List(parent).Context(ctx).Do()
if err != nil {
return nil, err
}
return resp.Clusters, nil
}
func GetGoogleCloudCluster(ctx context.Context, project, location, cluster string) (*container.Cluster, error) {
client, err := google.DefaultClient(ctx, container.CloudPlatformScope)
if err != nil {
return nil, err
}
containerService, err := container.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
return nil, err
}
name := fmt.Sprintf("projects/%s/locations/%s/clusters/%s", project, location, cluster)
return containerService.Projects.Locations.Clusters.Get(name).Context(ctx).Do()
}