-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (45 loc) · 1.82 KB
/
main.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
48
49
50
51
52
53
54
package main
import (
"flag"
"fmt"
"github.com/joshbrgs/aws-mfa/aws"
"github.com/joshbrgs/aws-mfa/color"
"github.com/joshbrgs/aws-mfa/utils"
)
// Option for flag arguments : --verbose, --kubeConfig, --help
func main() {
// Flags
verboseFL := flag.Bool("verbose", false, "a bool that turns on output")
updateFL := flag.Bool("kubeConfig", false, "a bool to activate updating your local kube config with your session keys")
defaultProfileFL := flag.String("defaultProfile", "default", "declare the specific profile that holds your keys for your aws account, default value is --profile default")
mfaProfileFL := flag.String("mfaProfile", "mfa", "declare the specific profile you want your mfa credentials and keys saved to")
flag.Parse()
// Get the user's arn
var arn string = utils.GetARN(*defaultProfileFL)
// check if they have mfa profile, if not create it
var live bool = aws.MfaProfileCheck(*mfaProfileFL)
// If the session token is still live skip MFA
if live {
updateKube(*updateFL, *verboseFL, *mfaProfileFL)
return
}
var code string = retrieveMFA()
// set results of the mfa as cred variables under mfa profile
utils.ConfigureSession(arn, code, *verboseFL, *defaultProfileFL, *mfaProfileFL)
fmt.Println(color.Cyan + "Your Session token is set ✔" + color.Reset)
updateKube(*updateFL, *verboseFL, *mfaProfileFL)
}
/***************************** Helper Functions *********************************/
func retrieveMFA() (code string) {
// ask for the mfa code if one is not in args
fmt.Println(color.Purple + "What is your mfa code?:" + color.Reset)
fmt.Println()
fmt.Scanln(&code)
return code
}
func updateKube(updateFL bool, verboseFL bool, mfaProfile string) {
// Update kubernetes config if flagged
if updateFL {
aws.KubeConfig(verboseFL, mfaProfile)
}
}