Skip to content

Commit 9ca5f13

Browse files
refactor(auth): move startUrls to constants file (#5998)
## Problem Static start urls are scattered ## Solution Move them to the auth constants file ## Additional Created a file for datetime related code. It includes static values which represent certain amounts of time in milliseconds. Future work will use this. --- <!--- REMINDER: Ensure that your PR meets the guidelines in CONTRIBUTING.md --> License: I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Signed-off-by: nkomonen-amazon <[email protected]>
1 parent b753e82 commit 9ca5f13

File tree

32 files changed

+246
-225
lines changed

32 files changed

+246
-225
lines changed

packages/core/src/auth/auth.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Timeout } from '../shared/utilities/timeoutUtils'
1616
import { errorCode, isAwsError, isNetworkError, ToolkitError, UnknownError } from '../shared/errors'
1717
import { getCache, getCacheFileWatcher } from './sso/cache'
1818
import { isNonNullable, Mutable } from '../shared/utilities/tsUtils'
19-
import { builderIdStartUrl, SsoToken, truncateStartUrl } from './sso/model'
19+
import { SsoToken, truncateStartUrl } from './sso/model'
2020
import { SsoClient } from './sso/clients'
2121
import { getLogger } from '../shared/logger'
2222
import { CredentialsProviderManager } from './providers/credentialsProviderManager'
@@ -68,6 +68,7 @@ import { asStringifiedStack } from '../shared/telemetry/spans'
6868
import { withTelemetryContext } from '../shared/telemetry/util'
6969
import { DiskCacheError } from '../shared/utilities/cacheUtils'
7070
import { setContext } from '../shared/vscode/setContext'
71+
import { builderIdStartUrl, internalStartUrl } from './sso/constants'
7172

7273
interface AuthService {
7374
/**
@@ -189,7 +190,7 @@ export class Auth implements AuthService, ConnectionManager {
189190
}
190191

191192
public isInternalAmazonUser(): boolean {
192-
return this.isConnected() && this.startUrl === 'https://amzn.awsapps.com/start'
193+
return this.isConnected() && this.startUrl === internalStartUrl
193194
}
194195

195196
/**

packages/core/src/auth/connection.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import * as vscode from 'vscode'
66
import { Credentials } from '@aws-sdk/types'
77
import { Mutable } from '../shared/utilities/tsUtils'
8-
import { builderIdStartUrl, ClientRegistration, SsoToken, truncateStartUrl } from './sso/model'
8+
import { ClientRegistration, SsoToken, truncateStartUrl } from './sso/model'
99
import { SsoClient } from './sso/clients'
1010
import { CredentialsProviderManager } from './providers/credentialsProviderManager'
1111
import { fromString } from './providers/credentials'
@@ -17,6 +17,7 @@ import { withTelemetryContext } from '../shared/telemetry/util'
1717
import { AuthModifyConnection, telemetry } from '../shared/telemetry/telemetry'
1818
import { asStringifiedStack } from '../shared/telemetry/spans'
1919
import { getTelemetryReason, getTelemetryReasonDesc } from '../shared/errors'
20+
import { builderIdStartUrl } from './sso/constants'
2021

2122
/** Shows a warning message unless it is the same as the last one shown. */
2223
const warnOnce = onceChanged((s: string, url: string) => {

packages/core/src/auth/providers/sharedCredentialsProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ import {
2929
Profile,
3030
Section,
3131
} from '../credentials/sharedCredentials'
32-
import { builderIdStartUrl } from '../sso/model'
3332
import { SectionName, SharedCredentialsKeys } from '../credentials/types'
3433
import { SsoProfile, hasScopes, scopesSsoAccountAccess } from '../connection'
34+
import { builderIdStartUrl } from '../sso/constants'
3535

3636
const credentialSources = {
3737
ECS_CONTAINER: 'EcsContainer',

packages/core/src/auth/sso/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
* web, node, or vue.
99
*/
1010

11+
export const builderIdStartUrl = 'https://view.awsapps.com/start'
12+
export const internalStartUrl = 'https://amzn.awsapps.com/start'
13+
1114
export const ssoUrlFormatRegex =
1215
/^(https?:\/\/(.+)\.awsapps\.com\/start|https?:\/\/identitycenter\.amazonaws\.com\/ssoins-[\da-zA-Z]{16})\/?$/
1316

packages/core/src/auth/sso/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { ssoAuthHelpUrl } from '../../shared/constants'
1616
import { openUrl } from '../../shared/utilities/vsCodeUtils'
1717
import { ToolkitError } from '../../shared/errors'
1818
import { isCloud9 } from '../../shared/extensionUtilities'
19+
import { builderIdStartUrl } from './constants'
1920

2021
export interface SsoToken {
2122
/**
@@ -88,7 +89,6 @@ export interface SsoProfile {
8889
readonly identifier?: string
8990
}
9091

91-
export const builderIdStartUrl = 'https://view.awsapps.com/start'
9292
export const trustedDomainCancellation = 'TrustedDomainCancellation'
9393

9494
const tryOpenHelpUrl = (url: vscode.Uri) =>

packages/core/src/auth/sso/ssoAccessTokenProvider.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,7 @@
66
import * as vscode from 'vscode'
77
import globals from '../../shared/extensionGlobals'
88
import { AuthorizationPendingException, SSOOIDCServiceException, SlowDownException } from '@aws-sdk/client-sso-oidc'
9-
import {
10-
SsoToken,
11-
ClientRegistration,
12-
isExpired,
13-
SsoProfile,
14-
builderIdStartUrl,
15-
openSsoPortalLink,
16-
isDeprecatedAuth,
17-
} from './model'
9+
import { SsoToken, ClientRegistration, isExpired, SsoProfile, openSsoPortalLink, isDeprecatedAuth } from './model'
1810
import { getCache } from './cache'
1911
import { hasProps, hasStringProps, RequiredProps, selectFrom } from '../../shared/utilities/tsUtils'
2012
import { OidcClient } from './clients'
@@ -46,6 +38,7 @@ import { NestedMap } from '../../shared/utilities/map'
4638
import { asStringifiedStack } from '../../shared/telemetry/spans'
4739
import { showViewLogsMessage } from '../../shared/utilities/messages'
4840
import _ from 'lodash'
41+
import { builderIdStartUrl } from './constants'
4942

5043
export const authenticationPath = 'sso/authenticated'
5144

packages/core/src/awsService/cloudWatchLogs/commands/viewLogStream.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import {
2424
import { prepareDocument, searchLogGroup } from './searchLogGroup'
2525
import { telemetry, Result } from '../../../shared/telemetry/telemetry'
2626
import { CancellationError } from '../../../shared/utilities/timeoutUtils'
27-
import { formatLocalized } from '../../../shared/utilities/textUtilities'
2827
import { cwlUriSchema } from '../cloudWatchLogsUtils'
28+
import { formatLocalized } from '../../../shared/datetime'
2929

3030
export async function viewLogStream(node: LogGroupNode, registry: LogDataRegistry): Promise<void> {
3131
await telemetry.cloudwatchlogs_open.run(async (span) => {

packages/core/src/awsService/cloudWatchLogs/document/textContent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import { formatDateTimestamp } from '../../../shared/datetime'
67
import { CloudWatchLogsEvent, CloudWatchLogsGroupInfo } from '../registry/logDataRegistry'
7-
import { formatDateTimestamp } from '../../../shared/utilities/textUtilities'
88

99
export const timestampSpaceEquivalent = ' '
1010

packages/core/src/awsService/ecs/commands.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import globals from '../../shared/extensionGlobals'
1111
import { ToolkitPromptSettings } from '../../shared/settings'
1212
import { ChildProcess } from '../../shared/utilities/processUtils'
1313
import { showMessageWithCancel, showOutputMessage } from '../../shared/utilities/messages'
14-
import { formatDateTimestamp, removeAnsi } from '../../shared/utilities/textUtilities'
14+
import { removeAnsi } from '../../shared/utilities/textUtilities'
1515
import { CancellationError, Timeout } from '../../shared/utilities/timeoutUtils'
1616
import { Commands } from '../../shared/vscode/commands2'
1717
import { EcsSettings } from './util'
@@ -22,6 +22,7 @@ import { Container, Service } from './model'
2222
import { Instance } from '../../shared/utilities/typeConstructors'
2323
import { telemetry } from '../../shared/telemetry/telemetry'
2424
import { openRemoteTerminal } from '../../shared/remoteSession'
25+
import { formatDateTimestamp } from '../../shared/datetime'
2526

2627
async function runCommandWizard(
2728
param?: unknown,

packages/core/src/awsService/iot/explorer/iotCertificateNode.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ import { IotCertsFolderNode } from './iotCertFolderNode'
2020
import { IotThingNode } from './iotThingNode'
2121
import { IotPolicyCertNode } from './iotPolicyNode'
2222
import { getIcon } from '../../../shared/icons'
23-
import { formatLocalized, truncate } from '../../../shared/utilities/textUtilities'
23+
import { truncate } from '../../../shared/utilities/textUtilities'
2424
import { Settings } from '../../../shared/settings'
2525
import { ClassToInterfaceType } from '../../../shared/utilities/tsUtils'
26+
import { formatLocalized } from '../../../shared/datetime'
2627

2728
const contextBase = 'awsIotCertificateNode'
2829
/**

0 commit comments

Comments
 (0)