193
193
@keydown.enter =" handleContinueClick()"
194
194
/>
195
195
<h4 class =" start-url-error" >{{ startUrlError }}</h4 >
196
+ <h4 class =" start-url-warning" >{{ startUrlWarning }}</h4 >
196
197
<div class =" title topMargin" >Region</div >
197
198
<div class =" hint" >AWS Region that hosts identity directory</div >
198
199
<select
@@ -278,7 +279,7 @@ import { LoginOption } from './types'
278
279
import { CommonAuthWebview } from ' ./backend'
279
280
import { WebviewClientFactory } from ' ../../../webviews/client'
280
281
import { Region } from ' ../../../shared/regions/endpoints'
281
- import { ssoUrlFormatRegex , ssoUrlFormatMessage } from ' ../../../auth/sso/constants'
282
+ import { ssoUrlFormatRegex , ssoUrlFormatMessage , urlInvalidFormatMessage } from ' ../../../auth/sso/constants'
282
283
283
284
const client = WebviewClientFactory .create <CommonAuthWebview >()
284
285
@@ -340,6 +341,7 @@ export default defineComponent({
340
341
stage: ' START' as Stage ,
341
342
regions: [] as Region [],
342
343
startUrlError: ' ' ,
344
+ startUrlWarning: ' ' ,
343
345
selectedRegion: ' us-east-1' ,
344
346
startUrl: ' ' ,
345
347
app: this .app ,
@@ -365,7 +367,7 @@ export default defineComponent({
365
367
366
368
// Pre-select the first available login option
367
369
await this .preselectLoginOption ()
368
- this .handleUrlInput () // validate the default startUrl
370
+ await this .handleUrlInput () // validate the default startUrl
369
371
},
370
372
methods: {
371
373
toggleItemSelection(itemId : number ) {
@@ -475,18 +477,48 @@ export default defineComponent({
475
477
this .stage = ' CONNECTED'
476
478
}
477
479
},
478
- handleUrlInput() {
479
- if (this .startUrl && ! ssoUrlFormatRegex .test (this .startUrl )) {
480
- this .startUrlError = ssoUrlFormatMessage
481
- } else if (this .startUrl && this .existingStartUrls .some ((url ) => url === this .startUrl )) {
482
- this .startUrlError =
483
- ' A connection for this start URL already exists. Sign out before creating a new one.'
484
- } else {
485
- this .startUrlError = ' '
480
+ async handleUrlInput() {
481
+ const messages = await resolveStartUrlMessages (this .startUrl , this .existingStartUrls )
482
+ this .startUrlError = messages .error
483
+ this .startUrlWarning = messages .warning
484
+
485
+ if (! messages .error && ! messages .warning ) {
486
486
void client .storeMetricMetadata ({
487
487
credentialStartUrl: this .startUrl ,
488
488
})
489
489
}
490
+
491
+ async function resolveStartUrlMessages(
492
+ startUrl : string | undefined ,
493
+ existingStartUrls : string []
494
+ ): Promise <{ warning: string ; error: string }> {
495
+ // No URL
496
+ if (! startUrl ) {
497
+ return { error: ' ' , warning: ' ' }
498
+ }
499
+
500
+ // Validate URL format
501
+ if (! ssoUrlFormatRegex .test (startUrl )) {
502
+ console .log (' Before Validate' )
503
+ if (await client .validateUrl (startUrl )) {
504
+ console .log (' After Validate' )
505
+ return { error: ' ' , warning: ssoUrlFormatMessage }
506
+ } else {
507
+ return { error: urlInvalidFormatMessage , warning: ' ' }
508
+ }
509
+ }
510
+
511
+ // Ensure that URL does not exist yet
512
+ if (existingStartUrls .some ((url ) => url === startUrl )) {
513
+ return {
514
+ error: ' A connection for this start URL already exists. Sign out before creating a new one.' ,
515
+ warning: ' ' ,
516
+ }
517
+ }
518
+
519
+ // URL is valid
520
+ return { error: ' ' , warning: ' ' }
521
+ }
490
522
},
491
523
handleRegionInput(event : any ) {
492
524
void client .storeMetricMetadata ({
@@ -743,6 +775,10 @@ body.vscode-high-contrast:not(body.vscode-high-contrast-light) .regionSelect {
743
775
color : #ff0000 ;
744
776
font-size : var (--font-size-sm );
745
777
}
778
+ .start-url-warning {
779
+ color : #dfe216 ;
780
+ font-size : var (--font-size-sm );
781
+ }
746
782
#logo {
747
783
fill : var (--vscode-button-foreground );
748
784
}
0 commit comments