docs(iam-samples): extract PrivateKeyData from ServiceAccountkey
For more context: b/216208252
Fix: Extracting the PrivateKeyData which contains the json key credential in base64 format.
@@ -17,6 +17,7 @@ package snippets
// [START iam_create_key]
import (
"context"
+ // "encoding/base64"
"fmt"
"io"
@@ -37,7 +38,12 @@ func createKey(w io.Writer, serviceAccountEmail string) (*iam.ServiceAccountKey,
if err != nil {
return nil, fmt.Errorf("Projects.ServiceAccounts.Keys.Create: %v", err)
}
- fmt.Fprintf(w, "Created key: %v", key.Name)
+ // The PrivateKeyData field contains the base64-encoded service account key
+ // in JSON format.
+ // TODO(Developer): Save the below key (jsonKeyFile) to a secure location.
+ // You cannot download it later.
+ // jsonKeyFile, _ := base64.StdEncoding.DecodeString(key.PrivateKeyData)
+ fmt.Fprintf(w, "Key created successfully")
return key, nil
}
