This repository has been archived by the owner on Jun 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathcloudRunDir.go
62 lines (54 loc) · 1.55 KB
/
cloudRunDir.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
56
57
58
59
60
61
62
package gcp
import (
"context"
"fmt"
"net/http"
"github.com/puppetlabs/wash/plugin"
"google.golang.org/api/option"
"google.golang.org/api/run/v1"
)
type cloudRunProjectAPIService struct {
*run.APIService
projectID string
// We need to pass this around to access cloud function logs
client *http.Client
}
type cloudRunDir struct {
plugin.EntryBase
apiService cloudRunProjectAPIService
}
func newCloudRunDir(ctx context.Context, client *http.Client, projID string) (*cloudRunDir, error) {
svc, err := run.NewService(context.Background(), option.WithHTTPClient(client))
if err != nil {
return nil, err
}
cr := &cloudRunDir{
EntryBase: plugin.NewEntry("cloud_run"),
apiService: cloudRunProjectAPIService{APIService: svc, projectID: projID, client: client},
}
if _, err := plugin.List(ctx, cr); err != nil {
cr.MarkInaccessible(ctx, err)
}
return cr, nil
}
func (cr *cloudRunDir) List(ctx context.Context) ([]plugin.Entry, error) {
var entries []plugin.Entry
servicesReq := cr.apiService.Projects.Locations.Services.List(fmt.Sprintf("projects/%s/locations/-", cr.apiService.projectID))
resp, err := servicesReq.Context(ctx).Do()
if err != nil {
return nil, err
}
for _, service := range resp.Items {
entries = append(entries, newCloudRunService(service, cr.apiService))
}
return entries, err
}
func (cr *cloudRunDir) Schema() *plugin.EntrySchema {
return plugin.NewEntrySchema(cr, "cloud_run").
IsSingleton()
}
func (cr *cloudRunDir) ChildSchemas() []*plugin.EntrySchema {
return []*plugin.EntrySchema{
(&cloudRunService{}).Schema(),
}
}