ProviderName provides a name of EC2Role provider
const ProviderName = "EC2RoleProvider"
GetMetadataAPIClient provides the interface for an EC2 IMDS API client for the GetMetadata operation.
type GetMetadataAPIClient interface { GetMetadata(context.Context, *imds.GetMetadataInput, ...func(*imds.Options)) (*imds.GetMetadataOutput, error) }
Options is a list of user settable options for setting the behavior of the Provider.
type Options struct { // The API client that will be used by the provider to make GetMetadata API // calls to EC2 IMDS. // // If nil, the provider will default to the EC2 IMDS client. Client GetMetadataAPIClient }
A Provider retrieves credentials from the EC2 service, and keeps track if those credentials are expired.
The New function must be used to create the with a custom EC2 IMDS client.
p := &ec2rolecreds.New(func(o *ec2rolecreds.Options{ o.Client = imds.New(imds.Options{/* custom options */}) })
type Provider struct {
// contains filtered or unexported fields
}
func New(optFns ...func(*Options)) *Provider
New returns an initialized Provider value configured to retrieve credentials from EC2 Instance Metadata service.
func (p *Provider) AdjustExpiresBy(creds aws.Credentials, dur time.Duration) ( aws.Credentials, error, )
AdjustExpiresBy will adds the passed in duration to the passed in credential's Expires time, unless the time until Expires is less than 15 minutes. Returns the credentials, even if not updated.
func (p *Provider) HandleFailToRefresh(ctx context.Context, prevCreds aws.Credentials, err error) ( aws.Credentials, error, )
HandleFailToRefresh will extend the credentials Expires time if it it is expired. If the credentials will not expire within the minimum time, they will be returned.
If the credentials cannot expire, the original error will be returned.
func (p *Provider) Retrieve(ctx context.Context) (aws.Credentials, error)
Retrieve retrieves credentials from the EC2 service. Error will be returned if the request fails, or unable to extract the desired credentials.