@@ -7,6 +7,7 @@ import { isManaged } from "../../api/debug";
7
7
import * as certificates from "../../api/debug/certificates" ;
8
8
import { instance } from "../../instantiate" ;
9
9
import { ConnectionData , Server } from '../../typings' ;
10
+ import { t } from "../../locale" ;
10
11
11
12
const ENCODINGS = [ `37` , `256` , `273` , `277` , `278` , `280` , `284` , `285` , `297` , `500` , `871` , `870` , `905` , `880` , `420` , `875` , `424` , `1026` , `290` , `win37` , `win256` , `win273` , `win277` , `win278` , `win280` , `win284` , `win285` , `win297` , `win500` , `win871` , `win870` , `win905` , `win880` , `win420` , `win875` , `win424` , `win1026` ] ;
12
13
@@ -311,44 +312,77 @@ export class SettingsUI {
311
312
if ( connections ) {
312
313
const connectionIdx = connections . findIndex ( item => item . name === name ) ;
313
314
let connection = connections [ connectionIdx ] ;
315
+ const storedPassword = await context . secrets . get ( `${ name } _password` ) ;
314
316
315
317
const page = await new CustomUI ( )
316
- . addInput ( `host` , `Host or IP Address` , undefined , { default : connection . host , minlength : 1 } )
317
- . addInput ( `port` , `Port (SSH)` , undefined , { default : String ( connection . port ) , minlength : 1 , maxlength : 5 , regexTest : `^\\d+$` } )
318
- . addInput ( `username` , `Username` , undefined , { default : connection . username , minlength : 1 } )
319
- . addParagraph ( `Only provide either the password or a private key - not both.` )
320
- . addPassword ( `password` , `Password` , `Only provide a password if you want to update an existing one or set a new one.` )
321
- . addFile ( `privateKeyPath` , `Private Key${ connection . privateKeyPath ? ` (current: ${ connection . privateKeyPath } )` : `` } ` , `Only provide a private key if you want to update from the existing one or set one. OpenSSH, RFC4716, or PPK formats are supported.` )
322
- . addButtons ( { id : `submitButton` , label : `Save` , requiresValidation : true } )
323
- . loadPage < LoginSettings > ( `Login Settings: ${ name } ` ) ;
318
+ . addInput ( `host` , t ( `login.host` ) , undefined , { default : connection . host , minlength : 1 } )
319
+ . addInput ( `port` , t ( `login.port` ) , undefined , { default : String ( connection . port ) , minlength : 1 , maxlength : 5 , regexTest : `^\\d+$` } )
320
+ . addInput ( `username` , t ( `username` ) , undefined , { default : connection . username , minlength : 1 } )
321
+ . addParagraph ( t ( `login.authDecision` ) )
322
+ . addPassword ( `password` , `${ t ( `password` ) } ${ storedPassword ? ` (${ t ( `stored` ) } )` : `` } ` , t ( `login.password.label` ) )
323
+ . addFile ( `privateKeyPath` , `${ t ( `privateKey` ) } ${ connection . privateKeyPath ? ` (${ t ( `current` ) } : ${ connection . privateKeyPath } )` : `` } ` , t ( `login.privateKey.label` ) + ' ' + t ( `login.privateKey.support` ) )
324
+ . addButtons (
325
+ { id : `submitButton` , label : t ( `save` ) , requiresValidation : true } ,
326
+ { id : `removeAuth` , label : t ( `login.removeAuth` ) }
327
+ )
328
+ . loadPage < LoginSettings > ( t ( `login.title.edit` , name ) ) ;
324
329
325
330
if ( page && page . data ) {
326
331
page . panel . dispose ( ) ;
327
332
328
333
const data = page . data ;
329
- if ( ! data . privateKeyPath ?. trim ( ) ) {
330
- if ( connection . privateKeyPath ?. trim ( ) ) {
331
- data . privateKeyPath = connection . privateKeyPath ;
334
+
335
+ let doUpdate = false ;
336
+
337
+ const chosenButton = data . buttons as "submitButton" | "removeAuth" ;
338
+
339
+ switch ( chosenButton ) {
340
+ case `submitButton` :
341
+ if ( data . password ) {
342
+ // New password was entered, so store the password
343
+ // and remove the private key path from the data
344
+ await context . secrets . store ( `${ name } _password` , `${ data . password } ` ) ;
345
+ data . privateKeyPath = undefined ;
346
+
347
+ vscode . window . showInformationMessage ( t ( `login.password.updated` , name ) ) ;
348
+
349
+ doUpdate = true ;
350
+
351
+ } else {
352
+ // If no password was entered, but a keypath exists
353
+ // then remove the password from the data and
354
+ // use the keypath instead
355
+ if ( data . privateKeyPath ?. trim ( ) ) {
356
+ await context . secrets . delete ( `${ name } _password` ) ;
357
+
358
+ vscode . window . showInformationMessage ( t ( `login.privateKey.updated` , name ) ) ;
359
+
360
+ doUpdate = true ;
361
+ }
362
+ }
363
+ break ;
364
+
365
+ case `removeAuth` :
332
366
await context . secrets . delete ( `${ name } _password` ) ;
333
- }
334
- else {
335
- delete data . privateKeyPath ;
336
- }
337
- }
367
+ data . password = undefined ;
368
+ data . privateKeyPath = undefined ;
369
+
370
+ vscode . window . showInformationMessage ( t ( `login.authRemoved` , name ) ) ;
338
371
339
- if ( data . password && ! data . privateKeyPath ) {
340
- await context . secrets . delete ( `${ name } _password` ) ;
341
- await context . secrets . store ( `${ name } _password` , `${ data . password } ` ) ;
342
- delete data . privateKeyPath ;
372
+ doUpdate = true ;
373
+ break ;
343
374
}
344
375
345
- //Fix values before assigning the data
346
- data . port = Number ( data . port ) ;
347
- delete data . password ;
348
- delete data . buttons ;
349
376
350
- connections [ connectionIdx ] = Object . assign ( connection , data ) ;
351
- await GlobalConfiguration . set ( `connections` , connections ) ;
377
+ if ( doUpdate ) {
378
+ //Fix values before assigning the data
379
+ data . port = Number ( data . port ) ;
380
+ delete data . password ;
381
+ delete data . buttons ;
382
+
383
+ connections [ connectionIdx ] = Object . assign ( connection , data ) ;
384
+ await GlobalConfiguration . set ( `connections` , connections ) ;
385
+ }
352
386
}
353
387
}
354
388
}
0 commit comments