Skip to content

Commit 2dabb43

Browse files
committed
fix(amazonq): delete iam profile when logout
1 parent e923bad commit 2dabb43

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

aws-toolkit-vscode.code-workspace

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
"path": "packages/amazonq",
1414
},
1515
{
16-
"path": "../language-servers",
16+
"path": "../language-server-runtimes",
1717
},
1818
{
19-
"path": "../language-server-runtimes",
19+
"path": "../language-servers",
2020
},
2121
],
2222
"settings": {

packages/core/src/auth/auth2.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@ import {
1212
GetIamCredentialParams,
1313
getIamCredentialRequestType,
1414
GetIamCredentialResult,
15+
InvalidateIamCredentialResult,
1516
IamIdentityCenterSsoTokenSource,
1617
InvalidateSsoTokenParams,
18+
InvalidateIamCredentialParams,
1719
invalidateSsoTokenRequestType,
20+
invalidateIamCredentialRequestType,
1821
ProfileKind,
1922
UpdateProfileParams,
2023
updateProfileRequestType,
24+
DeleteProfileParams,
25+
deleteProfileRequestType,
2126
SsoTokenChangedParams,
2227
// StsCredentialChangedParams,
2328
ssoTokenChangedRequestType,
@@ -45,6 +50,7 @@ import {
4550
iamCredentialsUpdateRequestType,
4651
Profile,
4752
SsoSession,
53+
DeleteProfileResult,
4854
// invalidateStsCredentialRequestType,
4955
// InvalidateStsCredentialParams,
5056
// InvalidateStsCredentialResult,
@@ -187,6 +193,12 @@ export class LanguageClientAuth {
187193
} satisfies UpdateProfileParams)
188194
}
189195

196+
deleteIamProfile(name: string): Promise<DeleteProfileResult> {
197+
return this.client.sendRequest(deleteProfileRequestType.method, {
198+
profileName: name,
199+
} satisfies DeleteProfileParams)
200+
}
201+
190202
listProfiles() {
191203
return this.client.sendRequest(listProfilesRequestType.method, {}) as Promise<ListProfilesResult>
192204
}
@@ -227,6 +239,12 @@ export class LanguageClientAuth {
227239
} satisfies InvalidateSsoTokenParams) as Promise<InvalidateSsoTokenResult>
228240
}
229241

242+
invalidateIamCredential(tokenId: string) {
243+
return this.client.sendRequest(invalidateIamCredentialRequestType.method, {
244+
iamCredentialsId: tokenId,
245+
} satisfies InvalidateIamCredentialParams) as Promise<InvalidateIamCredentialResult>
246+
}
247+
230248
// invalidateStsCredential(tokenId: string) {
231249
// return this.client.sendRequest(invalidateStsCredentialRequestType.method, {
232250
// stsCredentialId: tokenId,
@@ -464,7 +482,7 @@ export class SsoLogin extends BaseLogin {
464482
*/
465483
export class IamLogin extends BaseLogin {
466484
// Cached information from the identity server for easy reference
467-
// private iamCredentialId: string | undefined
485+
private iamCredentialId: string | undefined
468486

469487
constructor(profileName: string, lspAuth: LanguageClientAuth, eventEmitter: vscode.EventEmitter<AuthStateEvent>) {
470488
super(profileName, lspAuth, eventEmitter)
@@ -486,9 +504,10 @@ export class IamLogin extends BaseLogin {
486504
}
487505

488506
async logout() {
489-
// if (this.stsCredentialId) {
490-
// await this.lspAuth.invalidateStsCredential(this.iamCredentialId)
491-
// }
507+
if (this.iamCredentialId) {
508+
await this.lspAuth.invalidateIamCredential(this.iamCredentialId)
509+
}
510+
await this.deleteProfile(this.profileName)
492511
this.updateConnectionState('notConnected')
493512
this._data = undefined
494513
// TODO: DeleteProfile api in Identity Service (this doesn't exist yet)
@@ -502,6 +521,10 @@ export class IamLogin extends BaseLogin {
502521
}
503522
}
504523

524+
async deleteProfile(profileName: string) {
525+
await this.lspAuth.deleteIamProfile(profileName)
526+
}
527+
505528
/**
506529
* Restore the connection state and connection details to memory, if they exist.
507530
*/

0 commit comments

Comments
 (0)