Struct: aws.CredentialsCache

import "../ibm-cos-sdk-go-v2/aws"

Overview

CredentialsCache provides caching and concurrency safe credentials retrieval via the provider’s retrieve method.

CredentialsCache will look for optional interfaces on the Provider to adjust how the credential cache handles credentials caching.

  • HandleFailRefreshCredentialsCacheStrategy - Allows provider to handle credential refresh failures. This could return an updated Credentials value, or attempt another means of retrieving credentials.

  • AdjustExpiresByCredentialsCacheStrategy - Allows provider to adjust how credentials Expires is modified. This could modify how the Credentials Expires is adjusted based on the CredentialsCache ExpiryWindow option. Such as providing a floor not to reduce the Expires below.

Implemented Interfaces

types.AnalyticsFilter, CredentialProviderSource, CredentialsProvider, v4.HTTPPresigner, s3.HTTPPresignerV4, types.MetricsFilter, s3.PresignPost, customizations.S3ExpressCredentialsProvider, arn.S3ObjectLambdaARN, types.SelectObjectContentEventStream

Method Summary collapse

Method Details

func (p *CredentialsCache) Invalidate()

Invalidate will invalidate the cached credentials. The next call to Retrieve will cause the provider’s Retrieve method to be called.



187
188
189
// File 'aws/credential_cache.go', line 187

func (p *CredentialsCache) Invalidate() { p.creds.Store((*Credentials)(nil)) }

func (p *CredentialsCache) IsCredentialsProvider(target CredentialsProvider) bool

IsCredentialsProvider returns whether credential provider wrapped by CredentialsCache matches the target provider type.



193
194
195
// File 'aws/credential_cache.go', line 193

func (p *CredentialsCache) IsCredentialsProvider(target CredentialsProvider) bool { return IsCredentialsProvider(p.provider, target) }

func (p *CredentialsCache) ProviderSources() []CredentialSource

ProviderSources returns a list of where the underlying credential provider has been sourced, if available. Returns empty if the provider doesn’t implement the interface



177
178
179
180
181
182
183
// File 'aws/credential_cache.go', line 177

func (p *CredentialsCache) ProviderSources() []CredentialSource { asSource, ok := p.provider.(CredentialProviderSource) if !ok { return []CredentialSource{} } return asSource.ProviderSources() }

func (p *CredentialsCache) Retrieve(ctx context.Context) (Credentials, error)

Retrieve returns the credentials. If the credentials have already been retrieved, and not expired the cached credentials will be returned. If the credentials have not been retrieved yet, or expired the provider’s Retrieve method will be called.

Returns and error if the provider’s retrieve method returns an error.



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// File 'aws/credential_cache.go', line 97

func (p *CredentialsCache) Retrieve(ctx context.Context) (Credentials, error) { if creds, ok := p.getCreds(); ok && !creds.Expired() { return creds, nil } resCh := p.sf.DoChan("", func() (interface{}, error) { return p.singleRetrieve(&suppressedContext{ctx}) }) select { case res := <-resCh: return res.Val.(Credentials), res.Err case <-ctx.Done(): return Credentials{}, &RequestCanceledError{Err: ctx.Err()} } }