33 * SPDX-License-Identifier: Apache-2.0
44 */
55
6- import globals from '../shared/extensionGlobals'
7-
86import * as vscode from 'vscode'
97import { getLogger } from '../shared/logger'
108import { cast , Optional } from '../shared/utilities/typeConstructors'
@@ -18,6 +16,7 @@ import { AuthStatus, telemetry } from '../shared/telemetry/telemetry'
1816import { asStringifiedStack } from '../shared/telemetry/spans'
1917import { withTelemetryContext } from '../shared/telemetry/util'
2018import { isNetworkError } from '../shared/errors'
19+ import globals from '../shared/extensionGlobals'
2120
2221export type ToolId = 'codecatalyst' | 'codewhisperer' | 'testId'
2322
@@ -214,10 +213,14 @@ export class SecondaryAuth<T extends Connection = Connection> {
214213 return ! ! this . activeConnection && this . auth . getConnectionState ( this . activeConnection ) === 'invalid'
215214 }
216215
216+ public get state ( ) {
217+ return this . auth . getStateMemento ( )
218+ }
219+
217220 public async saveConnection ( conn : T ) {
218221 // TODO: fix this
219222 // eslint-disable-next-line aws-toolkits/no-banned-usages
220- await globals . context . globalState . update ( this . key , conn . id )
223+ await this . state . update ( this . key , conn . id )
221224 this . #savedConnection = conn
222225 this . #onDidChangeActiveConnection. fire ( this . activeConnection )
223226 }
@@ -251,7 +254,7 @@ export class SecondaryAuth<T extends Connection = Connection> {
251254 public async clearSavedConnection ( ) {
252255 // TODO: fix this
253256 // eslint-disable-next-line aws-toolkits/no-banned-usages
254- await globals . context . globalState . update ( this . key , undefined )
257+ await this . state . update ( this . key , undefined )
255258 this . #savedConnection = undefined
256259 this . #onDidChangeActiveConnection. fire ( this . activeConnection )
257260 }
@@ -326,9 +329,6 @@ export class SecondaryAuth<T extends Connection = Connection> {
326329 * Provides telemetry if called by restoreConnection() (or another auth_modifyConnection context)
327330 */
328331 private async _loadSavedConnection ( ) {
329- // TODO: fix this
330- // eslint-disable-next-line aws-toolkits/no-banned-usages
331- const globalState = globals . context . globalState
332332 const id = this . getStateConnectionId ( )
333333 if ( id === undefined ) {
334334 return
@@ -337,10 +337,10 @@ export class SecondaryAuth<T extends Connection = Connection> {
337337 const conn = await this . auth . getConnection ( { id } )
338338 if ( conn === undefined ) {
339339 getLogger ( ) . warn ( `auth (${ this . toolId } ): removing saved connection "${ this . key } " as it no longer exists` )
340- await globalState . update ( this . key , undefined )
340+ await this . state . update ( this . key , undefined )
341341 } else if ( ! this . isUsable ( conn ) ) {
342342 getLogger ( ) . warn ( `auth (${ this . toolId } ): saved connection "${ this . key } " is not valid` )
343- await globalState . update ( this . key , undefined )
343+ await this . state . update ( this . key , undefined )
344344 } else {
345345 const getAuthStatus = ( state : ReturnType < typeof this . auth . getConnectionState > ) : AuthStatus => {
346346 return state === 'invalid' ? 'expired' : 'connected'
@@ -377,7 +377,7 @@ export class SecondaryAuth<T extends Connection = Connection> {
377377 }
378378
379379 private getStateConnectionId ( ) {
380- return cast ( globals . globalState . get ( this . key ) , Optional ( String ) )
380+ return cast ( this . state . get ( this . key ) , Optional ( String ) )
381381 }
382382}
383383
0 commit comments