github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/gce/gcp_secret.go (about) 1 // Copyright 2021 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package gce 5 6 import ( 7 "context" 8 9 secretmanager "cloud.google.com/go/secretmanager/apiv1" 10 "cloud.google.com/go/secretmanager/apiv1/secretmanagerpb" 11 ) 12 13 // GcpSecret returns the GCP Secret Manager blob as a []byte data. 14 func GcpSecret(name string) ([]byte, error) { 15 // name := "projects/my-project/secrets/my-secret/versions/5" 16 // name := "projects/my-project/secrets/my-secret/versions/latest" 17 18 // Create the client. 19 ctx := context.Background() 20 client, err := secretmanager.NewClient(ctx) 21 if err != nil { 22 return nil, err 23 } 24 defer client.Close() 25 26 // Build the request. 27 req := &secretmanagerpb.AccessSecretVersionRequest{ 28 Name: name, 29 } 30 31 // Call the API. 32 result, err := client.AccessSecretVersion(ctx, req) 33 if err != nil { 34 return nil, err 35 } 36 37 return result.Payload.Data, nil 38 }