generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCcapiService.ts
More file actions
53 lines (47 loc) · 1.72 KB
/
CcapiService.ts
File metadata and controls
53 lines (47 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import {
CloudControlClient,
GetResourceCommand,
GetResourceInput,
ListResourcesCommand,
ListResourcesOutput,
} from '@aws-sdk/client-cloudcontrol';
import { Measure } from '../telemetry/TelemetryDecorator';
import { AwsClient } from './AwsClient';
export interface ListResourcesOptions {
nextToken?: string;
maxResults?: number;
}
export class CcapiService {
constructor(private readonly awsClient: AwsClient) {}
private async withClient<T>(request: (client: CloudControlClient) => Promise<T>): Promise<T> {
const client = this.awsClient.getCloudControlClient();
return await request(client);
}
@Measure({ name: 'listResources' })
public async listResources(typeName: string, options?: ListResourcesOptions): Promise<ListResourcesOutput> {
return await this.withClient(async (client) => {
const response = await client.send(
new ListResourcesCommand({
TypeName: typeName,
NextToken: options?.nextToken,
MaxResults: options?.maxResults,
}),
);
return {
TypeName: response.TypeName,
ResourceDescriptions: response.ResourceDescriptions,
NextToken: response.NextToken,
};
});
}
@Measure({ name: 'getResource' })
public async getResource(typeName: string, identifier: string) {
return await this.withClient(async (client) => {
const getResourceInput: GetResourceInput = {
TypeName: typeName,
Identifier: identifier,
};
return await client.send(new GetResourceCommand(getResourceInput));
});
}
}