package ec2metadata

import (
	
	
	

	
	
	
)
A tokenProvider struct provides access to EC2Metadata client and atomic instance of a token, along with configuredTTL for it. tokenProvider also provides an atomic flag to disable the fetch token operation. The disabled member will use 0 as false, and 1 as true.
A ec2Token struct helps use of token in EC2 Metadata service ops
newTokenProvider provides a pointer to a tokenProvider instance
fetchTokenHandler fetches token for EC2Metadata service client by default.
short-circuits to insecure data flow if tokenProvider is disabled.
	if  := atomic.LoadUint32(&.disabled);  == 1 {
		return
	}

	if ,  := .token.Load().(ec2Token);  && !.IsExpired() {
		.HTTPRequest.Header.Set(tokenHeader, .token)
		return
	}

	,  := .client.getToken(.Context(), .configuredTTL)

	if  != nil {
change the disabled flag on token provider to true, when error is request timeout error.
		if ,  := .(awserr.RequestFailure);  {
			switch .StatusCode() {
			case http.StatusForbidden, http.StatusNotFound, http.StatusMethodNotAllowed:
				atomic.StoreUint32(&.disabled, 1)
			case http.StatusBadRequest:
				.Error = 
			}
Check if request timed out while waiting for response
			if ,  := .OrigErr().(awserr.Error);  {
				if .Code() == request.ErrCodeRequestError {
					atomic.StoreUint32(&.disabled, 1)
				}
			}
		}
		return
	}

	 := ec2Token{
		token: .Token,
	}
	.SetExpiration(time.Now().Add(.TTL), ttlExpirationWindow)
	.token.Store()
Inject token header to the request.
	if ,  := .token.Load().(ec2Token);  {
		.HTTPRequest.Header.Set(tokenHeader, .token)
	}
}
enableTokenProviderHandler enables the token provider
If the error code status is 401, we enable the token provider
	if ,  := .Error.(awserr.RequestFailure);  &&  != nil &&
		.StatusCode() == http.StatusUnauthorized {
		atomic.StoreUint32(&.disabled, 0)
	}