Source File
token_provider.go
Belonging Package
github.com/aws/aws-sdk-go/aws/ec2metadata
package ec2metadata
import (
)
type tokenProvider struct {
client *EC2Metadata
token atomic.Value
configuredTTL time.Duration
disabled uint32
}
type ec2Token struct {
token string
credentials.Expiry
}
func ( *EC2Metadata, time.Duration) *tokenProvider {
return &tokenProvider{client: , configuredTTL: }
}
func ( *tokenProvider) ( *request.Request) {
if := atomic.LoadUint32(&.disabled); == 1 {
return
}
if , := .token.Load().(ec2Token); && !.IsExpired() {
.HTTPRequest.Header.Set(tokenHeader, .token)
return
}
, := .client.getToken(.Context(), .configuredTTL)
if != nil {
if , := .(awserr.RequestFailure); {
switch .StatusCode() {
case http.StatusForbidden, http.StatusNotFound, http.StatusMethodNotAllowed:
atomic.StoreUint32(&.disabled, 1)
case http.StatusBadRequest:
.Error =
}
if , := .OrigErr().(awserr.Error); {
if .Code() == request.ErrCodeRequestError {
atomic.StoreUint32(&.disabled, 1)
}
}
}
return
}
:= ec2Token{
token: .Token,
}
.SetExpiration(time.Now().Add(.TTL), ttlExpirationWindow)
.token.Store()
if , := .token.Load().(ec2Token); {
.HTTPRequest.Header.Set(tokenHeader, .token)
}
}
if , := .Error.(awserr.RequestFailure); && != nil &&
.StatusCode() == http.StatusUnauthorized {
atomic.StoreUint32(&.disabled, 0)
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |