-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (35 loc) · 980 Bytes
/
main.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
package main
import (
"cloud.google.com/go/storage"
"context"
"fmt"
"github.com/jsiebens/tailscale-gcp-helper/pkg/tsgcp"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
"log"
)
func main() {
projectID := "YOUR_PROJECT_ID"
projectNumber := "YOUR_PROJECT_NUMBER"
serviceAccount := "YOUR_SERVICE_ACCOUNT_TO_IMPERSONATE"
poolId := "YOUR_WORKLOAD_IDENTITY_POOL_ID"
providerId := "YOUR_WORKLOAD_IDENTITY_PROVIDER_ID"
ctx := context.Background()
credentials := tsgcp.Credentials(serviceAccount, tsgcp.DefaultAudience(projectNumber, poolId, providerId))
client, err := storage.NewClient(ctx, option.WithCredentials(credentials))
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
defer client.Close()
it := client.Buckets(ctx, projectID)
for {
battrs, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
log.Fatalf("Failed to list buckets: %v", err)
}
fmt.Printf("Bucket: %v\n", battrs.Name)
}
}