forked from Versent/saml2aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.go
104 lines (78 loc) · 2.81 KB
/
input.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package saml2aws
import (
"fmt"
"sort"
"github.com/pkg/errors"
"github.com/versent/saml2aws/pkg/cfg"
"github.com/versent/saml2aws/pkg/creds"
"github.com/versent/saml2aws/pkg/prompter"
)
// PromptForConfigurationDetails prompt the user to present their hostname, username and mfa
func PromptForConfigurationDetails(idpAccount *cfg.IDPAccount) error {
providers := MFAsByProvider.Names()
var err error
idpAccount.Provider, err = prompter.ChooseWithDefault("Please choose a provider:", idpAccount.Provider, providers)
if err != nil {
return errors.Wrap(err, "error selecting provider file")
}
mfas := MFAsByProvider.Mfas(idpAccount.Provider)
// only prompt for MFA if there is more than one option
if len(mfas) > 1 {
idpAccount.MFA, err = prompter.ChooseWithDefault("Please choose an MFA", idpAccount.MFA, mfas)
if err != nil {
return errors.Wrap(err, "error selecting provider file")
}
} else {
idpAccount.MFA = mfas[0]
}
idpAccount.Profile = prompter.String("AWS Profile", idpAccount.Profile)
fmt.Println("")
idpAccount.URL = prompter.String("URL", idpAccount.URL)
idpAccount.Username = prompter.String("Username", idpAccount.Username)
fmt.Println("")
if idpAccount.Provider == "OneLogin" {
idpAccount.AppID = prompter.String("App ID", idpAccount.AppID)
fmt.Println("")
idpAccount.Subdomain = prompter.String("Subdomain", idpAccount.Subdomain)
fmt.Println("")
}
return nil
}
// PromptForLoginDetails prompt the user to present their username, password
func PromptForLoginDetails(loginDetails *creds.LoginDetails, provider string) error {
fmt.Println("To use saved password just hit enter.")
loginDetails.Username = prompter.String("Username", loginDetails.Username)
if enteredPassword := prompter.Password("Password"); enteredPassword != "" {
loginDetails.Password = enteredPassword
}
fmt.Println("")
if provider == "OneLogin" {
if enteredClientID := prompter.Password("Client ID"); enteredClientID != "" {
loginDetails.ClientID = enteredClientID
}
fmt.Println("")
if enteredCientSecret := prompter.Password("Client Secret"); enteredCientSecret != "" {
loginDetails.ClientSecret = enteredCientSecret
}
fmt.Println("")
}
return nil
}
// PromptForAWSRoleSelection present a list of roles to the user for selection
func PromptForAWSRoleSelection(accounts []*AWSAccount) (*AWSRole, error) {
roles := map[string]*AWSRole{}
var roleOptions []string
for _, account := range accounts {
for _, role := range account.Roles {
name := fmt.Sprintf("%s / %s", role.Name, account.Name)
roles[name] = role
roleOptions = append(roleOptions, name)
}
}
sort.Strings(roleOptions)
selectedRole, err := prompter.ChooseWithDefault("Please choose the role", "", roleOptions)
if err != nil {
return nil, errors.Wrap(err, "Role selection failed")
}
return roles[selectedRole], nil
}