try to create credentials file if using env to authenticate
parent
0f5a2ca4a4
commit
4f4124c69d
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue