-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.go
46 lines (39 loc) · 1.13 KB
/
auth.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
package main
import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/external"
"github.com/urfave/cli"
)
func awsConfigArgs(c *cli.Context) (string, string, string, string, string) {
return c.String("aws-access-key-id"),
c.String("aws-secret-access-key"),
c.String("aws-session-token"),
c.String("profile"),
c.String("aws-region")
}
func awsConfig(keyid, secretid, token, profile, region string) (aws.Config, error) {
configs := make([]external.Config, 0)
if keyid != "" && secretid != "" {
credentials := aws.Credentials{
AccessKeyID: keyid,
SecretAccessKey: secretid,
}
configs = append(configs, external.WithCredentialsValue(credentials))
} else if token != "" {
credentials := aws.Credentials{
SessionToken: token,
}
configs = append(configs, external.WithCredentialsValue(credentials))
}
if profile != "" {
configs = append(configs, external.WithSharedConfigProfile(profile))
}
if region != "" {
configs = append(configs, external.WithRegion(region))
}
cfg, err := external.LoadDefaultAWSConfig(configs...)
if err != nil {
return aws.Config{}, err
}
return cfg, err
}