...
1 package credentials
2
3 import (
4 "context"
5
6 "github.com/aws/aws-sdk-go-v2/aws"
7 )
8
9 const (
10
11 StaticCredentialsName = "StaticCredentials"
12 )
13
14
15 type StaticCredentialsEmptyError struct{}
16
17 func (*StaticCredentialsEmptyError) Error() string {
18 return "static credentials are empty"
19 }
20
21
22
23 type StaticCredentialsProvider struct {
24 Value aws.Credentials
25 }
26
27
28
29 func NewStaticCredentialsProvider(key, secret, session string) StaticCredentialsProvider {
30 return StaticCredentialsProvider{
31 Value: aws.Credentials{
32 AccessKeyID: key,
33 SecretAccessKey: secret,
34 SessionToken: session,
35 },
36 }
37 }
38
39
40 func (s StaticCredentialsProvider) Retrieve(_ context.Context) (aws.Credentials, error) {
41 v := s.Value
42 if v.AccessKeyID == "" || v.SecretAccessKey == "" {
43 return aws.Credentials{
44 Source: StaticCredentialsName,
45 }, &StaticCredentialsEmptyError{}
46 }
47
48 if len(v.Source) == 0 {
49 v.Source = StaticCredentialsName
50 }
51
52 return v, nil
53 }
54
View as plain text