-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcredentials.go
47 lines (39 loc) · 1.02 KB
/
credentials.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
package main
import (
"bufio"
"encoding/json"
"fmt"
"io"
"log"
"os"
"github.com/mitchellh/mapstructure"
)
type credentials struct {
AccessKeyId string
SecretAccessKey string
SessionToken string
Expiration string
}
func getCredentialsFromStdIn() credentials {
var stdin []byte
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
stdin = append(stdin, scanner.Bytes()...)
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
m := make(map[string]interface{})
err := json.Unmarshal(stdin, &m)
handleErr(err)
var credentials credentials
err = mapstructure.Decode(m["Credentials"], &credentials)
handleErr(err)
return credentials
}
func appendCredentials(credentials credentials, profile string, buffer io.Writer) {
fmt.Fprintf(buffer, "[%s]\n", profile)
fmt.Fprintf(buffer, "aws_access_key_id = %s\n", credentials.AccessKeyId)
fmt.Fprintf(buffer, "aws_secret_access_key = %s\n", credentials.SecretAccessKey)
fmt.Fprintf(buffer, "aws_session_token = %s\n", credentials.SessionToken)
}