@@ -10,7 +10,9 @@ import { createWorkspaceIdentifier, extractAgents } from "./api/api-helper";
10
10
import { CoderApi } from "./api/coderApi" ;
11
11
import { needToken } from "./api/utils" ;
12
12
import { CliConfigManager } from "./core/cliConfig" ;
13
+ import { MementoManager } from "./core/mementoManager" ;
13
14
import { PathResolver } from "./core/pathResolver" ;
15
+ import { SecretsManager } from "./core/secretsManager" ;
14
16
import { CertificateError } from "./error" ;
15
17
import { getGlobalFlags } from "./globalFlags" ;
16
18
import { Storage } from "./storage" ;
@@ -39,6 +41,8 @@ export class Commands {
39
41
private readonly restClient : Api ,
40
42
private readonly storage : Storage ,
41
43
private readonly pathResolver : PathResolver ,
44
+ private readonly mementoManager : MementoManager ,
45
+ private readonly secretsManager : SecretsManager ,
42
46
) {
43
47
this . cliConfigManager = new CliConfigManager ( pathResolver ) ;
44
48
}
@@ -108,7 +112,7 @@ export class Commands {
108
112
quickPick . title = "Enter the URL of your Coder deployment." ;
109
113
110
114
// Initial items.
111
- quickPick . items = this . storage
115
+ quickPick . items = this . mementoManager
112
116
. withUrlHistory ( defaultURL , process . env . CODER_URL )
113
117
. map ( ( url ) => ( {
114
118
alwaysShow : true ,
@@ -119,7 +123,7 @@ export class Commands {
119
123
// an option in case the user wants to connect to something that is not in
120
124
// the list.
121
125
quickPick . onDidChangeValue ( ( value ) => {
122
- quickPick . items = this . storage
126
+ quickPick . items = this . mementoManager
123
127
. withUrlHistory ( defaultURL , process . env . CODER_URL , value )
124
128
. map ( ( url ) => ( {
125
129
alwaysShow : true ,
@@ -199,8 +203,8 @@ export class Commands {
199
203
this . restClient . setSessionToken ( res . token ) ;
200
204
201
205
// Store these to be used in later sessions.
202
- await this . storage . setUrl ( url ) ;
203
- await this . storage . setSessionToken ( res . token ) ;
206
+ await this . mementoManager . setUrl ( url ) ;
207
+ await this . secretsManager . setSessionToken ( res . token ) ;
204
208
205
209
// Store on disk to be used by the cli.
206
210
await this . cliConfigManager . configure ( label , url , res . token ) ;
@@ -288,7 +292,7 @@ export class Commands {
288
292
title : "Coder API Key" ,
289
293
password : true ,
290
294
placeHolder : "Paste your API key." ,
291
- value : token || ( await this . storage . getSessionToken ( ) ) ,
295
+ value : token || ( await this . secretsManager . getSessionToken ( ) ) ,
292
296
ignoreFocusOut : true ,
293
297
validateInput : async ( value ) => {
294
298
client . setSessionToken ( value ) ;
@@ -354,7 +358,7 @@ export class Commands {
354
358
* Log out from the currently logged-in deployment.
355
359
*/
356
360
public async logout ( ) : Promise < void > {
357
- const url = this . storage . getUrl ( ) ;
361
+ const url = this . mementoManager . getUrl ( ) ;
358
362
if ( ! url ) {
359
363
// Sanity check; command should not be available if no url.
360
364
throw new Error ( "You are not logged in" ) ;
@@ -366,8 +370,8 @@ export class Commands {
366
370
this . restClient . setSessionToken ( "" ) ;
367
371
368
372
// Clear from memory.
369
- await this . storage . setUrl ( undefined ) ;
370
- await this . storage . setSessionToken ( undefined ) ;
373
+ await this . mementoManager . setUrl ( undefined ) ;
374
+ await this . secretsManager . setSessionToken ( undefined ) ;
371
375
372
376
await vscode . commands . executeCommand (
373
377
"setContext" ,
@@ -392,7 +396,7 @@ export class Commands {
392
396
* Must only be called if currently logged in.
393
397
*/
394
398
public async createWorkspace ( ) : Promise < void > {
395
- const uri = this . storage . getUrl ( ) + "/templates" ;
399
+ const uri = this . mementoManager . getUrl ( ) + "/templates" ;
396
400
await vscode . commands . executeCommand ( "vscode.open" , uri ) ;
397
401
}
398
402
@@ -407,7 +411,7 @@ export class Commands {
407
411
public async navigateToWorkspace ( item : OpenableTreeItem ) {
408
412
if ( item ) {
409
413
const workspaceId = createWorkspaceIdentifier ( item . workspace ) ;
410
- const uri = this . storage . getUrl ( ) + `/@${ workspaceId } ` ;
414
+ const uri = this . mementoManager . getUrl ( ) + `/@${ workspaceId } ` ;
411
415
await vscode . commands . executeCommand ( "vscode.open" , uri ) ;
412
416
} else if ( this . workspace && this . workspaceRestClient ) {
413
417
const baseUrl =
@@ -430,7 +434,7 @@ export class Commands {
430
434
public async navigateToWorkspaceSettings ( item : OpenableTreeItem ) {
431
435
if ( item ) {
432
436
const workspaceId = createWorkspaceIdentifier ( item . workspace ) ;
433
- const uri = this . storage . getUrl ( ) + `/@${ workspaceId } /settings` ;
437
+ const uri = this . mementoManager . getUrl ( ) + `/@${ workspaceId } /settings` ;
434
438
await vscode . commands . executeCommand ( "vscode.open" , uri ) ;
435
439
} else if ( this . workspace && this . workspaceRestClient ) {
436
440
const baseUrl =
@@ -508,7 +512,7 @@ export class Commands {
508
512
509
513
// If workspace_name is provided, run coder ssh before the command
510
514
511
- const url = this . storage . getUrl ( ) ;
515
+ const url = this . mementoManager . getUrl ( ) ;
512
516
if ( ! url ) {
513
517
throw new Error ( "No coder url found for sidebar" ) ;
514
518
}
@@ -650,8 +654,8 @@ export class Commands {
650
654
newWindow = false ;
651
655
}
652
656
653
- // Only set the memento if when opening a new folder
654
- await this . storage . setFirstConnect ( ) ;
657
+ // Only set the memento when opening a new folder
658
+ await this . mementoManager . setFirstConnect ( ) ;
655
659
await vscode . commands . executeCommand (
656
660
"vscode.openFolder" ,
657
661
vscode . Uri . from ( {
@@ -831,8 +835,8 @@ export class Commands {
831
835
}
832
836
}
833
837
834
- // Only set the memento if when opening a new folder/window
835
- await this . storage . setFirstConnect ( ) ;
838
+ // Only set the memento when opening a new folder/window
839
+ await this . mementoManager . setFirstConnect ( ) ;
836
840
if ( folderPath ) {
837
841
await vscode . commands . executeCommand (
838
842
"vscode.openFolder" ,
0 commit comments