Skip to content

Commit 6747bca

Browse files
committed
Update references and fix unit tests
1 parent 31959d5 commit 6747bca

File tree

14 files changed

+578
-570
lines changed

14 files changed

+578
-570
lines changed

packages/amazonq/src/app/amazonqScan/chat/controller/controller.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import {
3333
} from '../../models/constants'
3434
import path from 'path'
3535
import { telemetry } from 'aws-core-vscode/telemetry'
36-
import { auth2 } from 'aws-core-vscode/auth'
3736

3837
export class ScanController {
3938
private readonly messenger: Messenger

packages/amazonq/src/extensionNode.ts

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -78,49 +78,49 @@ async function activateAmazonQNode(context: vscode.ExtensionContext) {
7878
await setupDevMode(context)
7979
await beta.activate(context)
8080

81+
// TODO: @opieter add telemetry
82+
8183
// TODO: Should probably emit for web as well.
8284
// Will the web metric look the same?
83-
telemetry.auth_userState.emit({
84-
passive: true,
85-
result: 'Succeeded',
86-
source: AuthUtils.ExtensionUse.instance.sourceForTelemetry(),
87-
...(await getAuthState()),
88-
})
89-
90-
void activateNotifications(context, getAuthState)
85+
// telemetry.auth_userState.emit({
86+
// passive: true,
87+
// result: 'Succeeded',
88+
// source: AuthUtils.ExtensionUse.instance.sourceForTelemetry(),
89+
// ...(await getAuthState()),
90+
// })
91+
92+
// void activateNotifications(context, getAuthState)
9193
}
9294

93-
async function getAuthState(): Promise<Omit<AuthUserState, 'source'>> {
94-
let authState: AuthState = 'disconnected'
95-
try {
96-
// May call connection validate functions that try to refresh the token.
97-
// This could result in network errors.
98-
authState = (await AuthUtil.instance._getChatAuthState(false)).codewhispererChat
99-
} catch (err) {
100-
if (
101-
isNetworkError(err) &&
102-
AuthUtil.instance.conn &&
103-
AuthUtil.instance.auth.getConnectionState(AuthUtil.instance.conn) === 'valid'
104-
) {
105-
authState = 'connectedWithNetworkError'
106-
} else {
107-
throw err
108-
}
109-
}
110-
const currConn = AuthUtil.instance.conn
111-
if (currConn !== undefined && !(isAnySsoConnection(currConn) || isSageMaker())) {
112-
getLogger().error(`Current Amazon Q connection is not SSO, type is: %s`, currConn?.type)
113-
}
114-
115-
return {
116-
authStatus:
117-
authState === 'connected' || authState === 'expired' || authState === 'connectedWithNetworkError'
118-
? authState
119-
: 'notConnected',
120-
authEnabledConnections: AuthUtils.getAuthFormIdsFromConnection(currConn).join(','),
121-
...(await getTelemetryMetadataForConn(currConn)),
122-
}
123-
}
95+
// async function getAuthState(): Promise<Omit<AuthUserState, 'source'>> {
96+
// let authState: AuthState = 'disconnected'
97+
// try {
98+
// // May call connection validate functions that try to refresh the token.
99+
// // This could result in network errors.
100+
// authState = AuthUtil.instance.getAuthState()
101+
// } catch (err) {
102+
// if (
103+
// isNetworkError(err) &&
104+
// AuthUtil.instance.isConnected()
105+
// ) {
106+
// authState = 'connectedWithNetworkError'
107+
// } else {
108+
// throw err
109+
// }
110+
// }
111+
// if (AuthUtil.instance.isConnected() && !(AuthUtil.instance.isSsoSession() || isSageMaker())) {
112+
// getLogger().error('Current Amazon Q connection is not SSO')
113+
// }
114+
115+
// return {
116+
// authStatus:
117+
// authState === 'connected' || authState === 'expired' || authState === 'connectedWithNetworkError'
118+
// ? authState
119+
// : 'notConnected',
120+
// authEnabledConnections: AuthUtils.getAuthFormIdsFromConnection(currConn).join(','),
121+
// ...(await getTelemetryMetadataForConn(currConn)),
122+
// }
123+
// }
124124

125125
/**
126126
* Some parts of this do not work in Web mode so we need to set Dev Mode up here.

packages/amazonq/src/inlineChat/provider/inlineChatProvider.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { codeWhispererClient } from 'aws-core-vscode/codewhisperer'
2525
import type { InlineChatEvent } from 'aws-core-vscode/codewhisperer'
2626
import { InlineTask } from '../controller/inlineTask'
2727
import { extractAuthFollowUp } from 'aws-core-vscode/amazonq'
28-
import { auth2 } from 'aws-core-vscode/auth'
2928

3029
export class InlineChatProvider {
3130
private readonly editorContextExtractor: EditorContextExtractor

packages/amazonq/src/lsp/client.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ import * as nls from 'vscode-nls'
88
import * as crypto from 'crypto'
99
import { LanguageClient, LanguageClientOptions } from 'vscode-languageclient'
1010
import { InlineCompletionManager } from '../app/inline/completion'
11-
import { AmazonQLspAuth, encryptionKey, notificationTypes } from './auth'
1211
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
1312
import { ConnectionMetadata } from '@aws/language-server-runtimes/protocol'
1413
import { Settings, oidcClientName, createServerOptions, globals, Experiments, Commands } from 'aws-core-vscode/shared'
1514
import { activate } from './chat/activation'
1615
import { AmazonQResourcePaths } from './lspInstaller'
16+
import { auth2 } from 'aws-core-vscode/auth'
1717

1818
const localize = nls.loadMessageBundle()
1919

20+
export const encryptionKey = crypto.randomBytes(32)
21+
2022
export async function startLanguageServer(
2123
extensionContext: vscode.ExtensionContext,
2224
resourcePaths: AmazonQResourcePaths
@@ -90,18 +92,15 @@ export async function startLanguageServer(
9092
const disposable = client.start()
9193
toDispose.push(disposable)
9294

93-
const auth = new AmazonQLspAuth(client)
94-
9595
return client.onReady().then(async () => {
9696
// Request handler for when the server wants to know about the clients auth connnection. Must be registered before the initial auth init call
97-
client.onRequest<ConnectionMetadata, Error>(notificationTypes.getConnectionMetadata.method, () => {
97+
client.onRequest<ConnectionMetadata, Error>(auth2.notificationTypes.getConnectionMetadata.method, () => {
9898
return {
9999
sso: {
100-
startUrl: AuthUtil.instance.auth.startUrl,
100+
startUrl: AuthUtil.instance.connection?.startUrl,
101101
},
102102
}
103103
})
104-
await auth.refreshConnection()
105104

106105
if (Experiments.instance.get('amazonqLSPInline', false)) {
107106
const inlineManager = new InlineCompletionManager(client)
@@ -120,17 +119,5 @@ export async function startLanguageServer(
120119
if (Experiments.instance.get('amazonqChatLSP', false)) {
121120
activate(client, encryptionKey, resourcePaths.ui)
122121
}
123-
124-
const refreshInterval = auth.startTokenRefreshInterval()
125-
126-
toDispose.push(
127-
AuthUtil.instance.auth.onDidChangeActiveConnection(async () => {
128-
await auth.refreshConnection()
129-
}),
130-
AuthUtil.instance.auth.onDidDeleteConnection(async () => {
131-
client.sendNotification(notificationTypes.deleteBearerToken.method)
132-
}),
133-
{ dispose: () => clearInterval(refreshInterval) }
134-
)
135122
})
136123
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
66

77
export async function loginToIdC() {
8-
const authState = await AuthUtil.instance.getChatAuthState()
8+
const authState = AuthUtil.instance.getAuthState()
99
if (process.env['AWS_TOOLKIT_AUTOMATION'] === 'local') {
10-
if (authState.amazonQ !== 'connected') {
10+
if (authState !== 'connected') {
1111
throw new Error('You will need to login manually before running tests.')
1212
}
1313
return
@@ -22,5 +22,5 @@ export async function loginToIdC() {
2222
)
2323
}
2424

25-
await AuthUtil.instance.connectToEnterpriseSso(startUrl, region)
25+
await AuthUtil.instance.login(startUrl, region)
2626
}

0 commit comments

Comments
 (0)