Skip to content

Commit f3c7d99

Browse files
committed
fix snake case and fix updateIamProfile
1 parent 903c22a commit f3c7d99

File tree

10 files changed

+29
-43
lines changed

10 files changed

+29
-43
lines changed

packages/amazonq/test/e2e/amazonq/utils/setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ export async function loginToIdC() {
2222
)
2323
}
2424

25-
await AuthUtil.instance.login_sso(startUrl, region)
25+
await AuthUtil.instance.loginSso(startUrl, region)
2626
}

packages/amazonq/test/unit/codewhisperer/region/regionProfileManager.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ describe('RegionProfileManager', async function () {
2626

2727
async function setupConnection(type: 'builderId' | 'idc') {
2828
if (type === 'builderId') {
29-
await AuthUtil.instance.login_sso(constants.builderIdStartUrl, region)
29+
await AuthUtil.instance.loginSso(constants.builderIdStartUrl, region)
3030
assert.ok(AuthUtil.instance.isSsoSession())
3131
assert.ok(AuthUtil.instance.isBuilderIdConnection())
3232
} else if (type === 'idc') {
33-
await AuthUtil.instance.login_sso(enterpriseSsoStartUrl, region)
33+
await AuthUtil.instance.loginSso(enterpriseSsoStartUrl, region)
3434
assert.ok(AuthUtil.instance.isSsoSession())
3535
assert.ok(AuthUtil.instance.isIdcConnection())
3636
}

packages/amazonq/test/unit/codewhisperer/util/authUtil.test.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,36 @@ describe('AuthUtil', async function () {
2626

2727
describe('Auth state', function () {
2828
it('login with BuilderId', async function () {
29-
await auth.login_sso(constants.builderIdStartUrl, constants.builderIdRegion)
29+
await auth.loginSso(constants.builderIdStartUrl, constants.builderIdRegion)
3030
assert.ok(auth.isConnected())
3131
assert.ok(auth.isBuilderIdConnection())
3232
})
3333

3434
it('login with IDC', async function () {
35-
await auth.login_sso('https://example.awsapps.com/start', 'us-east-1')
35+
await auth.loginSso('https://example.awsapps.com/start', 'us-east-1')
3636
assert.ok(auth.isConnected())
3737
assert.ok(auth.isIdcConnection())
3838
})
3939

4040
it('identifies internal users', async function () {
41-
await auth.login_sso(constants.internalStartUrl, 'us-east-1')
41+
await auth.loginSso(constants.internalStartUrl, 'us-east-1')
4242
assert.ok(auth.isInternalAmazonUser())
4343
})
4444

4545
it('identifies SSO session', async function () {
46-
await auth.login_sso(constants.internalStartUrl, 'us-east-1')
46+
await auth.loginSso(constants.internalStartUrl, 'us-east-1')
4747
assert.strictEqual(auth.isSsoSession(), true)
4848
})
4949

5050
it('identifies non-SSO session', async function () {
51-
await auth.login_iam('accessKey', 'secretKey', 'sessionToken')
51+
await auth.loginIam('accessKey', 'secretKey', 'sessionToken')
5252
assert.strictEqual(auth.isSsoSession(), false)
5353
})
5454
})
5555

5656
describe('Token management', function () {
5757
it('can get token when connected with SSO', async function () {
58-
await auth.login_sso(constants.builderIdStartUrl, constants.builderIdRegion)
58+
await auth.loginSso(constants.builderIdStartUrl, constants.builderIdRegion)
5959
const token = await auth.getToken()
6060
assert.ok(token)
6161
})
@@ -68,14 +68,14 @@ describe('AuthUtil', async function () {
6868

6969
describe('getTelemetryMetadata', function () {
7070
it('returns valid metadata for BuilderId connection', async function () {
71-
await auth.login_sso(constants.builderIdStartUrl, constants.builderIdRegion)
71+
await auth.loginSso(constants.builderIdStartUrl, constants.builderIdRegion)
7272
const metadata = await auth.getTelemetryMetadata()
7373
assert.strictEqual(metadata.credentialSourceId, 'awsId')
7474
assert.strictEqual(metadata.credentialStartUrl, constants.builderIdStartUrl)
7575
})
7676

7777
it('returns valid metadata for IDC connection', async function () {
78-
await auth.login_sso('https://example.awsapps.com/start', 'us-east-1')
78+
await auth.loginSso('https://example.awsapps.com/start', 'us-east-1')
7979
const metadata = await auth.getTelemetryMetadata()
8080
assert.strictEqual(metadata.credentialSourceId, 'iamIdentityCenter')
8181
assert.strictEqual(metadata.credentialStartUrl, 'https://example.awsapps.com/start')
@@ -96,7 +96,7 @@ describe('AuthUtil', async function () {
9696
})
9797

9898
it('returns BuilderId forms when using BuilderId', async function () {
99-
await auth.login_sso(constants.builderIdStartUrl, constants.builderIdRegion)
99+
await auth.loginSso(constants.builderIdStartUrl, constants.builderIdRegion)
100100
const forms = await auth.getAuthFormIds()
101101
assert.deepStrictEqual(forms, ['builderIdCodeWhisperer'])
102102
})
@@ -112,13 +112,13 @@ describe('AuthUtil', async function () {
112112
},
113113
})
114114

115-
await auth.login_sso('https://example.awsapps.com/start', 'us-east-1')
115+
await auth.loginSso('https://example.awsapps.com/start', 'us-east-1')
116116
const forms = await auth.getAuthFormIds()
117117
assert.deepStrictEqual(forms, ['identityCenterCodeWhisperer'])
118118
})
119119

120120
it('returns IDC forms with explorer when using IDC with SSO account access', async function () {
121-
await auth.login_sso('https://example.awsapps.com/start', 'us-east-1')
121+
await auth.loginSso('https://example.awsapps.com/start', 'us-east-1')
122122
const session = (auth as any).session
123123

124124
session &&
@@ -182,7 +182,7 @@ describe('AuthUtil', async function () {
182182
})
183183

184184
it('updates bearer token when state is refreshed', async function () {
185-
await auth.login_sso(constants.builderIdStartUrl, 'us-east-1')
185+
await auth.loginSso(constants.builderIdStartUrl, 'us-east-1')
186186

187187
await (auth as any).stateChangeHandler({ state: 'refreshed' })
188188

@@ -191,7 +191,7 @@ describe('AuthUtil', async function () {
191191
})
192192

193193
it('cleans up when connection expires', async function () {
194-
await auth.login_sso(constants.builderIdStartUrl, 'us-east-1')
194+
await auth.loginSso(constants.builderIdStartUrl, 'us-east-1')
195195

196196
await (auth as any).stateChangeHandler({ state: 'expired' })
197197

@@ -209,7 +209,7 @@ describe('AuthUtil', async function () {
209209
it('updates bearer token and restores profile on reconnection', async function () {
210210
const restoreProfileSelectionSpy = sinon.spy(regionProfileManager, 'restoreProfileSelection')
211211

212-
await auth.login_sso('https://example.awsapps.com/start', 'us-east-1')
212+
await auth.loginSso('https://example.awsapps.com/start', 'us-east-1')
213213

214214
await (auth as any).stateChangeHandler({ state: 'connected' })
215215

@@ -221,7 +221,7 @@ describe('AuthUtil', async function () {
221221
const invalidateProfileSpy = sinon.spy(regionProfileManager, 'invalidateProfile')
222222
const clearCacheSpy = sinon.spy(regionProfileManager, 'clearCache')
223223

224-
await auth.login_sso('https://example.awsapps.com/start', 'us-east-1')
224+
await auth.loginSso('https://example.awsapps.com/start', 'us-east-1')
225225

226226
await (auth as any).stateChangeHandler({ state: 'expired' })
227227

@@ -410,7 +410,7 @@ describe('AuthUtil', async function () {
410410
})
411411
})
412412

413-
describe('login_iam', function () {
413+
describe('loginIam', function () {
414414
it('creates IAM session and logs in', async function () {
415415
const mockResponse = {
416416
id: 'test-credential-id',
@@ -431,7 +431,7 @@ describe('AuthUtil', async function () {
431431

432432
sinon.stub(auth2, 'IamLogin').returns(mockIamLogin as any)
433433

434-
const response = await auth.login_iam('accessKey', 'secretKey', 'sessionToken')
434+
const response = await auth.loginIam('accessKey', 'secretKey', 'sessionToken')
435435

436436
assert.ok(mockIamLogin.login.calledOnce)
437437
assert.ok(

packages/amazonq/test/unit/codewhisperer/util/showSsoPrompt.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('showConnectionPrompt', function () {
2828
})
2929

3030
it('can select connect to AwsBuilderId', async function () {
31-
sinon.stub(AuthUtil.instance, 'login_sso').resolves()
31+
sinon.stub(AuthUtil.instance, 'loginSso').resolves()
3232

3333
getTestWindow().onDidShowQuickPick(async (picker) => {
3434
await picker.untilReady()
@@ -44,7 +44,7 @@ describe('showConnectionPrompt', function () {
4444

4545
it('connectToAwsBuilderId calls AuthUtil login with builderIdStartUrl', async function () {
4646
sinon.stub(vscode.commands, 'executeCommand')
47-
const loginStub = sinon.stub(AuthUtil.instance, 'login_sso').resolves()
47+
const loginStub = sinon.stub(AuthUtil.instance, 'loginSso').resolves()
4848

4949
await awsIdSignIn()
5050

packages/core/src/auth/auth2.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export class LanguageClientAuth {
178178
): Promise<UpdateProfileResult> {
179179
// Add credentials and delete SSO settings from profile
180180
let profile: Profile
181-
if (roleArn) {
181+
if (roleArn && sourceProfile) {
182182
profile = {
183183
kinds: [ProfileKind.IamSourceProfileProfile],
184184
name: profileName,
@@ -219,10 +219,6 @@ export class LanguageClientAuth {
219219
}
220220
return this.client.sendRequest(updateProfileRequestType.method, {
221221
profile: profile,
222-
ssoSession: {
223-
name: profileName,
224-
settings: undefined,
225-
},
226222
} satisfies UpdateProfileParams)
227223
}
228224

@@ -266,20 +262,10 @@ export class LanguageClientAuth {
266262
} satisfies InvalidateSsoTokenParams) as Promise<InvalidateSsoTokenResult>
267263
}
268264

269-
// invalidateStsCredential(tokenId: string) {
270-
// return this.client.sendRequest(invalidateStsCredentialRequestType.method, {
271-
// stsCredentialId: tokenId,
272-
// } satisfies InvalidateStsCredentialParams) as Promise<InvalidateStsCredentialResult>
273-
// }
274-
275265
registerSsoTokenChangedHandler(ssoTokenChangedHandler: (params: SsoTokenChangedParams) => any) {
276266
this.client.onNotification(ssoTokenChangedRequestType.method, ssoTokenChangedHandler)
277267
}
278268

279-
// registerStsCredentialChangedHandler(stsCredentialChangedHandler: (params: StsCredentialChangedParams) => any) {
280-
// this.client.onNotification(stsCredentialChangedRequestType.method, stsCredentialChangedHandler)
281-
// }
282-
283269
registerCacheWatcher(cacheChangedHandler: (event: cacheChangedEvent) => any) {
284270
this.cacheWatcher.onDidCreate(() => cacheChangedHandler('create'))
285271
this.cacheWatcher.onDidDelete(() => cacheChangedHandler('delete'))

packages/core/src/codewhisperer/ui/codeWhispererNodes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export function createSignIn(): DataQuickPickItem<'signIn'> {
271271
if (isWeb()) {
272272
// TODO: nkomonen, call a Command instead
273273
onClick = () => {
274-
void AuthUtil.instance.login_sso(builderIdStartUrl, builderIdRegion)
274+
void AuthUtil.instance.loginSso(builderIdStartUrl, builderIdRegion)
275275
}
276276
}
277277

packages/core/src/codewhisperer/util/authUtil.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export class AuthUtil implements IAuthProvider {
161161
}
162162

163163
// Log in using SSO
164-
async login_sso(startUrl: string, region: string): Promise<GetSsoTokenResult | undefined> {
164+
async loginSso(startUrl: string, region: string): Promise<GetSsoTokenResult | undefined> {
165165
let response: GetSsoTokenResult | undefined
166166
// Create SSO login session
167167
if (!this.isSsoSession()) {
@@ -174,7 +174,7 @@ export class AuthUtil implements IAuthProvider {
174174
}
175175

176176
// Log in using IAM or STS credentials
177-
async login_iam(
177+
async loginIam(
178178
accessKey: string,
179179
secretKey: string,
180180
sessionToken?: string

packages/core/src/codewhisperer/util/getStartUrl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const getStartUrl = async () => {
2929

3030
export async function connectToEnterpriseSso(startUrl: string, region: Region['id']) {
3131
try {
32-
await AuthUtil.instance.login_sso(startUrl, region)
32+
await AuthUtil.instance.loginSso(startUrl, region)
3333
} catch (e) {
3434
throw ToolkitError.chain(e, CodeWhispererConstants.failedToConnectIamIdentityCenter, {
3535
code: 'FailedToConnect',

packages/core/src/codewhisperer/util/showSsoPrompt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const showCodeWhispererConnectionPrompt = async () => {
4747
export async function awsIdSignIn() {
4848
getLogger().info('selected AWS ID sign in')
4949
try {
50-
await AuthUtil.instance.login_sso(builderIdStartUrl, builderIdRegion)
50+
await AuthUtil.instance.loginSso(builderIdStartUrl, builderIdRegion)
5151
} catch (e) {
5252
throw ToolkitError.chain(e, failedToConnectAwsBuilderId, { code: 'FailedToConnect' })
5353
}

packages/core/src/login/webview/vue/amazonq/backend_amazonq.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export class AmazonQLoginWebview extends CommonAuthWebview {
202202
// Defining separate auth function to emit telemetry before returning from this method
203203
const runAuth = async (): Promise<AuthError | undefined> => {
204204
try {
205-
await AuthUtil.instance.login_iam(accessKey, secretKey)
205+
await AuthUtil.instance.loginIam(accessKey, secretKey)
206206
} catch (e) {
207207
getLogger().error('Failed submitting credentials %O', e)
208208
return { id: this.id, text: e as string }

0 commit comments

Comments
 (0)