forked from remind101/assume-role
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
44 lines (36 loc) · 903 Bytes
/
Copy pathconfig.go
File metadata and controls
44 lines (36 loc) · 903 Bytes
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 (
"bufio"
"fmt"
"io/ioutil"
"os"
"strings"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)
type roleConfig struct {
Role string `yaml:"role"`
MFA string `yaml:"mfa"`
}
type config map[string]roleConfig
var configFilePath = fmt.Sprintf("%s/.aws/roles", os.Getenv("HOME"))
// readTokenCode reads the MFA token from Stdin.
func readTokenCode() (string, error) {
r := bufio.NewReader(os.Stdin)
fmt.Fprintf(os.Stderr, "MFA code: ")
text, err := r.ReadString('\n')
if err != nil {
return "", err
}
return strings.TrimSpace(text), nil
}
// loadConfig loads the ~/.aws/roles file.
func loadConfig() (config, error) {
log.WithField("configFilePath", configFilePath).Debug("Reading config...")
raw, err := ioutil.ReadFile(configFilePath)
if err != nil {
return nil, err
}
roleConfig := make(config)
return roleConfig, yaml.Unmarshal(raw, &roleConfig)
}