Skip to content

Commit 024ac3d

Browse files
committed
Upgrade sdk v2 to sdk v3 - DataZoneCustomClient
1 parent 20a5e85 commit 024ac3d

File tree

7 files changed

+1208
-1051
lines changed

7 files changed

+1208
-1051
lines changed

package-lock.json

Lines changed: 1087 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
@@ -582,6 +582,7 @@
582582
"@amzn/codewhisperer-streaming": "file:../../src.gen/@amzn/codewhisperer-streaming",
583583
"@amzn/sagemaker-client": "file:../../src.gen/@amzn/sagemaker-client/1.0.0.tgz",
584584
"@amzn/glue-catalog-client": "file:../../src.gen/@amzn/glue-catalog-client/0.0.1.tgz",
585+
"@amzn/datazone-custom-client": "file:../../src.gen/@amzn/datazone-custom-client/3.0.0.tgz",
585586
"@aws-sdk/client-accessanalyzer": "^3.888.0",
586587
"@aws-sdk/client-api-gateway": "<3.731.0",
587588
"@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/sqlworkbench.json',
246246
serviceName: 'SQLWorkbench',
247247
},
248-
{
249-
serviceJsonPath: 'src/sagemakerunifiedstudio/shared/client/datazonecustomclient.json',
250-
serviceName: 'DataZoneCustomClient',
251-
},
252248
]
253249
await generateServiceClients(serviceClientDefinitions)
254250
})()

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

Lines changed: 62 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@
44
*/
55

66
import { 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'
1320
import { CredentialsProvider } from '../../../auth/providers/credentials'
1421
import { ToolkitError } from '../../../shared/errors'
1522
import { SmusUtils, isIamDomain } from '../smusUtils'
@@ -30,7 +37,7 @@ export const DataZoneErrorCode = {
3037
* Helper client for interacting with AWS DataZone Custom API
3138
*/
3239
export 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

Comments
 (0)