11import { ExecUtils , WorkspaceClient } from "@databricks/databricks-sdk" ;
22import { commands , Disposable , Uri , window } from "vscode" ;
3- import { AuthProvider } from "./auth/AuthProvider" ;
3+ import { AzureCliAuthProvider } from "./auth/AuthProvider" ;
44
55export type Step < S , N > = ( ) => Promise <
66 SuccessResult < S > | NextResult < N > | ErrorResult
@@ -54,25 +54,30 @@ type AzureStepName =
5454
5555export class AzureCliCheck implements Disposable {
5656 private disposables : Disposable [ ] = [ ] ;
57+ private isCodeSpaces : boolean ;
58+
59+ tenantId : string | undefined ;
5760
5861 constructor (
59- private authProvider : AuthProvider ,
62+ private authProvider : AzureCliAuthProvider ,
6063 private azBinPath : string = "az"
61- ) { }
64+ ) {
65+ this . isCodeSpaces = process . env . CODESPACES === "true" ;
66+ }
6267
6368 dispose ( ) {
6469 this . disposables . forEach ( ( i ) => i . dispose ( ) ) ;
6570 this . disposables = [ ] ;
6671 }
6772
6873 public async check ( silent = false ) : Promise < boolean > {
69- let tenant : string ;
74+ this . tenantId = this . authProvider . tenantId ;
7075
7176 const steps : Record < AzureStepName , Step < boolean , AzureStepName > > = {
7277 tryLogin : async ( ) => {
7378 const result = await this . tryLogin ( this . authProvider . host ) ;
7479 if ( typeof result === "string" ) {
75- tenant = result ;
80+ this . tenantId = result ;
7681 return {
7782 type : "next" ,
7883 next : "loginAzureCli" ,
@@ -123,7 +128,7 @@ export class AzureCliCheck implements Disposable {
123128 } ;
124129 } ,
125130 loginAzureCli : async ( ) => {
126- if ( await this . loginAzureCli ( tenant ) ) {
131+ if ( await this . loginAzureCli ( this . tenantId ) ) {
127132 return {
128133 type : "next" ,
129134 next : "tryLogin" ,
@@ -233,7 +238,7 @@ export class AzureCliCheck implements Disposable {
233238 public async loginAzureCli ( tenant = "" ) : Promise < boolean > {
234239 let message = 'You need to run "az login" to login with Azure.' ;
235240 if ( tenant ) {
236- message = `You are logged in with the wrong tenant ID. Run "az login -t ${ tenant } " to login with Azure with the correct tenant .` ;
241+ message = `You need to tun "az login -t ${ tenant } " to login with Azure.` ;
237242 }
238243 const choice = await window . showInformationMessage (
239244 message ,
@@ -245,8 +250,11 @@ export class AzureCliCheck implements Disposable {
245250 const terminal = window . createTerminal ( "az login" ) ;
246251 this . disposables . push ( terminal ) ;
247252 terminal . show ( ) ;
253+
254+ const useDeviceCode = this . isCodeSpaces ? "--use-device-code" : "" ;
255+
248256 terminal . sendText (
249- `${ this . azBinPath } login ${
257+ `${ this . azBinPath } login ${ useDeviceCode } ${
250258 tenant ? "-t " + tenant : ""
251259 } ; echo "Press any key to close the terminal and continue ..."; read; exit`
252260 ) ;
0 commit comments