github.com/aavshr/aws-sdk-go@v1.41.3/aws/credentials/static_provider.go (about)

     1  package credentials
     2  
     3  import (
     4  	"github.com/aavshr/aws-sdk-go/aws/awserr"
     5  )
     6  
     7  // StaticProviderName provides a name of Static provider
     8  const StaticProviderName = "StaticProvider"
     9  
    10  var (
    11  	// ErrStaticCredentialsEmpty is emitted when static credentials are empty.
    12  	ErrStaticCredentialsEmpty = awserr.New("EmptyStaticCreds", "static credentials are empty", nil)
    13  )
    14  
    15  // A StaticProvider is a set of credentials which are set programmatically,
    16  // and will never expire.
    17  type StaticProvider struct {
    18  	Value
    19  }
    20  
    21  // NewStaticCredentials returns a pointer to a new Credentials object
    22  // wrapping a static credentials value provider. Token is only required
    23  // for temporary security credentials retrieved via STS, otherwise an empty
    24  // string can be passed for this parameter.
    25  func NewStaticCredentials(id, secret, token string) *Credentials {
    26  	return NewCredentials(&StaticProvider{Value: Value{
    27  		AccessKeyID:     id,
    28  		SecretAccessKey: secret,
    29  		SessionToken:    token,
    30  	}})
    31  }
    32  
    33  // NewStaticCredentialsFromCreds returns a pointer to a new Credentials object
    34  // wrapping the static credentials value provide. Same as NewStaticCredentials
    35  // but takes the creds Value instead of individual fields
    36  func NewStaticCredentialsFromCreds(creds Value) *Credentials {
    37  	return NewCredentials(&StaticProvider{Value: creds})
    38  }
    39  
    40  // Retrieve returns the credentials or error if the credentials are invalid.
    41  func (s *StaticProvider) Retrieve() (Value, error) {
    42  	if s.AccessKeyID == "" || s.SecretAccessKey == "" {
    43  		return Value{ProviderName: StaticProviderName}, ErrStaticCredentialsEmpty
    44  	}
    45  
    46  	if len(s.Value.ProviderName) == 0 {
    47  		s.Value.ProviderName = StaticProviderName
    48  	}
    49  	return s.Value, nil
    50  }
    51  
    52  // IsExpired returns if the credentials are expired.
    53  //
    54  // For StaticProvider, the credentials never expired.
    55  func (s *StaticProvider) IsExpired() bool {
    56  	return false
    57  }