Skip to content

Commit b4221d9

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

File tree

8 files changed

+1207
-2227
lines changed

8 files changed

+1207
-2227
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: 71 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,36 @@
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,
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
/**
34-
* Resource parent information
31+
* Response type for getResources method
3532
*/
36-
export interface ParentResource {
37-
parentId: string
38-
parentType: string
33+
export interface GetResourcesResult {
34+
resources: Resource[]
35+
nextToken?: string
3936
}
4037

4138
/**
@@ -89,7 +86,7 @@ export async function createRedshiftConnectionConfig(
8986
}
9087

9188
// Determine auth type based on the provided parameters
92-
let authType: string
89+
let authType: DatabaseIntegrationConnectionAuthenticationTypes
9390

9491
if (secretArn) {
9592
authType = DatabaseIntegrationConnectionAuthenticationTypes.SECRET
@@ -118,11 +115,7 @@ export async function createRedshiftConnectionConfig(
118115
}
119116

120117
// Add auth object for SECRET authentication type
121-
if (
122-
(authType as DatabaseIntegrationConnectionAuthenticationTypes) ===
123-
DatabaseIntegrationConnectionAuthenticationTypes.SECRET &&
124-
secretArn
125-
) {
118+
if (authType === DatabaseIntegrationConnectionAuthenticationTypes.SECRET && secretArn) {
126119
connectionConfig.auth = { secretArn }
127120
}
128121

@@ -177,7 +170,7 @@ export class SQLWorkbenchClient {
177170
/**
178171
* Gets resources from SQL Workbench
179172
* @param params Request parameters
180-
* @returns Raw response from getResources API
173+
* @returns Response containing resources and optional next token
181174
*/
182175
public async getResources(params: {
183176
connection: ConnectionConfig
@@ -187,13 +180,13 @@ export class SQLWorkbenchClient {
187180
parents?: ParentResource[]
188181
pageToken?: string
189182
forceRefresh?: boolean
190-
}): Promise<SQLWorkbench.GetResourcesResponse> {
183+
}): Promise<GetResourcesResult> {
191184
try {
192185
this.logger.info(`SQLWorkbenchClient: Getting resources in region ${this.region}`)
193186

194187
const sqlClient = await this.getSQLClient()
195188

196-
const requestParams = {
189+
const requestParams: GetResourcesRequest = {
197190
connection: params.connection,
198191
type: params.resourceType,
199192
maxItems: params.maxItems || 100,
@@ -203,8 +196,9 @@ export class SQLWorkbenchClient {
203196
accountSettings: {},
204197
}
205198

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

209203
return {
210204
resources: response.resources || [],
@@ -228,26 +222,27 @@ export class SQLWorkbenchClient {
228222

229223
const sqlClient = await this.getSQLClient()
230224

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()
225+
const requestParams: ExecuteQueryRequest = {
226+
connection: connectionConfig,
227+
databaseType: 'REDSHIFT',
228+
accountSettings: {},
229+
executionContext: [
230+
{
231+
parentType: 'DATABASE',
232+
parentId: connectionConfig.database || '',
233+
},
234+
],
235+
query,
236+
queryExecutionType: 'NO_SESSION',
237+
queryResponseDeliveryType: 'ASYNC',
238+
maxItems: 100,
239+
ignoreHistory: true,
240+
tabId: 'data_explorer',
241+
}
242+
243+
// Call the ExecuteQuery API using SDK v3 Command pattern
244+
const command = new ExecuteQueryCommand(requestParams)
245+
const response = await sqlClient.send(command)
251246

252247
// Log the response
253248
this.logger.info(
@@ -261,9 +256,6 @@ export class SQLWorkbenchClient {
261256
}
262257
}
263258

264-
/**
265-
* Gets the SQL client, initializing it if necessary
266-
*/
267259
/**
268260
* Gets the SQL Workbench endpoint URL for the given region
269261
* @param region AWS region
@@ -273,6 +265,9 @@ export class SQLWorkbenchClient {
273265
return `https://api-v2.sqlworkbench.${region}.amazonaws.com`
274266
}
275267

268+
/**
269+
* Gets the SQL client, initializing it if necessary
270+
*/
276271
private async getSQLClient(): Promise<SQLWorkbench> {
277272
if (!this.sqlClient) {
278273
try {
@@ -281,30 +276,27 @@ export class SQLWorkbenchClient {
281276
this.logger.info(`Using SQL Workbench endpoint: ${endpoint}`)
282277

283278
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
279+
// Create client with credential provider function for auto-refresh
280+
const awsCredentialProvider = async () => {
281+
const credentials = await this.connectionCredentialsProvider!.getCredentials()
282+
return {
283+
accessKeyId: credentials.accessKeyId,
284+
secretAccessKey: credentials.secretAccessKey,
285+
sessionToken: credentials.sessionToken,
286+
expiration: credentials.expiration,
287+
}
288+
}
289+
this.sqlClient = new SQLWorkbench({
290+
region: this.region,
291+
endpoint: endpoint,
292+
credentials: awsCredentialProvider,
293+
})
296294
} 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
295+
// Use default credentials
296+
this.sqlClient = new SQLWorkbench({
297+
region: this.region,
298+
endpoint: endpoint,
299+
})
308300
}
309301

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

0 commit comments

Comments
 (0)