Skip to content
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

fix(amazonq): Update initializationOptions extension name #6468

Open
wants to merge 1 commit into
base: feature/amazonqLSP
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/amazonq/src/lsp/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { AmazonQLspAuth, encryptionKey, notificationTypes } from './auth'
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
import { ConnectionMetadata } from '@aws/language-server-runtimes/protocol'
import { ResourcePaths, createServerOptions } from 'aws-core-vscode/shared'
import { AuthUtils } from 'aws-core-vscode/auth'

const localize = nls.loadMessageBundle()

Expand Down Expand Up @@ -45,7 +46,7 @@ export async function startLanguageServer(extensionContext: vscode.ExtensionCont
name: env.appName,
version: version,
extension: {
name: `AWS IDE Extensions for VSCode`, // TODO change this to C9/Amazon
name: AuthUtils.clientName(),
version: '0.0.1',
},
clientId: crypto.randomUUID(),
Expand Down
12 changes: 5 additions & 7 deletions packages/core/src/auth/sso/ssoAccessTokenProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { AwsLoginWithBrowser, AwsRefreshCredentials, telemetry } from '../../sha
import { indent, toBase64URL } from '../../shared/utilities/textUtilities'
import { AuthSSOServer } from './server'
import { CancellationError, sleep } from '../../shared/utilities/timeoutUtils'
import { getIdeProperties, isAmazonQ, isCloud9 } from '../../shared/extensionUtilities'
import { isAmazonQ } from '../../shared/extensionUtilities'
import { randomBytes, createHash } from 'crypto'
import { localize } from '../../shared/utilities/vsCodeUtils'
import { randomUUID } from '../../shared/crypto'
Expand All @@ -39,6 +39,7 @@ import { asStringifiedStack } from '../../shared/telemetry/spans'
import { showViewLogsMessage } from '../../shared/utilities/messages'
import _ from 'lodash'
import { builderIdStartUrl } from './constants'
import { clientName } from '../utils'

export const authenticationPath = 'sso/authenticated'

Expand Down Expand Up @@ -451,10 +452,9 @@ function getSessionDuration(id: string) {
*/
export class DeviceFlowAuthorization extends SsoAccessTokenProvider {
override async registerClient(): Promise<ClientRegistration> {
const companyName = getIdeProperties().company
return this.oidc.registerClient(
{
clientName: isCloud9() ? `${companyName} Cloud9` : `${companyName} IDE Extensions for VSCode`,
clientName: clientName(),
clientType: clientRegistrationType,
scopes: this.profile.scopes,
},
Expand Down Expand Up @@ -556,11 +556,10 @@ export class DeviceFlowAuthorization extends SsoAccessTokenProvider {
*/
class AuthFlowAuthorization extends SsoAccessTokenProvider {
override async registerClient(): Promise<ClientRegistration> {
const companyName = getIdeProperties().company
return this.oidc.registerClient(
{
// All AWS extensions (Q, Toolkit) for a given IDE use the same client name.
clientName: isCloud9() ? `${companyName} Cloud9` : `${companyName} IDE Extensions for VSCode`,
clientName: clientName(),
clientType: clientRegistrationType,
scopes: this.profile.scopes,
grantTypes: [authorizationGrantType, refreshGrantType],
Expand Down Expand Up @@ -666,11 +665,10 @@ class WebAuthorization extends SsoAccessTokenProvider {
private redirectUri = 'http://127.0.0.1:54321/oauth/callback'

override async registerClient(): Promise<ClientRegistration> {
const companyName = getIdeProperties().company
return this.oidc.registerClient(
{
// All AWS extensions (Q, Toolkit) for a given IDE use the same client name.
clientName: isCloud9() ? `${companyName} Cloud9` : `${companyName} IDE Extensions for VSCode`,
clientName: clientName(),
clientType: clientRegistrationType,
scopes: this.profile.scopes,
grantTypes: [authorizationGrantType, refreshGrantType],
Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/auth/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { TreeNode } from '../shared/treeview/resourceTreeDataProvider'
import { createInputBox } from '../shared/ui/inputPrompter'
import { CredentialSourceId, telemetry } from '../shared/telemetry/telemetry'
import { createCommonButtons, createExitButton, createHelpButton, createRefreshButton } from '../shared/ui/buttons'
import { getIdeProperties, isAmazonQ } from '../shared/extensionUtilities'
import { getIdeProperties, isAmazonQ, isCloud9 } from '../shared/extensionUtilities'
import { addScopes, getDependentAuths } from './secondaryAuth'
import { DevSettings } from '../shared/settings'
import { createRegionPrompter } from '../shared/ui/common/region'
Expand Down Expand Up @@ -60,6 +60,7 @@ import { EnvVarsCredentialsProvider } from './providers/envVarsCredentialsProvid
import { showMessageWithUrl } from '../shared/utilities/messages'
import { credentialHelpUrl } from '../shared/constants'
import { ExtStartUpSource } from '../shared/telemetry/util'
import { once } from '../shared/utilities/functionUtils'

// iam-only excludes Builder ID and IAM Identity Center from the list of valid connections
// TODO: Understand if "iam" should include these from the list at all
Expand Down Expand Up @@ -800,3 +801,9 @@ export async function getAuthType() {
}
return authType
}

export const clientName = once(_clientName)
function _clientName() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cleaning this up! Should it live in extensionUtilities next to the other similar functions (productName(), etc)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering that as well. On the one hand the current implementation keeps it next to auth and I'm not sure that non-auth projects have a use for this? On the other hand like you mentioned, productName() etc lives in extensionUtils. I'm fine with either tbh

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps mention this new function in the docstring of productName(), and vice-versa?

const companyName = getIdeProperties().company
return isCloud9() ? `${companyName} Cloud9` : `${companyName} IDE Extensions for VSCode`
}
Loading