Skip to content

Commit d7f13ec

Browse files
committed
feat(smus): Upgrade sdk v2 to sdk v3 - SQLWorkbench
1 parent 75d1f24 commit d7f13ec

File tree

8 files changed

+1212
-2226
lines changed

8 files changed

+1212
-2226
lines changed

package-lock.json

Lines changed: 1095 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@
581581
"@amzn/amazon-q-developer-streaming-client": "file:../../src.gen/@amzn/amazon-q-developer-streaming-client",
582582
"@amzn/codewhisperer-streaming": "file:../../src.gen/@amzn/codewhisperer-streaming",
583583
"@amzn/sagemaker-client": "file:../../src.gen/@amzn/sagemaker-client/1.0.0.tgz",
584+
"@amzn/sql-workbench-client": "file:../../src.gen/@amzn/sql-workbench-client/3.0.0.tgz",
584585
"@aws-sdk/client-accessanalyzer": "^3.888.0",
585586
"@aws-sdk/client-api-gateway": "<3.731.0",
586587
"@aws-sdk/client-apprunner": "<3.731.0",

packages/core/scripts/build/generateServiceClient.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,6 @@ void (async () => {
245245
serviceJsonPath: 'src/sagemakerunifiedstudio/shared/client/gluecatalogapi.json',
246246
serviceName: 'GlueCatalogApi',
247247
},
248-
{
249-
serviceJsonPath: 'src/sagemakerunifiedstudio/shared/client/sqlworkbench.json',
250-
serviceName: 'SQLWorkbench',
251-
},
252248
{
253249
serviceJsonPath: 'src/sagemakerunifiedstudio/shared/client/datazonecustomclient.json',
254250
serviceName: 'DataZoneCustomClient',

packages/core/src/sagemakerunifiedstudio/explorer/nodes/redshiftStrategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ function createSchemaNode(schemaName: string, connectionConfig: ConnectionConfig
458458
parentType: ResourceType.SCHEMA,
459459
},
460460
{
461-
parentId: schemaConnectionConfig.database,
461+
parentId: schemaConnectionConfig.database || '',
462462
parentType: ResourceType.DATABASE,
463463
},
464464
],

packages/core/src/sagemakerunifiedstudio/shared/client/sqlWorkbenchClient.ts

Lines changed: 76 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,42 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { Service } from 'aws-sdk'
7-
import { ServiceConfigurationOptions } from 'aws-sdk/lib/service'
8-
import globals from '../../../shared/extensionGlobals'
96
import { getLogger } from '../../../shared/logger/logger'
10-
import * as SQLWorkbench from './sqlworkbench'
11-
import apiConfig = require('./sqlworkbench.json')
7+
import {
8+
SQLWorkbench,
9+
GetResourcesCommand,
10+
ExecuteQueryCommand,
11+
GetResourcesRequest,
12+
GetResourcesResponse,
13+
ExecuteQueryRequest,
14+
DatabaseConnectionConfiguration,
15+
ParentResource as SDKParentResource,
16+
Resource,
17+
DatabaseIntegrationConnectionAuthenticationTypes,
18+
} from '@amzn/sql-workbench-client'
1219
import { v4 as uuidv4 } from 'uuid'
1320
import { getRedshiftTypeFromHost } from '../../explorer/nodes/utils'
14-
import { DatabaseIntegrationConnectionAuthenticationTypes, RedshiftType } from '../../explorer/nodes/types'
21+
import { RedshiftType } from '../../explorer/nodes/types'
1522
import { ConnectionCredentialsProvider } from '../../auth/providers/connectionCredentialsProvider'
16-
import { adaptConnectionCredentialsProvider } from './credentialsAdapter'
1723

1824
/**
1925
* Connection configuration for SQL Workbench
26+
* This is an alias for the SDK's DatabaseConnectionConfiguration type
2027
*/
21-
export interface ConnectionConfig {
22-
id: string
23-
type: string
24-
databaseType: string
25-
connectableResourceIdentifier: string
26-
connectableResourceType: string
27-
database: string
28-
auth?: {
29-
secretArn?: string
30-
}
31-
}
28+
export type ConnectionConfig = DatabaseConnectionConfiguration
3229

3330
/**
3431
* Resource parent information
32+
* This is an alias for the SDK's ParentResource type
3533
*/
36-
export interface ParentResource {
37-
parentId: string
38-
parentType: string
34+
export type ParentResource = SDKParentResource
35+
36+
/**
37+
* Response type for getResources method
38+
*/
39+
export interface GetResourcesResult {
40+
resources: Resource[]
41+
nextToken?: string
3942
}
4043

4144
/**
@@ -89,7 +92,7 @@ export async function createRedshiftConnectionConfig(
8992
}
9093

9194
// Determine auth type based on the provided parameters
92-
let authType: string
95+
let authType: DatabaseIntegrationConnectionAuthenticationTypes
9396

9497
if (secretArn) {
9598
authType = DatabaseIntegrationConnectionAuthenticationTypes.SECRET
@@ -118,11 +121,7 @@ export async function createRedshiftConnectionConfig(
118121
}
119122

120123
// Add auth object for SECRET authentication type
121-
if (
122-
(authType as DatabaseIntegrationConnectionAuthenticationTypes) ===
123-
DatabaseIntegrationConnectionAuthenticationTypes.SECRET &&
124-
secretArn
125-
) {
124+
if (authType === DatabaseIntegrationConnectionAuthenticationTypes.SECRET && secretArn) {
126125
connectionConfig.auth = { secretArn }
127126
}
128127

@@ -177,7 +176,7 @@ export class SQLWorkbenchClient {
177176
/**
178177
* Gets resources from SQL Workbench
179178
* @param params Request parameters
180-
* @returns Raw response from getResources API
179+
* @returns Response containing resources and optional next token
181180
*/
182181
public async getResources(params: {
183182
connection: ConnectionConfig
@@ -187,13 +186,13 @@ export class SQLWorkbenchClient {
187186
parents?: ParentResource[]
188187
pageToken?: string
189188
forceRefresh?: boolean
190-
}): Promise<SQLWorkbench.GetResourcesResponse> {
189+
}): Promise<GetResourcesResult> {
191190
try {
192191
this.logger.info(`SQLWorkbenchClient: Getting resources in region ${this.region}`)
193192

194193
const sqlClient = await this.getSQLClient()
195194

196-
const requestParams = {
195+
const requestParams: GetResourcesRequest = {
197196
connection: params.connection,
198197
type: params.resourceType,
199198
maxItems: params.maxItems || 100,
@@ -203,8 +202,9 @@ export class SQLWorkbenchClient {
203202
accountSettings: {},
204203
}
205204

206-
// Call the GetResources API
207-
const response = await sqlClient.getResources(requestParams).promise()
205+
// Call the GetResources API using SDK v3 Command pattern
206+
const command = new GetResourcesCommand(requestParams)
207+
const response: GetResourcesResponse = await sqlClient.send(command)
208208

209209
return {
210210
resources: response.resources || [],
@@ -228,26 +228,27 @@ export class SQLWorkbenchClient {
228228

229229
const sqlClient = await this.getSQLClient()
230230

231-
// Call the ExecuteQuery API
232-
const response = await sqlClient
233-
.executeQuery({
234-
connection: connectionConfig as any,
235-
databaseType: 'REDSHIFT',
236-
accountSettings: {},
237-
executionContext: [
238-
{
239-
parentType: 'DATABASE',
240-
parentId: connectionConfig.database || '',
241-
},
242-
],
243-
query,
244-
queryExecutionType: 'NO_SESSION',
245-
queryResponseDeliveryType: 'ASYNC',
246-
maxItems: 100,
247-
ignoreHistory: true,
248-
tabId: 'data_explorer',
249-
})
250-
.promise()
231+
const requestParams: ExecuteQueryRequest = {
232+
connection: connectionConfig,
233+
databaseType: 'REDSHIFT',
234+
accountSettings: {},
235+
executionContext: [
236+
{
237+
parentType: 'DATABASE',
238+
parentId: connectionConfig.database || '',
239+
},
240+
],
241+
query,
242+
queryExecutionType: 'NO_SESSION',
243+
queryResponseDeliveryType: 'ASYNC',
244+
maxItems: 100,
245+
ignoreHistory: true,
246+
tabId: 'data_explorer',
247+
}
248+
249+
// Call the ExecuteQuery API using SDK v3 Command pattern
250+
const command = new ExecuteQueryCommand(requestParams)
251+
const response = await sqlClient.send(command)
251252

252253
// Log the response
253254
this.logger.info(
@@ -261,9 +262,6 @@ export class SQLWorkbenchClient {
261262
}
262263
}
263264

264-
/**
265-
* Gets the SQL client, initializing it if necessary
266-
*/
267265
/**
268266
* Gets the SQL Workbench endpoint URL for the given region
269267
* @param region AWS region
@@ -273,6 +271,9 @@ export class SQLWorkbenchClient {
273271
return `https://api-v2.sqlworkbench.${region}.amazonaws.com`
274272
}
275273

274+
/**
275+
* Gets the SQL client, initializing it if necessary
276+
*/
276277
private async getSQLClient(): Promise<SQLWorkbench> {
277278
if (!this.sqlClient) {
278279
try {
@@ -281,30 +282,27 @@ export class SQLWorkbenchClient {
281282
this.logger.info(`Using SQL Workbench endpoint: ${endpoint}`)
282283

283284
if (this.connectionCredentialsProvider) {
284-
// Create client with provided credentials
285-
this.sqlClient = (await globals.sdkClientBuilder.createAwsService(
286-
Service,
287-
{
288-
apiConfig: apiConfig,
289-
region: this.region,
290-
endpoint: endpoint,
291-
credentialProvider: adaptConnectionCredentialsProvider(this.connectionCredentialsProvider),
292-
} as ServiceConfigurationOptions,
293-
undefined,
294-
false
295-
)) as SQLWorkbench
285+
// Create client with credential provider function for auto-refresh
286+
const awsCredentialProvider = async () => {
287+
const credentials = await this.connectionCredentialsProvider!.getCredentials()
288+
return {
289+
accessKeyId: credentials.accessKeyId,
290+
secretAccessKey: credentials.secretAccessKey,
291+
sessionToken: credentials.sessionToken,
292+
expiration: credentials.expiration,
293+
}
294+
}
295+
this.sqlClient = new SQLWorkbench({
296+
region: this.region,
297+
endpoint: endpoint,
298+
credentials: awsCredentialProvider,
299+
})
296300
} else {
297-
// Use the SDK client builder for default credentials
298-
this.sqlClient = (await globals.sdkClientBuilder.createAwsService(
299-
Service,
300-
{
301-
apiConfig: apiConfig,
302-
region: this.region,
303-
endpoint: endpoint,
304-
} as ServiceConfigurationOptions,
305-
undefined,
306-
false
307-
)) as SQLWorkbench
301+
// Use default credentials
302+
this.sqlClient = new SQLWorkbench({
303+
region: this.region,
304+
endpoint: endpoint,
305+
})
308306
}
309307

310308
this.logger.debug('SQLWorkbenchClient: Successfully created SQL client')

0 commit comments

Comments
 (0)