From 990173083ef2d6dbf748a234c55d66b3321a0f52 Mon Sep 17 00:00:00 2001 From: Patrick Jones Date: Mon, 25 Jan 2021 12:41:29 -0800 Subject: [PATCH] Changing some nits. Change-Id: I74140daa4acf876388f4f8ef83c475c1ae7d1865 --- .../externalaccount/basecredentials.go | 23 ++++++++----------- .../internal/externalaccount/impersonate.go | 2 +- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/google/internal/externalaccount/basecredentials.go b/google/internal/externalaccount/basecredentials.go index 6bca094..07efa33 100644 --- a/google/internal/externalaccount/basecredentials.go +++ b/google/internal/externalaccount/basecredentials.go @@ -31,25 +31,20 @@ type Config struct { // TokenSource Returns an external account TokenSource struct. This is to be called by package google to construct a google.Credentials. func (c *Config) TokenSource(ctx context.Context) oauth2.TokenSource { - if c.ServiceAccountImpersonationURL == "" { - ts := tokenSource{ - ctx: ctx, - conf: c, - } - return oauth2.ReuseTokenSource(nil, ts) - } - imp := impersonateTokenSource{ - ctx: ctx, - url: c.ServiceAccountImpersonationURL, - scopes: c.Scopes, - } ts := tokenSource{ ctx: ctx, conf: c, } - ts.conf.ServiceAccountImpersonationURL = "" + if c.ServiceAccountImpersonationURL == "" { + return oauth2.ReuseTokenSource(nil, ts) + } ts.conf.Scopes = []string{"https://www.googleapis.com/auth/cloud-platform"} - imp.ts = oauth2.ReuseTokenSource(nil, ts) + imp := impersonateTokenSource{ + ctx: ctx, + url: c.ServiceAccountImpersonationURL, + scopes: c.Scopes, + ts: oauth2.ReuseTokenSource(nil, ts), + } return oauth2.ReuseTokenSource(nil, imp) } diff --git a/google/internal/externalaccount/impersonate.go b/google/internal/externalaccount/impersonate.go index f794a3a..d8697f9 100644 --- a/google/internal/externalaccount/impersonate.go +++ b/google/internal/externalaccount/impersonate.go @@ -36,7 +36,7 @@ type impersonateTokenSource struct { scopes []string } -// impersonate performs the exchange to get a temporary service account +// Token performs the exchange to get a temporary service account func (its impersonateTokenSource) Token() (*oauth2.Token, error) { reqBody := generateAccessTokenReq{ Lifetime: "3600s",