forked from aws/aws-sdk-go-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
static_provider.go
52 lines (43 loc) · 1.47 KB
/
static_provider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package aws
import (
"github.com/aws/aws-sdk-go-v2/aws/awserr"
)
// StaticCredentialsProviderName provides a name of Static provider
const StaticCredentialsProviderName = "StaticCredentialsProvider"
var (
// ErrStaticCredentialsEmpty is emitted when static credentials are empty.
ErrStaticCredentialsEmpty = awserr.New("EmptyStaticCreds", "static credentials are empty", nil)
)
// A StaticCredentialsProvider is a set of credentials which are set programmatically,
// and will never expire.
type StaticCredentialsProvider struct {
Value Credentials
}
// NewStaticCredentialsProvider return a StaticCredentialsProvider initialized with the AWS credentials
// passed in.
func NewStaticCredentialsProvider(key, secret, session string) StaticCredentialsProvider {
return StaticCredentialsProvider{
Value: Credentials{
AccessKeyID: key,
SecretAccessKey: secret,
SessionToken: session,
},
}
}
// Retrieve returns the credentials or error if the credentials are invalid.
func (s StaticCredentialsProvider) Retrieve() (Credentials, error) {
v := s.Value
if v.AccessKeyID == "" || v.SecretAccessKey == "" {
return Credentials{Source: StaticCredentialsProviderName}, ErrStaticCredentialsEmpty
}
if len(v.Source) == 0 {
v.Source = StaticCredentialsProviderName
}
return v, nil
}
// IsExpired returns if the credentials are expired.
//
// For StaticCredentialsProvider, the credentials never expired.
func (s StaticCredentialsProvider) IsExpired() bool {
return false
}