44 */
55
66import { getLogger } from '../../../shared/logger/logger'
7- import apiConfig = require( './datazonecustomclient.json' )
8- import globals from '../../../shared/extensionGlobals'
9- import { Service } from 'aws-sdk'
10- import { ServiceConfigurationOptions } from 'aws-sdk/lib/service'
11- import * as DataZoneCustomClient from './datazonecustomclient'
12- import { adaptConnectionCredentialsProvider } from './credentialsAdapter'
7+ import {
8+ DataZone ,
9+ ListDomainsCommand ,
10+ GetDomainCommand ,
11+ SearchGroupProfilesCommand ,
12+ SearchUserProfilesCommand ,
13+ DomainSummary ,
14+ GetDomainOutput ,
15+ GroupProfileSummary ,
16+ UserProfileSummary ,
17+ GroupSearchType ,
18+ UserSearchType ,
19+ } from '@amzn/datazone-custom-client'
1320import { CredentialsProvider } from '../../../auth/providers/credentials'
1421import { ToolkitError } from '../../../shared/errors'
1522import { SmusUtils , isIamDomain } from '../smusUtils'
@@ -30,7 +37,7 @@ export const DataZoneErrorCode = {
3037 * Helper client for interacting with AWS DataZone Custom API
3138 */
3239export class DataZoneCustomClientHelper {
33- private datazoneCustomClient : DataZoneCustomClient | undefined
40+ private datazoneCustomClient : DataZone | undefined
3441 private static instances = new Map < string , DataZoneCustomClientHelper > ( )
3542 private readonly logger = getLogger ( 'smus' )
3643
@@ -91,33 +98,38 @@ export class DataZoneCustomClientHelper {
9198 /**
9299 * Gets the DataZone client, initializing it if necessary
93100 */
94- private async getDataZoneCustomClient ( ) : Promise < DataZoneCustomClient > {
101+ private async getDataZoneCustomClient ( ) : Promise < DataZone > {
95102 if ( ! this . datazoneCustomClient ) {
96103 try {
97104 this . logger . info ( 'DataZoneCustomClientHelper: Creating authenticated DataZone client' )
98105
99- // Use user setting for endpoint if provided, otherwise use default
106+ // Create credential provider function for auto-refresh
107+ const awsCredentialProvider = async ( ) => {
108+ const credentials = await this . credentialProvider . getCredentials ( )
109+ return {
110+ accessKeyId : credentials . accessKeyId ,
111+ secretAccessKey : credentials . secretAccessKey ,
112+ sessionToken : credentials . sessionToken ,
113+ expiration : credentials . expiration ,
114+ }
115+ }
116+
117+ const clientConfig : any = {
118+ region : this . region ,
119+ credentials : awsCredentialProvider ,
120+ }
121+
122+ // Use user setting for endpoint if provided
100123 const devSettings = DevSettings . instance
101124 const customEndpoint = devSettings . get ( 'endpoints' , { } ) [ 'datazone' ]
102- const endpoint = customEndpoint || `https://datazone.${ this . region } .api.aws`
103-
104125 if ( customEndpoint ) {
126+ clientConfig . endpoint = customEndpoint
105127 this . logger . debug (
106- `DataZoneCustomClientHelper: Using custom DataZone endpoint from settings: ${ endpoint } `
128+ `DataZoneCustomClientHelper: Using custom DataZone endpoint from settings: ${ customEndpoint } `
107129 )
108130 }
109131
110- this . datazoneCustomClient = ( await globals . sdkClientBuilder . createAwsService (
111- Service ,
112- {
113- apiConfig : apiConfig ,
114- endpoint : endpoint ,
115- region : this . region ,
116- credentialProvider : adaptConnectionCredentialsProvider ( this . credentialProvider ) ,
117- } as ServiceConfigurationOptions ,
118- undefined ,
119- false
120- ) ) as DataZoneCustomClient
132+ this . datazoneCustomClient = new DataZone ( clientConfig )
121133
122134 this . logger . info ( 'DataZoneCustomClientHelper: Successfully created authenticated DataZone client' )
123135 } catch ( err ) {
@@ -137,20 +149,19 @@ export class DataZoneCustomClientHelper {
137149 maxResults ?: number
138150 status ?: string
139151 nextToken ?: string
140- } ) : Promise < { domains : DataZoneCustomClient . Types . DomainSummary [ ] ; nextToken ?: string } > {
152+ } ) : Promise < { domains : DomainSummary [ ] ; nextToken ?: string } > {
141153 try {
142154 this . logger . info ( `DataZoneCustomClientHelper: Listing domains in region ${ this . region } ` )
143155
144156 const datazoneCustomClient = await this . getDataZoneCustomClient ( )
145157
146158 // Call DataZone API to list domains with pagination
147- const response = await datazoneCustomClient
148- . listDomains ( {
149- maxResults : options ?. maxResults ,
150- status : options ?. status ,
151- nextToken : options ?. nextToken ,
152- } )
153- . promise ( )
159+ const command = new ListDomainsCommand ( {
160+ maxResults : options ?. maxResults ,
161+ status : options ?. status as any ,
162+ nextToken : options ?. nextToken ,
163+ } )
164+ const response = await datazoneCustomClient . send ( command )
154165
155166 const domains = response . items || [ ]
156167
@@ -172,9 +183,9 @@ export class DataZoneCustomClientHelper {
172183 * @param options Options for listing domains (excluding nextToken which is handled internally)
173184 * @returns Promise resolving to an array of all DataZone domains
174185 */
175- public async fetchAllDomains ( options ?: { status ?: string } ) : Promise < DataZoneCustomClient . Types . DomainSummary [ ] > {
186+ public async fetchAllDomains ( options ?: { status ?: string } ) : Promise < DomainSummary [ ] > {
176187 try {
177- let allDomains : DataZoneCustomClient . Types . DomainSummary [ ] = [ ]
188+ let allDomains : DomainSummary [ ] = [ ]
178189 let nextToken : string | undefined
179190 do {
180191 const maxResultsPerPage = 25
@@ -199,7 +210,7 @@ export class DataZoneCustomClientHelper {
199210 * Gets the domain with IAM authentication mode using pagination with early termination
200211 * @returns Promise resolving to the DataZone domain or undefined if not found
201212 */
202- public async getIamDomain ( ) : Promise < DataZoneCustomClient . Types . DomainSummary | undefined > {
213+ public async getIamDomain ( ) : Promise < DomainSummary | undefined > {
203214 const logger = getLogger ( 'smus' )
204215
205216 try {
@@ -259,17 +270,16 @@ export class DataZoneCustomClientHelper {
259270 * @param domainId The ID of the domain to retrieve
260271 * @returns Promise resolving to the GetDomainOutput
261272 */
262- public async getDomain ( domainId : string ) : Promise < DataZoneCustomClient . Types . GetDomainOutput > {
273+ public async getDomain ( domainId : string ) : Promise < GetDomainOutput > {
263274 try {
264275 this . logger . debug ( `DataZoneCustomClientHelper: Getting domain with ID: ${ domainId } ` )
265276
266277 const datazoneCustomClient = await this . getDataZoneCustomClient ( )
267278
268- const response = await datazoneCustomClient
269- . getDomain ( {
270- identifier : domainId ,
271- } )
272- . promise ( )
279+ const command = new GetDomainCommand ( {
280+ identifier : domainId ,
281+ } )
282+ const response = await datazoneCustomClient . send ( command )
273283
274284 this . logger . debug ( `DataZoneCustomClientHelper: Successfully retrieved domain: ${ domainId } ` )
275285 return response
@@ -293,25 +303,23 @@ export class DataZoneCustomClientHelper {
293303 maxResults ?: number
294304 nextToken ?: string
295305 }
296- ) : Promise < { items : DataZoneCustomClient . Types . GroupProfileSummary [ ] ; nextToken ?: string } > {
306+ ) : Promise < { items : GroupProfileSummary [ ] ; nextToken ?: string } > {
297307 try {
298308 this . logger . debug (
299309 `DataZoneCustomClientHelper: Searching group profiles in domain ${ domainIdentifier } with groupType: ${ options ?. groupType } , searchText: ${ options ?. searchText } `
300310 )
301311
302312 const datazoneCustomClient = await this . getDataZoneCustomClient ( )
303313
304- // Build the request parameters
305- const params : DataZoneCustomClient . Types . SearchGroupProfilesInput = {
314+ // Call DataZone API to search group profiles
315+ const command = new SearchGroupProfilesCommand ( {
306316 domainIdentifier,
307- groupType : options ?. groupType as DataZoneCustomClient . Types . GroupSearchType ,
317+ groupType : options ?. groupType as GroupSearchType ,
308318 searchText : options ?. searchText ,
309319 maxResults : options ?. maxResults ,
310320 nextToken : options ?. nextToken ,
311- }
312-
313- // Call DataZone API to search group profiles
314- const response = await datazoneCustomClient . searchGroupProfiles ( params ) . promise ( )
321+ } )
322+ const response = await datazoneCustomClient . send ( command )
315323
316324 const items = response . items || [ ]
317325
@@ -342,25 +350,23 @@ export class DataZoneCustomClientHelper {
342350 maxResults ?: number
343351 nextToken ?: string
344352 }
345- ) : Promise < { items : DataZoneCustomClient . Types . UserProfileSummary [ ] ; nextToken ?: string } > {
353+ ) : Promise < { items : UserProfileSummary [ ] ; nextToken ?: string } > {
346354 try {
347355 this . logger . debug (
348356 `DataZoneCustomClientHelper: Searching user profiles in domain ${ domainIdentifier } with userType: ${ options . userType } , searchText: ${ options . searchText } `
349357 )
350358
351359 const datazoneCustomClient = await this . getDataZoneCustomClient ( )
352360
353- // Build the request parameters
354- const params : DataZoneCustomClient . Types . SearchUserProfilesInput = {
361+ // Call DataZone API to search user profiles
362+ const command = new SearchUserProfilesCommand ( {
355363 domainIdentifier,
356- userType : options . userType as DataZoneCustomClient . Types . UserSearchType ,
364+ userType : options . userType as UserSearchType ,
357365 searchText : options . searchText ,
358366 maxResults : options . maxResults ,
359367 nextToken : options . nextToken ,
360- }
361-
362- // Call DataZone API to search user profiles
363- const response = await datazoneCustomClient . searchUserProfiles ( params ) . promise ( )
368+ } )
369+ const response = await datazoneCustomClient . send ( command )
364370
365371 const items = response . items || [ ]
366372
0 commit comments