Changing some nits.

Change-Id: I74140daa4acf876388f4f8ef83c475c1ae7d1865
This commit is contained in:
Patrick Jones 2021-01-25 12:41:29 -08:00
parent 8857346214
commit 990173083e
2 changed files with 10 additions and 15 deletions

View File

@ -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. // 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 { func (c *Config) TokenSource(ctx context.Context) oauth2.TokenSource {
if c.ServiceAccountImpersonationURL == "" {
ts := tokenSource{ ts := tokenSource{
ctx: ctx, ctx: ctx,
conf: c, conf: c,
} }
if c.ServiceAccountImpersonationURL == "" {
return oauth2.ReuseTokenSource(nil, ts) return oauth2.ReuseTokenSource(nil, ts)
} }
ts.conf.Scopes = []string{"https://www.googleapis.com/auth/cloud-platform"}
imp := impersonateTokenSource{ imp := impersonateTokenSource{
ctx: ctx, ctx: ctx,
url: c.ServiceAccountImpersonationURL, url: c.ServiceAccountImpersonationURL,
scopes: c.Scopes, scopes: c.Scopes,
ts: oauth2.ReuseTokenSource(nil, ts),
} }
ts := tokenSource{
ctx: ctx,
conf: c,
}
ts.conf.ServiceAccountImpersonationURL = ""
ts.conf.Scopes = []string{"https://www.googleapis.com/auth/cloud-platform"}
imp.ts = oauth2.ReuseTokenSource(nil, ts)
return oauth2.ReuseTokenSource(nil, imp) return oauth2.ReuseTokenSource(nil, imp)
} }

View File

@ -36,7 +36,7 @@ type impersonateTokenSource struct {
scopes []string 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) { func (its impersonateTokenSource) Token() (*oauth2.Token, error) {
reqBody := generateAccessTokenReq{ reqBody := generateAccessTokenReq{
Lifetime: "3600s", Lifetime: "3600s",