File tree Expand file tree Collapse file tree 3 files changed +25
-20
lines changed Expand file tree Collapse file tree 3 files changed +25
-20
lines changed Original file line number Diff line number Diff line change
1
+ /*!
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * For compatibility, this file should not import anything that cannot be used in
8
+ * web, node, or vue.
9
+ */
10
+
11
+ export const ssoUrlFormatRegex =
12
+ / ^ ( h t t p s ? : \/ \/ ( .+ ) \. a w s a p p s \. c o m \/ s t a r t | h t t p s ? : \/ \/ i d e n t i t y c e n t e r \. a m a z o n a w s \. c o m \/ s s o i n s - [ \d a - z A - Z ] { 16 } ) \/ ? $ /
13
+
14
+ export const ssoUrlFormatMessage =
15
+ 'URLs must start with http:// or https://. Example: https://d-xxxxxxxxxx.awsapps.com/start'
Original file line number Diff line number Diff line change @@ -6,19 +6,15 @@ import * as vscode from 'vscode'
6
6
import { UnknownError } from '../../shared/errors'
7
7
import { AuthType } from '../auth'
8
8
import { SsoConnection , hasScopes , isAnySsoConnection } from '../connection'
9
+ import { ssoUrlFormatMessage , ssoUrlFormatRegex } from './constants'
9
10
10
- export function validateSsoUrl ( auth : AuthType , url : string , requiredScopes ?: string [ ] ) {
11
- const urlFormatError = validateSsoUrlFormat ( url )
12
- if ( urlFormatError ) {
13
- return urlFormatError
14
- }
15
-
16
- return validateIsNewSsoUrlAsync ( auth , url , requiredScopes )
17
- }
18
-
11
+ /**
12
+ * Returns an error message if the url is not properly formatted.
13
+ * Otherwise, returns undefined.
14
+ */
19
15
export function validateSsoUrlFormat ( url : string ) {
20
- if ( ! url . match ( / ^ ( h t t p | h t t p s ) : \/ \/ / i ) ) {
21
- return 'URLs must start with http:// or https://. Example: https://d-xxxxxxxxxx.awsapps.com/start'
16
+ if ( ! ssoUrlFormatRegex . test ( url ) ) {
17
+ return ssoUrlFormatMessage
22
18
}
23
19
}
24
20
Original file line number Diff line number Diff line change @@ -278,18 +278,13 @@ import { LoginOption } from './types'
278
278
import { CommonAuthWebview } from ' ./backend'
279
279
import { WebviewClientFactory } from ' ../../../webviews/client'
280
280
import { Region } from ' ../../../shared/regions/endpoints'
281
+ import { ssoUrlFormatRegex , ssoUrlFormatMessage } from ' ../../../auth/sso/constants'
281
282
282
283
const client = WebviewClientFactory .create <CommonAuthWebview >()
283
284
284
285
/** Where the user is currently in the builder id setup process */
285
286
type Stage = ' START' | ' SSO_FORM' | ' CONNECTED' | ' AUTHENTICATING' | ' AWS_PROFILE'
286
287
287
- function validateSsoUrlFormat(url : string ) {
288
- const regex =
289
- / ^ (https? :\/\/ (. + )\. awsapps\. com\/ start| https? :\/\/ identitycenter\. amazonaws\. com\/ ssoins-[\d a-zA-Z ] {16} )\/ ? $ /
290
- return regex .test (url )
291
- }
292
-
293
288
function getCredentialId(loginOption : LoginOption ) {
294
289
switch (loginOption ) {
295
290
case LoginOption .BUILDER_ID :
@@ -481,9 +476,8 @@ export default defineComponent({
481
476
}
482
477
},
483
478
handleUrlInput() {
484
- if (this .startUrl && ! validateSsoUrlFormat (this .startUrl )) {
485
- this .startUrlError =
486
- ' URLs must start with http:// or https://. Example: https://d-xxxxxxxxxx.awsapps.com/start'
479
+ if (this .startUrl && ! ssoUrlFormatRegex .test (this .startUrl )) {
480
+ this .startUrlError = ssoUrlFormatMessage
487
481
} else if (this .startUrl && this .existingStartUrls .some ((url ) => url === this .startUrl )) {
488
482
this .startUrlError =
489
483
' A connection for this start URL already exists. Sign out before creating a new one.'
You can’t perform that action at this time.
0 commit comments