Skip to content

Commit 844b206

Browse files
authored
refactor: sync types with IAM authentication changes (#626)
## Problem The IAM type changes are behind the changes in aws/language-servers#1869 and aws/language-servers#1846. As a result, the language-servers PRs are unable to compile. ## Solution This is part of #572. - Rename validatePermissions to permissionSets and make it accept a list of permissions instead of validating only 1 set of permissions - Wrap credentials from getIamCredentialResult into an intermediate object - Add credentials override and additional error codes to getIamCredentials - Add mfaSerial to GetMfaSerialResult and optionalize it in GetMfaSerialParams <!--- REMINDER: - Read CONTRIBUTING.md first. - Add test coverage for your changes. - Link to related issues/commits. - Testing: how did you test your changes? - Screenshots if applicable --> ## License By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent a2b8532 commit 844b206

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

runtimes/protocol/identity-management.ts

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,35 @@ export const AwsErrorCodes = {
3737
E_SSO_TOKEN_EXPIRED: 'E_SSO_TOKEN_EXPIRED',
3838
E_STS_CREDENTIAL_EXPIRED: 'E_STS_CREDENTIAL_EXPIRED',
3939
E_SSO_TOKEN_SOURCE_NOT_SUPPORTED: 'E_SSO_TOKEN_SOURCE_NOT_SUPPORTED',
40+
E_CALLER_IDENTITY_NOT_FOUND: 'E_CALLER_IDENTITY_NOT_FOUND',
4041
E_MFA_REQUIRED: 'E_MFA_REQUIRED',
42+
E_PERMISSION_DENIED: 'E_PERMISSION_DENIED',
4143
E_TIMEOUT: 'E_TIMEOUT',
4244
E_UNKNOWN: 'E_UNKNOWN',
4345
E_CANCELLED: 'E_CANCELLED',
4446
} as const
4547

48+
// Permissions
49+
export const PermissionSets = {
50+
Q: [
51+
'q:StartConversation',
52+
'q:SendMessage',
53+
'q:GetConversation',
54+
'q:ListConversations',
55+
'q:UpdateConversation',
56+
'q:DeleteConversation',
57+
'q:PassRequest',
58+
'q:StartTroubleshootingAnalysis',
59+
'q:StartTroubleshootingResolutionExplanation',
60+
'q:GetTroubleshootingResults',
61+
'q:UpdateTroubleshootingCommandResult',
62+
'q:GetIdentityMetaData',
63+
'q:GenerateCodeFromCommands',
64+
'q:UsePlugin',
65+
'codewhisperer:GenerateRecommendations',
66+
],
67+
}
68+
4669
export interface AwsResponseErrorData {
4770
awsErrorCode: string
4871
}
@@ -253,22 +276,29 @@ export type IamCredentialId = string // Opaque identifier
253276

254277
export interface GetIamCredentialOptions {
255278
callStsOnInvalidIamCredential?: boolean
256-
validatePermissions?: boolean
279+
permissionSet?: string[]
280+
credentialOverride?: IamCredentials
257281
}
258282

259283
export const getIamCredentialOptionsDefaults = {
260284
callStsOnInvalidIamCredential: true,
261-
validatePermissions: true,
285+
permissionSet: PermissionSets.Q,
286+
credentialOverride: undefined,
262287
} satisfies GetIamCredentialOptions
263288

264289
export interface GetIamCredentialParams {
265290
profileName: string
266291
options?: GetIamCredentialOptions
267292
}
268293

269-
export interface GetIamCredentialResult {
294+
export interface IamCredential {
270295
id: IamCredentialId
296+
kinds: ProfileKind[]
271297
credentials: IamCredentials
298+
}
299+
300+
export interface GetIamCredentialResult {
301+
credential: IamCredential
272302
updateCredentialsParams: UpdateCredentialsParams
273303
}
274304

@@ -282,12 +312,13 @@ export const getIamCredentialRequestType = new ProtocolRequestType<
282312

283313
// getMfaCode
284314
export interface GetMfaCodeParams {
285-
mfaSerial: string
286315
profileName: string
316+
mfaSerial?: string
287317
}
288318

289319
export interface GetMfaCodeResult {
290320
code: string
321+
mfaSerial: string
291322
}
292323

293324
export const getMfaCodeRequestType = new ProtocolRequestType<
@@ -318,7 +349,7 @@ export const invalidateSsoTokenRequestType = new ProtocolRequestType<
318349

319350
// invalidateStsCredential
320351
export interface InvalidateStsCredentialParams {
321-
profileName: string
352+
iamCredentialId: IamCredentialId
322353
}
323354

324355
export interface InvalidateStsCredentialResult {

runtimes/runtimes/auth/standalone/encryption.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ export async function encryptIamResultWithKey(
124124
request: GetIamCredentialResult,
125125
key: string
126126
): Promise<GetIamCredentialResult> {
127-
request.credentials = {
128-
accessKeyId: await encryptObjectWithKey(request.credentials.accessKeyId, key),
129-
secretAccessKey: await encryptObjectWithKey(request.credentials.secretAccessKey, key),
130-
...(request.credentials.sessionToken
131-
? { sessionToken: await encryptObjectWithKey(request.credentials.sessionToken, key) }
127+
request.credential.credentials = {
128+
accessKeyId: await encryptObjectWithKey(request.credential.credentials.accessKeyId, key),
129+
secretAccessKey: await encryptObjectWithKey(request.credential.credentials.secretAccessKey, key),
130+
...(request.credential.credentials.sessionToken
131+
? { sessionToken: await encryptObjectWithKey(request.credential.credentials.sessionToken, key) }
132132
: {}),
133133
}
134134
if (!request.updateCredentialsParams.encrypted) {

0 commit comments

Comments
 (0)