@@ -174,7 +174,19 @@ export class ConnectionManager implements Disposable {
174174 return this . _workspaceClient ?. apiClient ;
175175 }
176176
177- async resolveAuth ( ) {
177+ private async loginWithSavedAuth ( ) {
178+ const authProvider = await this . resolveAuth ( ) ;
179+ if ( authProvider === undefined ) {
180+ await this . logout ( ) ;
181+ return ;
182+ }
183+ await this . connect ( authProvider ) ;
184+ }
185+
186+ @onError ( { popup : { prefix : "Failed to login." } } )
187+ @Mutex . synchronise ( "loginLogoutMutex" )
188+ private async resolveAuth ( ) {
189+ this . updateState ( "CONNECTING" ) ;
178190 const host = await this . configModel . get ( "host" ) ;
179191 const target = this . configModel . target ;
180192 if ( host === undefined || target === undefined ) {
@@ -211,63 +223,52 @@ export class ConnectionManager implements Disposable {
211223 }
212224 }
213225
214- @onError ( {
215- popup : { prefix : "Can't login with saved auth." } ,
216- } )
217- private async loginWithSavedAuth ( ) {
218- const authProvider = await this . resolveAuth ( ) ;
219- if ( authProvider === undefined ) {
220- await this . logout ( ) ;
221- return ;
222- }
223- await this . login ( authProvider ) ;
224- }
225-
226- private async login ( authProvider : AuthProvider ) : Promise < void > {
227- if ( ! ( await authProvider . check ( ) ) ) {
228- // We return without any state changes. This ensures that
229- // if users move from a working auth type to an invalid
230- // auth, the old auth will continue working and they will not
231- // have to re authenticate even the old one.
232- return ;
233- }
234-
226+ private async connect ( authProvider : AuthProvider ) : Promise < void > {
235227 try {
236- await this . loginLogoutMutex . synchronise ( async ( ) => {
237- this . updateState ( "CONNECTING" ) ;
238-
239- const databricksWorkspace = await DatabricksWorkspace . load (
240- authProvider . getWorkspaceClient ( ) ,
241- authProvider
242- ) ;
243- this . _databricksWorkspace = databricksWorkspace ;
244- this . _workspaceClient = authProvider . getWorkspaceClient ( ) ;
245-
246- await this . _databricksWorkspace . optionalEnableFilesInReposPopup (
247- this . _workspaceClient
248- ) ;
249- await this . configModel . set (
250- "authProfile" ,
251- authProvider . toJSON ( ) . profile as string | undefined
252- ) ;
253- await this . configModel . setAuthProvider ( authProvider ) ;
254- await this . updateSyncDestinationMapper ( ) ;
255- await this . updateClusterManager ( ) ;
256- await this . _metadataService . setApiClient ( this . apiClient ) ;
257- this . updateState ( "CONNECTED" ) ;
258- } ) ;
228+ await window . withProgress (
229+ {
230+ location : { viewId : "configurationView" } ,
231+ title : "Connecting to the workspace" ,
232+ } ,
233+ ( ) => this . _connect ( authProvider )
234+ ) ;
259235 } catch ( e ) {
260- NamedLogger . getOrCreate ( "Extension" ) . error ( `Login failed` , e ) ;
236+ NamedLogger . getOrCreate ( "Extension" ) . error (
237+ `Can't connect to the workspace` ,
238+ e
239+ ) ;
261240 if ( e instanceof Error ) {
262241 await window . showWarningMessage (
263- `Login failed with error : "${ e . message } "."`
242+ `Can't connect to the workspace : "${ e . message } "."`
264243 ) ;
265244 }
266245 await this . logout ( ) ;
267246 }
268247 }
269248
270- @onError ( { popup : { prefix : "Can't logout" } } )
249+ @Mutex . synchronise ( "loginLogoutMutex" )
250+ private async _connect ( authProvider : AuthProvider ) {
251+ this . updateState ( "CONNECTING" ) ;
252+ this . _databricksWorkspace = await DatabricksWorkspace . load (
253+ authProvider . getWorkspaceClient ( ) ,
254+ authProvider
255+ ) ;
256+ this . _workspaceClient = authProvider . getWorkspaceClient ( ) ;
257+ await this . _databricksWorkspace . optionalEnableFilesInReposPopup (
258+ this . _workspaceClient
259+ ) ;
260+ await this . configModel . set (
261+ "authProfile" ,
262+ authProvider . toJSON ( ) . profile as string | undefined
263+ ) ;
264+ await this . configModel . setAuthProvider ( authProvider ) ;
265+ await this . updateSyncDestinationMapper ( ) ;
266+ await this . updateClusterManager ( ) ;
267+ await this . _metadataService . setApiClient ( this . apiClient ) ;
268+ this . updateState ( "CONNECTED" ) ;
269+ }
270+
271+ @onError ( { popup : { prefix : "Can't logout." } } )
271272 @Mutex . synchronise ( "loginLogoutMutex" )
272273 async logout ( ) {
273274 this . _workspaceClient = undefined ;
@@ -288,8 +289,7 @@ export class ConnectionManager implements Disposable {
288289 if ( ! authProvider ) {
289290 return ;
290291 }
291-
292- await this . login ( authProvider ) ;
292+ await this . connect ( authProvider ) ;
293293 }
294294
295295 @onError ( {
0 commit comments