@@ -59,13 +59,15 @@ import {
59
59
AwsConnection ,
60
60
scopesCodeWhispererCore ,
61
61
ProfileNotFoundError ,
62
+ isSsoConnection ,
62
63
} from './connection'
63
64
import { isSageMaker , isCloud9 , isAmazonQ } from '../shared/extensionUtilities'
64
65
import { telemetry } from '../shared/telemetry/telemetry'
65
66
import { randomUUID } from '../shared/crypto'
66
67
import { asStringifiedStack } from '../shared/telemetry/spans'
67
68
import { withTelemetryContext } from '../shared/telemetry/util'
68
69
import { DiskCacheError } from '../shared/utilities/cacheUtils'
70
+ import { setContext } from '../shared/vscode/setContext'
69
71
70
72
interface AuthService {
71
73
/**
@@ -166,6 +168,30 @@ export class Auth implements AuthService, ConnectionManager {
166
168
return this . #ssoCacheWatcher
167
169
}
168
170
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
+
169
195
/**
170
196
* Map startUrl -> declared connections
171
197
*/
@@ -223,6 +249,8 @@ export class Auth implements AuthService, ConnectionManager {
223
249
this . #onDidChangeActiveConnection. fire ( conn )
224
250
await this . store . setCurrentProfileId ( id )
225
251
252
+ await setContext ( 'aws.isInternalUser' , this . isInternalAmazonUser ( ) )
253
+
226
254
return conn
227
255
}
228
256
@@ -373,6 +401,7 @@ export class Auth implements AuthService, ConnectionManager {
373
401
}
374
402
}
375
403
this . #onDidDeleteConnection. fire ( { connId, storedProfile : profile } )
404
+ await setContext ( 'aws.isInternalUser' , false )
376
405
}
377
406
378
407
@withTelemetryContext ( { name : 'clearStaleLinkedIamConnections' , class : authClassName } )
@@ -405,6 +434,7 @@ export class Auth implements AuthService, ConnectionManager {
405
434
await provider . invalidate ( 'devModeManualExpiration' )
406
435
// updates the state of the connection
407
436
await this . refreshConnectionState ( conn )
437
+ await setContext ( 'aws.isInternalUser' , false )
408
438
}
409
439
410
440
public async getConnection ( connection : Pick < Connection , 'id' > ) : Promise < Connection | undefined > {
0 commit comments