Skip to content

Update gke-gcloud-auth-plugin to add a flag to return application default credentials and skip the gcloud command #264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions cmd/gke-gcloud-auth-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ type gcloudConfiguration struct {
X map[string]interface{} `json:"-"` // Rest of the fields should go here.
}

var (
useAdcPtr = pflag.Bool("use_application_default_credentials", false, "returns exec credential filled with application default credentials.")
)

func main() {
pflag.Parse()
verflag.PrintAndExitIfRequested()
Expand Down Expand Up @@ -77,11 +81,13 @@ func execCredential() (*clientauth.ExecCredential, error) {
}

func accessToken() (string, *meta.Time, error) {
token, expiry, err := gcloudAccessToken()
if err != nil {
return defaultAccessToken()
if !*useAdcPtr {
token, expiry, err := gcloudAccessToken()
if err == nil {
return token, expiry, nil
}
}
return token, expiry, nil
return defaultAccessToken()
}

func gcloudAccessToken() (string, *meta.Time, error) {
Expand Down