forked from 99designs/aws-vault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add.go
44 lines (36 loc) · 1.09 KB
/
add.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
package main
import (
"os"
"github.com/99designs/aws-vault/keyring"
"github.com/aws/aws-sdk-go/aws/credentials"
)
type AddCommandInput struct {
Profile string
Keyring keyring.Keyring
FromEnv bool
}
func AddCommand(ui Ui, input AddCommandInput) {
var accessKeyId, secretKey string
if input.FromEnv {
if accessKeyId = os.Getenv("AWS_ACCESS_KEY_ID"); accessKeyId == "" {
ui.Error.Fatal("Missing value for AWS_ACCESS_KEY_ID")
}
if secretKey = os.Getenv("AWS_SECRET_ACCESS_KEY"); secretKey == "" {
ui.Error.Fatal("Missing value for AWS_SECRET_ACCESS_KEY")
}
} else {
var err error
if accessKeyId, err = prompt("Enter Access Key ID: "); err != nil {
ui.Error.Fatal(err)
}
if secretKey, err = promptPassword("Enter Secret Access Key: "); err != nil {
ui.Error.Fatal(err)
}
}
creds := credentials.Value{AccessKeyID: accessKeyId, SecretAccessKey: secretKey}
provider := &KeyringProvider{Keyring: input.Keyring, Profile: input.Profile}
if err := provider.Store(creds); err != nil {
ui.Error.Fatal(err)
}
ui.Printf("Added credentials to profile %q in vault", input.Profile)
}