]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/aws/aws-sdk-go/aws/credentials/static_provider.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / aws / aws-sdk-go / aws / credentials / static_provider.go
1 package credentials
2
3 import (
4 "github.com/aws/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.
23 func NewStaticCredentials(id, secret, token string) *Credentials {
24 return NewCredentials(&StaticProvider{Value: Value{
25 AccessKeyID: id,
26 SecretAccessKey: secret,
27 SessionToken: token,
28 }})
29 }
30
31 // NewStaticCredentialsFromCreds returns a pointer to a new Credentials object
32 // wrapping the static credentials value provide. Same as NewStaticCredentials
33 // but takes the creds Value instead of individual fields
34 func NewStaticCredentialsFromCreds(creds Value) *Credentials {
35 return NewCredentials(&StaticProvider{Value: creds})
36 }
37
38 // Retrieve returns the credentials or error if the credentials are invalid.
39 func (s *StaticProvider) Retrieve() (Value, error) {
40 if s.AccessKeyID == "" || s.SecretAccessKey == "" {
41 return Value{ProviderName: StaticProviderName}, ErrStaticCredentialsEmpty
42 }
43
44 if len(s.Value.ProviderName) == 0 {
45 s.Value.ProviderName = StaticProviderName
46 }
47 return s.Value, nil
48 }
49
50 // IsExpired returns if the credentials are expired.
51 //
52 // For StaticProvider, the credentials never expired.
53 func (s *StaticProvider) IsExpired() bool {
54 return false
55 }