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+ DatabaseIntegrationConnectionAuthenticationTypes ,
17+ } from '@amzn/sql-workbench-client'
1218import { v4 as uuidv4 } from 'uuid'
1319import { getRedshiftTypeFromHost } from '../../explorer/nodes/utils'
14- import { DatabaseIntegrationConnectionAuthenticationTypes , RedshiftType } from '../../explorer/nodes/types'
20+ import { RedshiftType } from '../../explorer/nodes/types'
1521import { ConnectionCredentialsProvider } from '../../auth/providers/connectionCredentialsProvider'
16- import { adaptConnectionCredentialsProvider } from './credentialsAdapter'
1722
1823/**
1924 * Connection configuration for SQL Workbench
25+ * This is an alias for the SDK's DatabaseConnectionConfiguration type
2026 */
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- }
32-
33- /**
34- * Resource parent information
35- */
36- export interface ParentResource {
37- parentId : string
38- parentType : string
39- }
27+ export type ConnectionConfig = DatabaseConnectionConfiguration
4028
4129/**
4230 * Gets a SQL Workbench ARN
@@ -89,7 +77,7 @@ export async function createRedshiftConnectionConfig(
8977 }
9078
9179 // Determine auth type based on the provided parameters
92- let authType : string
80+ let authType : DatabaseIntegrationConnectionAuthenticationTypes
9381
9482 if ( secretArn ) {
9583 authType = DatabaseIntegrationConnectionAuthenticationTypes . SECRET
@@ -118,11 +106,7 @@ export async function createRedshiftConnectionConfig(
118106 }
119107
120108 // Add auth object for SECRET authentication type
121- if (
122- ( authType as DatabaseIntegrationConnectionAuthenticationTypes ) ===
123- DatabaseIntegrationConnectionAuthenticationTypes . SECRET &&
124- secretArn
125- ) {
109+ if ( authType === DatabaseIntegrationConnectionAuthenticationTypes . SECRET && secretArn ) {
126110 connectionConfig . auth = { secretArn }
127111 }
128112
@@ -177,7 +161,7 @@ export class SQLWorkbenchClient {
177161 /**
178162 * Gets resources from SQL Workbench
179163 * @param params Request parameters
180- * @returns Raw response from getResources API
164+ * @returns Response containing resources and optional next token
181165 */
182166 public async getResources ( params : {
183167 connection : ConnectionConfig
@@ -187,13 +171,13 @@ export class SQLWorkbenchClient {
187171 parents ?: ParentResource [ ]
188172 pageToken ?: string
189173 forceRefresh ?: boolean
190- } ) : Promise < SQLWorkbench . GetResourcesResponse > {
174+ } ) : Promise < GetResourcesResponse > {
191175 try {
192176 this . logger . info ( `SQLWorkbenchClient: Getting resources in region ${ this . region } ` )
193177
194178 const sqlClient = await this . getSQLClient ( )
195179
196- const requestParams = {
180+ const requestParams : GetResourcesRequest = {
197181 connection : params . connection ,
198182 type : params . resourceType ,
199183 maxItems : params . maxItems || 100 ,
@@ -203,13 +187,9 @@ export class SQLWorkbenchClient {
203187 accountSettings : { } ,
204188 }
205189
206- // Call the GetResources API
207- const response = await sqlClient . getResources ( requestParams ) . promise ( )
208-
209- return {
210- resources : response . resources || [ ] ,
211- nextToken : response . nextToken ,
212- }
190+ // Call the GetResources API using SDK v3 Command pattern
191+ const command = new GetResourcesCommand ( requestParams )
192+ return await sqlClient . send ( command )
213193 } catch ( err ) {
214194 this . logger . error ( 'SQLWorkbenchClient: Failed to get resources: %s' , err as Error )
215195 throw err
@@ -228,26 +208,27 @@ export class SQLWorkbenchClient {
228208
229209 const sqlClient = await this . getSQLClient ( )
230210
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 ( )
211+ const requestParams : ExecuteQueryRequest = {
212+ connection : connectionConfig ,
213+ databaseType : 'REDSHIFT' ,
214+ accountSettings : { } ,
215+ executionContext : [
216+ {
217+ parentType : 'DATABASE' ,
218+ parentId : connectionConfig . database || '' ,
219+ } ,
220+ ] ,
221+ query,
222+ queryExecutionType : 'NO_SESSION' ,
223+ queryResponseDeliveryType : 'ASYNC' ,
224+ maxItems : 100 ,
225+ ignoreHistory : true ,
226+ tabId : 'data_explorer' ,
227+ }
228+
229+ // Call the ExecuteQuery API using SDK v3 Command pattern
230+ const command = new ExecuteQueryCommand ( requestParams )
231+ const response = await sqlClient . send ( command )
251232
252233 // Log the response
253234 this . logger . info (
@@ -261,9 +242,6 @@ export class SQLWorkbenchClient {
261242 }
262243 }
263244
264- /**
265- * Gets the SQL client, initializing it if necessary
266- */
267245 /**
268246 * Gets the SQL Workbench endpoint URL for the given region
269247 * @param region AWS region
@@ -273,6 +251,9 @@ export class SQLWorkbenchClient {
273251 return `https://api-v2.sqlworkbench.${ region } .amazonaws.com`
274252 }
275253
254+ /**
255+ * Gets the SQL client, initializing it if necessary
256+ */
276257 private async getSQLClient ( ) : Promise < SQLWorkbench > {
277258 if ( ! this . sqlClient ) {
278259 try {
@@ -281,30 +262,27 @@ export class SQLWorkbenchClient {
281262 this . logger . info ( `Using SQL Workbench endpoint: ${ endpoint } ` )
282263
283264 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
265+ // Create client with credential provider function for auto-refresh
266+ const awsCredentialProvider = async ( ) => {
267+ const credentials = await this . connectionCredentialsProvider ! . getCredentials ( )
268+ return {
269+ accessKeyId : credentials . accessKeyId ,
270+ secretAccessKey : credentials . secretAccessKey ,
271+ sessionToken : credentials . sessionToken ,
272+ expiration : credentials . expiration ,
273+ }
274+ }
275+ this . sqlClient = new SQLWorkbench ( {
276+ region : this . region ,
277+ endpoint : endpoint ,
278+ credentials : awsCredentialProvider ,
279+ } )
296280 } 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
281+ // Use default credentials
282+ this . sqlClient = new SQLWorkbench ( {
283+ region : this . region ,
284+ endpoint : endpoint ,
285+ } )
308286 }
309287
310288 this . logger . debug ( 'SQLWorkbenchClient: Successfully created SQL client' )
0 commit comments