-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
80 lines (70 loc) · 2.76 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"flag"
"fmt"
"os"
)
var (
profile string
allProfiles bool
forceRefresh bool
configure bool
mode string
noVerifySSL bool
noPrompt bool
)
func init() {
const (
profileDefaultValue = ""
profileUsage = "The name of the profile to log in with (or configure)"
allProfilesDefaultValue = false
allProfilesUsage = "Run for all configured profiles"
forceRefreshDefaultValue = false
forceRefreshUsage = "Force a credential refresh, even if they are still valid"
configureDefaultValue = false
configureUsage = "Configure the profile"
modeDefaultValue = "cli"
modeUsage = "'cli' to hide the login page and perform the login through the CLI (default behavior), 'gui' to perform the login through the Azure GUI (more reliable but only works on GUI operating system), 'debug' to show the login page but perform the login through the CLI (useful to debug issues with the CLI login)"
noVerifySSLDefaultValue = false
noVerifySSLUsage = "Disable SSL Peer Verification for connections to AWS (no effect if behind proxy)"
noPromptDefaultValue = false
noPromptUsage = "Do not prompt for input and accept the default choice"
)
flag.StringVar(&profile, "profile", profileDefaultValue, profileUsage)
flag.StringVar(&profile, "p", profileDefaultValue, profileUsage+" (shorthand)")
flag.BoolVar(&allProfiles, "all-profiles", allProfilesDefaultValue, allProfilesUsage)
flag.BoolVar(&allProfiles, "a", allProfilesDefaultValue, allProfilesUsage+" (shorthand)")
flag.BoolVar(&forceRefresh, "force-refresh", forceRefreshDefaultValue, forceRefreshUsage)
flag.BoolVar(&forceRefresh, "f", forceRefreshDefaultValue, forceRefreshUsage+" (shorthand)")
flag.StringVar(&mode, "mode", modeDefaultValue, modeUsage)
flag.StringVar(&mode, "m", modeDefaultValue, modeUsage+" (shorthand)")
flag.BoolVar(&configure, "configure", configureDefaultValue, configureUsage)
flag.BoolVar(&configure, "c", configureDefaultValue, configureUsage+" (shorthand)")
flag.BoolVar(&noVerifySSL, "no-verify-ssl", noVerifySSLDefaultValue, noVerifySSLUsage)
flag.BoolVar(&noPrompt, "no-prompt", noPromptDefaultValue, noPromptUsage)
flag.Parse()
if flag.NArg() > 0 {
fmt.Fprintf(os.Stderr, "Error: Unused command line arguments detected.\n")
flag.Usage()
os.Exit(2)
}
}
func main() {
var profileName string
if profile != "" {
profileName = profile
} else if osAWSProfile := os.Getenv("AWS_PROFILE"); osAWSProfile != "" {
profileName = osAWSProfile
} else {
profileName = "default"
}
if configure {
configureProfile(profileName)
} else {
if allProfiles {
loginAll(forceRefresh, noVerifySSL, noPrompt)
} else {
login(profileName, noVerifySSL, noPrompt)
}
}
}