-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompts.go
182 lines (146 loc) · 4.28 KB
/
prompts.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package main
import (
"net"
"github.com/manifoldco/promptui"
)
func initPrompt() string {
prompt := promptui.Select{
Label: "Select Certificate Type",
Items: []string{"Ca", "Certificate"},
}
_, certType, _ := prompt.Run()
if certType == "Ca" {
return "ca"
} else if certType == "Certificate" {
return "cert"
}
return ""
}
func loadPaths(certType string) (string, string, string) {
if certType == "ca" {
destinationPrompt := promptui.Prompt{
Label: "Provide the output path where the certificates will be placed",
}
outputPath, _ := destinationPrompt.Run()
checkForPath(outputPath)
caNamePrompt := promptui.Prompt{
Label: "Provide a name for the CA (this will be the filename)",
}
caName, _ := caNamePrompt.Run()
return outputPath, caName, ""
} else if certType == "cert" {
destinationPrompt := promptui.Prompt{
Label: "Provide the output path where the certificates will be placed",
}
outputPath, _ := destinationPrompt.Run()
checkForPath(outputPath)
caPathPrompt := promptui.Prompt{
Label: "Provide the path to the ca cert that will be used to sign new certificates",
}
caPath, _ := caPathPrompt.Run()
checkForPath(caPath)
caKeyPathPrompt := promptui.Prompt{
Label: "Provide the path to the private CA key that will be used to sign new certificates",
}
caKeyPath, _ := caKeyPathPrompt.Run()
checkForPath(caKeyPath)
return outputPath, caPath, caKeyPath
}
return "", "", ""
}
func caPrompt() Cert {
orgPrompt := promptui.Prompt{
Label: "Provide CA Organization Name",
}
caOrg, _ := orgPrompt.Run()
coPrompt := promptui.Prompt{
Label: "Provide CA Country (2 letter)",
}
caCountry, _ := coPrompt.Run()
provincePrompt := promptui.Prompt{
Label: "Provide CA Province Name",
}
caProvince, _ := provincePrompt.Run()
localityPrompt := promptui.Prompt{
Label: "Provide CA Locality Name",
}
caLocality, _ := localityPrompt.Run()
addressPrompt := promptui.Prompt{
Label: "Provide CA Address",
}
caStreetAdress, _ := addressPrompt.Run()
zipPrompt := promptui.Prompt{
Label: "Provide CA Zip Code",
}
caPostalCode, _ := zipPrompt.Run()
caCertObj := Cert{
Organization: []string{caOrg},
Country: []string{caCountry},
Province: []string{caProvince},
Locality: []string{caLocality},
StreetAddress: []string{caStreetAdress},
PostalCode: []string{caPostalCode},
}
return caCertObj
}
func continueToCertPrompt() bool {
prompt := promptui.Select{
Label: "Continue creating a certificate from the CA just created?",
Items: []string{"Yes", "No"},
}
_, continueCert, _ := prompt.Run()
if continueCert == "Yes" {
return true
}
return false
}
func certPrompt() Cert {
orgPrompt := promptui.Prompt{
Label: "Provide Organization for Certificate",
}
sOrg, _ := orgPrompt.Run()
coPrompt := promptui.Prompt{
Label: "Provide Country for Certificate (2 letter)",
}
sCountry, _ := coPrompt.Run()
provincePrompt := promptui.Prompt{
Label: "Provide Province for Certificate",
}
sProvince, _ := provincePrompt.Run()
localityPrompt := promptui.Prompt{
Label: "Provide Locality Name for Certificate",
}
sLocality, _ := localityPrompt.Run()
addressPrompt := promptui.Prompt{
Label: "Provide Address for Certificate",
}
sStreetAdress, _ := addressPrompt.Run()
zipPrompt := promptui.Prompt{
Label: "Provide Zip Code for Certificate",
}
sPostalCode, _ := zipPrompt.Run()
commonNamePrompt := promptui.Prompt{
Label: "Provide common name (hostname, web address or IP) to associate with the Certificate",
}
sCommonName, _ := commonNamePrompt.Run()
sanIPPrompt := promptui.Prompt{
Label: "Provide IPv4 alternative address (i.e 127.0.0.1) to associate with the Certificate",
}
sAltSubjectIP, _ := sanIPPrompt.Run()
sanDNSPrompt := promptui.Prompt{
Label: "Provide alternative hostnames or web address (i.e localhost) to associate with the Certificate",
}
sAltSubjectName, _ := sanDNSPrompt.Run()
certObj := Cert{
Organization: []string{sOrg},
Country: []string{sCountry},
Province: []string{sProvince},
Locality: []string{sLocality},
StreetAddress: []string{sStreetAdress},
PostalCode: []string{sPostalCode},
CommonName: sCommonName,
IPAddresses: []net.IP{net.ParseIP(sAltSubjectIP)},
DNSNames: []string{sAltSubjectName},
}
return certObj
}