-
Notifications
You must be signed in to change notification settings - Fork 738
fix(amazonq): Developer Profiles not being sent to Flare Auth as expected #7293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
945c05f
520acb0
33a5736
6958c25
779501f
e2c4197
5965e1d
d46ad37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,8 @@ import { builderIdStartUrl, internalStartUrl } from '../../auth/sso/constants' | |
| import { VSCODE_EXTENSION_ID } from '../../shared/extensions' | ||
| import { RegionProfileManager } from '../region/regionProfileManager' | ||
| import { AuthFormId } from '../../login/webview/vue/types' | ||
| import { notifySelectDeveloperProfile } from '../region/utils' | ||
| import { once } from '../../shared/utilities/functionUtils' | ||
|
|
||
| const localize = nls.loadMessageBundle() | ||
|
|
||
|
|
@@ -91,9 +93,31 @@ export class AuthUtil implements IAuthProvider { | |
| return this.session.loginType === LoginTypes.SSO | ||
| } | ||
|
|
||
| /** | ||
| * HACK: Ideally we'd put {@link notifySelectDeveloperProfile} in to {@link restore}. | ||
| * But because {@link refreshState} is only called if !isConnected, we cannot do it since | ||
| * {@link notifySelectDeveloperProfile} needs {@link refreshState} to run so it can set | ||
| * the Bearer Token in the LSP first. | ||
| */ | ||
| didStartSignedIn = false | ||
|
|
||
| async restore() { | ||
| await this.session.restore() | ||
| if (!this.isConnected()) { | ||
| this.didStartSignedIn = this.isConnected() | ||
|
|
||
| // HACK: We noticed that if calling `refreshState()` here when the user was already signed in, something broke. | ||
| // So as a solution we only call it if they were not already signed in. | ||
| // | ||
| // But in the case where a user was already signed in, we allow `session.restore()` to trigger `refreshState()` through | ||
| // event emitters. | ||
| // This is unoptimal since `refreshState()` should be able to be called multiple times and still work. | ||
| // | ||
| // Because of this edge case, when `restore()` is called we cannot assume all Auth is setup when this function returns, | ||
| // since we may still be waiting on the event emitter to trigger the expected functions. | ||
| // | ||
| // TODO: Figure out why removing the if statement below causes things to break. Maybe we just need to | ||
| // promisify the call and any subsequent callers will not make a redundant call. | ||
| if (!this.didStartSignedIn) { | ||
| await this.refreshState() | ||
| } | ||
| } | ||
|
|
@@ -257,20 +281,24 @@ export class AuthUtil implements IAuthProvider { | |
|
|
||
| private async refreshState(state = this.getAuthState()) { | ||
| if (state === 'expired' || state === 'notConnected') { | ||
| this.lspAuth.deleteBearerToken() | ||
| if (this.isIdcConnection()) { | ||
| await this.regionProfileManager.invalidateProfile(this.regionProfileManager.activeRegionProfile?.arn) | ||
| await this.regionProfileManager.clearCache() | ||
| } | ||
| this.lspAuth.deleteBearerToken() | ||
| } | ||
| if (state === 'connected') { | ||
| const bearerTokenParams = (await this.session.getToken()).updateCredentialsParams | ||
| await this.lspAuth.updateBearerToken(bearerTokenParams) | ||
|
|
||
| if (this.isIdcConnection()) { | ||
| await this.regionProfileManager.restoreProfileSelection() | ||
| } | ||
| const bearerTokenParams = (await this.session.getToken()).updateCredentialsParams | ||
| await this.lspAuth.updateBearerToken(bearerTokenParams) | ||
| } | ||
|
|
||
| // regardless of state, send message at startup if user needs to select a Developer Profile | ||
| void this.tryNotifySelectDeveloperProfile() | ||
|
|
||
|
Comment on lines
+299
to
+301
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function, see below, only triggers once on startup, and any subsequent times it will not because of the use of |
||
| vsCodeState.isFreeTierLimitReached = false | ||
| await this.setVscodeContextProps(state) | ||
| await Promise.all([ | ||
|
|
@@ -283,6 +311,12 @@ export class AuthUtil implements IAuthProvider { | |
| } | ||
| } | ||
|
|
||
| private tryNotifySelectDeveloperProfile = once(async () => { | ||
| if (this.regionProfileManager.requireProfileSelection() && this.didStartSignedIn) { | ||
| await notifySelectDeveloperProfile() | ||
| } | ||
| }) | ||
|
|
||
| async getTelemetryMetadata(): Promise<TelemetryMetadata> { | ||
| if (!this.isConnected()) { | ||
| return { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there no race conditions in swapping the event emitter with the status update?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is unlikely (maybe impossible in this case), but when we fire the event emitter and have not updated
this.connectionStateto the correct value yet, something may attempt to read it after getting the event and it will be a stale value.I made this change initially though with the assumption that it may have had no actual impact.