func main()

in security/wi-secrets/main.go [27:57]


func main() {

        // Get environment variables from Pod spec.
        projectID := os.Getenv("PROJECT_ID")
        secretId := os.Getenv("SECRET_ID")
        secretVersion := os.Getenv("SECRET_VERSION")

        // Create the Secret Manager client.
        ctx := context.Background()
        client, err := secretmanager.NewClient(ctx)
        if err != nil {
                log.Fatalf("failed to setup client: %v", err)
        }
        defer client.Close()

        // Create the request to access the secret.
        accessSecretReq := &secretmanagerpb.AccessSecretVersionRequest{
                Name: fmt.Sprintf("projects/%s/secrets/%s/versions/%s", projectID, secretId, secretVersion),
        }

        secret, err := client.AccessSecretVersion(ctx, accessSecretReq)
        if err != nil {
                log.Fatalf("failed to access secret: %v", err)
        }

        // Print the secret payload.
        //
        // WARNING: Do not print the secret in a production environment - this
        // snippet is showing how to access the secret material.
        log.Printf("Welcome to the key store, here's your key:\nKey: %s", secret.Payload.Data)
}