Skip to content

Commit

Permalink
Added ability to use access tokens for secret
Browse files Browse the repository at this point in the history
Signed-off-by: Brad Wadsworth <brad.wadsworth@mavenwave.com>
  • Loading branch information
Brad Wadsworth committed Oct 12, 2022
1 parent cf8ad7d commit e99137b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/clients/gke/gke.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ var DefaultScopes = []string{
func WrapRESTConfig(ctx context.Context, rc *rest.Config, credentials []byte, scopes ...string) error {
var ts oauth2.TokenSource
if credentials != nil {
// CredentialsFromJSON creates a TokenSource that handles token caching.
if isJSON(credentials) {
// If credentials are in a JSON format, extract the credential from the JSON
// CredentialsFromJSON creates a TokenSource that handles token caching.
creds, err := google.CredentialsFromJSON(ctx, credentials, scopes...)
if err != nil {
return errors.Wrap(err, "cannot load Google Application Credentials from JSON")
}
ts = creds.TokenSource
} else {
// if the credential not in a JSON format, treat the credential as an access token
t := oauth2.Token{
AccessToken: string(credentials),
}
Expand Down

0 comments on commit e99137b

Please sign in to comment.