Changes requested by @codyoss

This commit is contained in:
Ryan Kohler
2022-04-27 12:20:25 -07:00
parent d19f296b59
commit b777222fce

View File

@@ -226,6 +226,7 @@ func (cs executableCredentialSource) getTokenFromOutputFile() (string, error, bo
// No OutputFile found. Hasn't been created yet, so skip it. // No OutputFile found. Hasn't been created yet, so skip it.
return "", nil, false return "", nil, false
} }
defer file.Close()
data, err := ioutil.ReadAll(io.LimitReader(file, 1<<20)) data, err := ioutil.ReadAll(io.LimitReader(file, 1<<20))
if err != nil || len(data) == 0 { if err != nil || len(data) == 0 {
@@ -234,12 +235,7 @@ func (cs executableCredentialSource) getTokenFromOutputFile() (string, error, bo
} }
token, err := parseSubjectTokenFromSource(data, outputFileSource) token, err := parseSubjectTokenFromSource(data, outputFileSource)
if err != nil {
if err == nil {
// Token parsing succeeded. Use found token.
return token, nil, true
}
if _, ok := err.(nonCacheableError); ok { if _, ok := err.(nonCacheableError); ok {
// If the cached token is expired we need a new token, // If the cached token is expired we need a new token,
// and if the cache contains a failure, we need to try again. // and if the cache contains a failure, we need to try again.
@@ -249,6 +245,9 @@ func (cs executableCredentialSource) getTokenFromOutputFile() (string, error, bo
// There was an error in the cached token, and the developer should be aware of it. // There was an error in the cached token, and the developer should be aware of it.
return "", err, true return "", err, true
} }
// Token parsing succeeded. Use found token.
return token, nil, true
}
func (cs executableCredentialSource) getEnvironment() []string { func (cs executableCredentialSource) getEnvironment() []string {
result := baseEnv() result := baseEnv()