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'
96import { 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'
1219import { v4 as uuidv4 } from 'uuid'
1320import { getRedshiftTypeFromHost } from '../../explorer/nodes/utils'
14- import { DatabaseIntegrationConnectionAuthenticationTypes , RedshiftType } from '../../explorer/nodes/types'
21+ import { RedshiftType } from '../../explorer/nodes/types'
1522import { 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