@@ -88,7 +88,6 @@ func HandleTLSFLag(insecureTLS bool) {
88
88
if err != nil {
89
89
messageAndExit ("There was a problem writing to the cli config" )
90
90
}
91
-
92
91
if clientCert != "" {
93
92
cliConfig .Set (CertKey , clientCert )
94
93
err = cliConfig .WriteConfig ()
@@ -101,7 +100,6 @@ func HandleTLSFLag(insecureTLS bool) {
101
100
if ! insecureTLS && clientCert == "" {
102
101
103
102
fmt .Print ("Are you sure you want to continue with an insecure connection to " + cliConfig .GetString (KabURLKey ) + " (y/n): " )
104
-
105
103
reader := bufio .NewReader (os .Stdin )
106
104
char , _ , err := reader .ReadRune ()
107
105
if err != nil {
@@ -155,24 +153,54 @@ var loginCmd = &cobra.Command{
155
153
RunE : func (cmd * cobra.Command , args []string ) error {
156
154
Debug .log ("login called" )
157
155
var err error
156
+ var ePass = ""
157
+ var eUser = ""
158
158
159
+ fmt .Println (ePass )
160
+ fmt .Println (eUser )
159
161
username , _ := cmd .Flags ().GetString ("username" )
160
162
password , _ := cmd .Flags ().GetString ("password" )
161
163
164
+ if username == "" {
165
+ fmt .Printf ("Username:" )
166
+ bytePwd , err := terminal .ReadPassword (int (syscall .Stdin ))
167
+ if err != nil {
168
+ return err
169
+ }
170
+ eUser = base64 .StdEncoding .EncodeToString (bytePwd )
171
+ for i := 0 ; i < len (bytePwd ); i ++ {
172
+ bytePwd [i ] = 0
173
+ }
174
+ bytePwd = nil
175
+ if bytePwd == nil {
176
+ fmt .Print ()
177
+ }
178
+ fmt .Println ()
179
+ } else {
180
+ eUser = base64 .StdEncoding .EncodeToString ([]byte (username ))
181
+ }
162
182
if password == "" {
163
183
fmt .Printf ("Password:" )
164
184
bytePwd , err := terminal .ReadPassword (int (syscall .Stdin ))
165
185
if err != nil {
166
186
return err
167
187
}
168
- password = strings .TrimSpace (string (bytePwd ))
188
+ ePass = base64 .StdEncoding .EncodeToString (bytePwd )
189
+ for i := 0 ; i < len (bytePwd ); i ++ {
190
+ bytePwd [i ] = 0
191
+ }
192
+ bytePwd = nil
193
+ if bytePwd == nil {
194
+ fmt .Print ()
195
+ }
169
196
fmt .Println ()
197
+ } else {
198
+ ePass = base64 .StdEncoding .EncodeToString ([]byte (password ))
170
199
}
171
200
172
201
var kabLoginURL string
173
202
174
203
viper .SetEnvPrefix ("KABANERO" )
175
-
176
204
if len (args ) > 0 {
177
205
cliConfig .Set (KabURLKey , parseKabURL (args [0 ]))
178
206
err = cliConfig .WriteConfig ()
@@ -188,14 +216,24 @@ var loginCmd = &cobra.Command{
188
216
HandleTLSFLag (InsecureTLS )
189
217
190
218
kabLoginURL = getRESTEndpoint ("login" )
191
- ePass := base64 .StdEncoding .EncodeToString ([]byte (password ))
192
- eUser := base64 .StdEncoding .EncodeToString ([]byte (username ))
193
- requestBody , _ := json .Marshal (map [string ]string {"000_ERG_TEN_TWENTY" : eUser , "010_BOHM_THIRTY_FIVE" : ePass })
194
219
220
+ requestBody , _ := json .Marshal (map [string ]string {"000_ERG_TEN_TWENTY" : eUser , "010_BOHM_THIRTY_FIVE" : ePass })
195
221
resp , err := sendHTTPRequest ("POST" , kabLoginURL , requestBody )
196
222
if err != nil {
197
223
messageAndExit ("login: Error on sendHTTPRequest:" )
198
224
}
225
+ requestBody = nil
226
+ if requestBody == nil {
227
+ fmt .Print ()
228
+ }
229
+ eUser = ""
230
+ if eUser == "" {
231
+ fmt .Print ()
232
+ }
233
+ ePass = ""
234
+ if ePass == "" {
235
+ fmt .Print ()
236
+ }
199
237
200
238
Debug .log ("RESPONSE " , kabLoginURL , resp .StatusCode , http .StatusText (resp .StatusCode ))
201
239
if resp .StatusCode == 404 {
@@ -210,20 +248,18 @@ var loginCmd = &cobra.Command{
210
248
}
211
249
key := security .Create32BKey ((time .Now ().String ()))
212
250
cliConfig .Set ("key" , key )
213
-
214
251
encryptedJWT := security .EncryptString (data .JWT , key )
215
252
cliConfig .Set ("jwt" , encryptedJWT )
216
-
217
253
err = cliConfig .WriteConfig ()
218
254
if err != nil {
219
255
return err
220
256
}
221
257
if cliConfig .GetString ("jwt" ) == "" {
222
258
messageAndExit ("Unable to validate user: " + username + " to " + cliConfig .GetString (KabURLKey ))
223
259
}
224
-
260
+ key = ""
261
+ fmt .Println (key )
225
262
if ! is06Compatible () {
226
-
227
263
url := getRESTEndpoint ("logout" )
228
264
resp , err := sendHTTPRequest ("POST" , url , nil )
229
265
if err != nil {
@@ -237,12 +273,14 @@ var loginCmd = &cobra.Command{
237
273
return err
238
274
}
239
275
} else {
240
-
241
276
fmt .Println ("Logged in to Kabanero instance: " + cliConfig .GetString (KabURLKey ))
242
277
Debug .log ("Logged in to Kabanero instance: " + cliConfig .GetString (KabURLKey ))
243
278
}
244
279
defer resp .Body .Close ()
245
-
280
+ cliConfig = nil
281
+ if cliConfig == nil {
282
+ fmt .Print ()
283
+ }
246
284
return nil
247
285
},
248
286
}
@@ -252,7 +290,8 @@ func init() {
252
290
253
291
loginCmd .Flags ().StringP ("username" , "u" , "" , "github username" )
254
292
255
- _ = loginCmd .MarkFlagRequired ("username" )
293
+ //_ = loginCmd.MarkFlagRequired("username") // possibly comment out to make username flad not required and add promot for username
294
+ //loginCmd.Flags().String("username", "u", "", "github username. If no username is provided, prompt will appear")
256
295
loginCmd .Flags ().StringP ("password" , "p" , "" , "github password/PAT. If no password is provided, prompt will appear" )
257
296
loginCmd .Flags ().BoolVar (& InsecureTLS , "insecure-skip-tls-verify" , false , "If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure" )
258
297
loginCmd .Flags ().StringVar (& clientCert , "certificate-authority" , "" , "Path to a cert file for the certificate authority" )
0 commit comments