@@ -16,7 +16,7 @@ interface AuthTypeQuickPickItem extends QuickPickItem {
1616}
1717
1818interface State {
19- host : string ;
19+ host : URL ;
2020 authType : AuthType ;
2121 profile ?: string ;
2222 token ?: string ;
@@ -48,7 +48,7 @@ export async function configureWorkspaceWizard(
4848 } ,
4949 } ) ;
5050
51- state . host = host ;
51+ state . host = normalizeHost ( host ) ;
5252 return ( input : MultiStepInput ) => selectAuthMethod ( input , state ) ;
5353 }
5454
@@ -59,7 +59,7 @@ export async function configureWorkspaceWizard(
5959 const items : Array < AuthTypeQuickPickItem > = [ ] ;
6060 let profiles : Profiles = { } ;
6161
62- for ( const authMethod of authMethodsForHostname ( new URL ( state . host ! ) ) ) {
62+ for ( const authMethod of authMethodsForHostname ( state . host ! ) ) {
6363 switch ( authMethod ) {
6464 case "azure-cli" :
6565 items . push ( {
@@ -108,8 +108,7 @@ export async function configureWorkspaceWizard(
108108 . filter (
109109 ( label ) =>
110110 ( profiles [ label ] as Profile ) . host
111- . hostname ===
112- new URL ( state . host ! ) . hostname
111+ . hostname === state . host ! . hostname
113112 )
114113 . map ( ( label ) => ( {
115114 label,
@@ -195,36 +194,43 @@ export async function configureWorkspaceWizard(
195194 return ;
196195 }
197196
198- state . host = `https://${ new URL ( state . host ) . hostname } ` ;
199-
200197 return {
201198 authProvider : AuthProvider . fromJSON ( state ) ,
202199 } ;
203200}
204201
205- async function validateDatabricksHost (
206- host : string
207- ) : Promise < string | undefined > {
208- let url ;
202+ function normalizeHost ( host : string ) : URL {
203+ let url : URL ;
209204
210- if ( ! host . startsWith ( "https:// " ) ) {
205+ if ( ! host . startsWith ( "http " ) ) {
211206 host = `https://${ host } ` ;
212207 }
213-
214208 try {
215209 url = new URL ( host ) ;
216210 } catch ( e ) {
217- return "Invalid host name" ;
211+ throw new Error ( "Invalid host name" ) ;
218212 }
219213 if ( url . protocol !== "https:" ) {
220- return "Invalid protocol" ;
214+ throw new Error ( "Invalid protocol" ) ;
221215 }
222216 if (
223217 ! url . hostname . match (
224218 / ( \. a z u r e d a t a b r i c k s \. n e t | \. g c p \. d a t a b r i c k s \. c o m | \. c l o u d \. d a t a b r i c k s \. c o m ) $ /
225219 )
226220 ) {
227- return "Not a Databricks host" ;
221+ throw new Error ( "Not a Databricks host" ) ;
222+ }
223+
224+ return new URL ( `https://${ url . hostname } ` ) ;
225+ }
226+
227+ async function validateDatabricksHost (
228+ host : string
229+ ) : Promise < string | undefined > {
230+ try {
231+ normalizeHost ( host ) ;
232+ } catch ( e : any ) {
233+ return e . message ;
228234 }
229235}
230236
0 commit comments