-
Notifications
You must be signed in to change notification settings - Fork 0
/
keys.go
45 lines (39 loc) · 1.02 KB
/
keys.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
package commands
import (
"fmt"
"github.com/alecthomas/kong"
"github.com/pkg/errors"
"github.com/tb0hdan/aws-k8s/pkg/auth"
)
type KeysCmd struct {
Print bool `cmd:"print" help:"Print AWS values"`
}
func (p *KeysCmd) Run(ctx *CLIContext) error {
var (
AccessKeyId string
SecretAccessKey string
SessionToken string
)
if !p.Print {
return nil
}
absolutePath := kong.ExpandPath("~/.aws/aws-k8s.json")
credentials := auth.NewCredentials(absolutePath)
if credentials.Valid() {
validCredentials, err := credentials.Load()
if err != nil {
return errors.Wrapf(err, "Could not load credentials")
}
AccessKeyId = validCredentials.AccessKeyId
SecretAccessKey = validCredentials.SecretAccessKey
SessionToken = validCredentials.SessionToken
} else {
return fmt.Errorf("credentials invalid, please run `aws-k8s refresh --token=123456`")
}
fmt.Printf("export AWS_ACCESS_KEY_ID=%s; export AWS_SECRET_ACCESS_KEY=%s; export AWS_SESSION_TOKEN=%s",
AccessKeyId,
SecretAccessKey,
SessionToken,
)
return nil
}