aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/gce
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2021-12-28 17:47:42 +0100
committerGitHub <noreply@github.com>2021-12-28 17:47:42 +0100
commit76c8cf0609d485f3fc14508002a4fa5c2e68bacf (patch)
tree1be94779ba94ce2bc0aec5c5ab9ce9fab245a157 /pkg/gce
parent6b3c5e64ee67d74980d229cd1332aa038d4ce936 (diff)
syzkaller: add the gcp secret manager dependency (#2949)
Adds the function to read GCP Secrets.
Diffstat (limited to 'pkg/gce')
-rw-r--r--pkg/gce/gcp_secret.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/pkg/gce/gcp_secret.go b/pkg/gce/gcp_secret.go
new file mode 100644
index 000000000..c5f84f3bc
--- /dev/null
+++ b/pkg/gce/gcp_secret.go
@@ -0,0 +1,38 @@
+// Copyright 2021 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+package gce
+
+import (
+ "context"
+
+ secretmanager "cloud.google.com/go/secretmanager/apiv1"
+ secretmanagerpb "google.golang.org/genproto/googleapis/cloud/secretmanager/v1"
+)
+
+// GcpSecret returns the GCP Secret Manager blob as a []byte data.
+func GcpSecret(name string) ([]byte, error) {
+ // name := "projects/my-project/secrets/my-secret/versions/5"
+ // name := "projects/my-project/secrets/my-secret/versions/latest"
+
+ // Create the client.
+ ctx := context.Background()
+ client, err := secretmanager.NewClient(ctx)
+ if err != nil {
+ return nil, err
+ }
+ defer client.Close()
+
+ // Build the request.
+ req := &secretmanagerpb.AccessSecretVersionRequest{
+ Name: name,
+ }
+
+ // Call the API.
+ result, err := client.AccessSecretVersion(ctx, req)
+ if err != nil {
+ return nil, err
+ }
+
+ return result.Payload.Data, nil
+}