提交 4f4124c6 编写于 作者: S Sharif Elgamal

try to create credentials file if using env to authenticate

上级 0f5a2ca4
......@@ -19,6 +19,7 @@ package gcpauth
import (
"bytes"
"context"
"encoding/json"
"os"
"os/exec"
"strconv"
......@@ -63,6 +64,18 @@ func enableAddon(cfg *config.ClusterConfig) error {
exit.Message(reason.InternalCredsNotFound, "Could not find any GCP credentials. Either run `gcloud auth application-default login` or set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path of your credentials file.")
}
if creds.JSON == nil {
// credentials were found from the surrounding environment instead of from a file, we need to create a file from these creds.
token, err := creds.TokenSource.Token()
if err != nil {
// well that's no good, the creds aren't valid
exit.Message(reason.InternalCredsNotFound, "Could not find any GCP credentials. Either run `gcloud auth application-default login` or set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path of your credentials file.")
}
tokenCredsBuffer := new(bytes.Buffer)
json.NewEncoder(tokenCredsBuffer).Encode(token)
creds.JSON = tokenCredsBuffer.Bytes()
}
f := assets.NewMemoryAssetTarget(creds.JSON, credentialsPath, "0444")
err = r.Copy(f)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册