Skip to content

Commit

Permalink
EC2 IMDS Clear Token on 401
Browse files Browse the repository at this point in the history
  • Loading branch information
skmcgrail committed Oct 2, 2020
1 parent a538034 commit 7b28367
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ec2imds/token_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ func (t *tokenProvider) HandleDeserialize(
return out, metadata, fmt.Errorf("expect HTTP transport, got %T", out.RawResponse)
}

if resp.StatusCode == 401 { // unauthorized
if resp.StatusCode == http.StatusUnauthorized { // unauthorized
err = &retryableError{Err: err}
t.clearToken()
t.enable()
}

Expand Down Expand Up @@ -230,3 +231,10 @@ func (t *tokenProvider) disable() {
func (t *tokenProvider) enable() {
atomic.StoreUint32(&t.disabled, 0)
}

// clearToken clears tje current token present
func (t *tokenProvider) clearToken() {
t.tokenMux.Lock()
defer t.tokenMux.Unlock()
t.token = nil
}

0 comments on commit 7b28367

Please sign in to comment.