@@ -59,13 +59,15 @@ import {
5959 AwsConnection ,
6060 scopesCodeWhispererCore ,
6161 ProfileNotFoundError ,
62+ isSsoConnection ,
6263} from './connection'
6364import { isSageMaker , isCloud9 , isAmazonQ } from '../shared/extensionUtilities'
6465import { telemetry } from '../shared/telemetry/telemetry'
6566import { randomUUID } from '../shared/crypto'
6667import { asStringifiedStack } from '../shared/telemetry/spans'
6768import { withTelemetryContext } from '../shared/telemetry/util'
6869import { DiskCacheError } from '../shared/utilities/cacheUtils'
70+ import { setContext } from '../shared/vscode/setContext'
6971
7072interface AuthService {
7173 /**
@@ -166,6 +168,30 @@ export class Auth implements AuthService, ConnectionManager {
166168 return this . #ssoCacheWatcher
167169 }
168170
171+ public get startUrl ( ) : string | undefined {
172+ return isSsoConnection ( this . activeConnection )
173+ ? this . normalizeStartUrl ( this . activeConnection . startUrl )
174+ : undefined
175+ }
176+
177+ public isConnected ( ) : boolean {
178+ return this . activeConnection !== undefined
179+ }
180+
181+ /**
182+ * Normalizes the provided URL
183+ *
184+ * Any trailing '/' and `#` is removed from the URL
185+ * e.g. https://view.awsapps.com/start/# will become https://view.awsapps.com/start
186+ */
187+ public normalizeStartUrl ( startUrl : string | undefined ) {
188+ return ! startUrl ? undefined : startUrl . replace ( / [ \/ # ] + $ / g, '' )
189+ }
190+
191+ public isInternalAmazonUser ( ) : boolean {
192+ return this . isConnected ( ) && this . startUrl === 'https://amzn.awsapps.com/start'
193+ }
194+
169195 /**
170196 * Map startUrl -> declared connections
171197 */
@@ -223,6 +249,8 @@ export class Auth implements AuthService, ConnectionManager {
223249 this . #onDidChangeActiveConnection. fire ( conn )
224250 await this . store . setCurrentProfileId ( id )
225251
252+ await setContext ( 'aws.isInternalUser' , this . isInternalAmazonUser ( ) )
253+
226254 return conn
227255 }
228256
@@ -373,6 +401,7 @@ export class Auth implements AuthService, ConnectionManager {
373401 }
374402 }
375403 this . #onDidDeleteConnection. fire ( { connId, storedProfile : profile } )
404+ await setContext ( 'aws.isInternalUser' , false )
376405 }
377406
378407 @withTelemetryContext ( { name : 'clearStaleLinkedIamConnections' , class : authClassName } )
@@ -405,6 +434,7 @@ export class Auth implements AuthService, ConnectionManager {
405434 await provider . invalidate ( 'devModeManualExpiration' )
406435 // updates the state of the connection
407436 await this . refreshConnectionState ( conn )
437+ await setContext ( 'aws.isInternalUser' , false )
408438 }
409439
410440 public async getConnection ( connection : Pick < Connection , 'id' > ) : Promise < Connection | undefined > {
0 commit comments