Skip to content

Commit f01d5ae

Browse files
authored
feat(clients): adding throwable waiters WaitUntil[operationState] (#2302)
* feat(waiter-utils): adding reasons for waiter states and exceptions * feat(clients): adding waitUtilState from codegen * fix: moving waiter types to aws-sdk/types * fix: re-word documentation in generated clients * fix: updating documentation * fix: renaming errors
1 parent d7106b4 commit f01d5ae

File tree

132 files changed

+3028
-990
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+3028
-990
lines changed

Diff for: clients/client-acm-pca/waiters/waitForAuditReportCreated.ts

+23-7
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,40 @@ import {
33
DescribeCertificateAuthorityAuditReportCommand,
44
DescribeCertificateAuthorityAuditReportCommandInput,
55
} from "../commands/DescribeCertificateAuthorityAuditReportCommand";
6-
import { WaiterConfiguration, WaiterResult, WaiterState, createWaiter } from "@aws-sdk/util-waiter";
6+
import { WaiterConfiguration, WaiterResult, WaiterState, checkExceptions, createWaiter } from "@aws-sdk/util-waiter";
77

88
const checkState = async (
99
client: ACMPCAClient,
1010
input: DescribeCertificateAuthorityAuditReportCommandInput
1111
): Promise<WaiterResult> => {
12+
let reason;
1213
try {
1314
let result: any = await client.send(new DescribeCertificateAuthorityAuditReportCommand(input));
15+
reason = result;
1416
try {
1517
let returnComparator = () => {
1618
return result.AuditReportStatus;
1719
};
1820
if (returnComparator() === "SUCCESS") {
19-
return { state: WaiterState.SUCCESS };
21+
return { state: WaiterState.SUCCESS, reason };
2022
}
2123
} catch (e) {}
2224
try {
2325
let returnComparator = () => {
2426
return result.AuditReportStatus;
2527
};
2628
if (returnComparator() === "FAILED") {
27-
return { state: WaiterState.FAILURE };
29+
return { state: WaiterState.FAILURE, reason };
2830
}
2931
} catch (e) {}
30-
} catch (exception) {}
31-
return { state: WaiterState.RETRY };
32+
} catch (exception) {
33+
reason = exception;
34+
}
35+
return { state: WaiterState.RETRY, reason };
3236
};
3337
/**
3438
* Wait until a Audit Report is created
35-
* @param params : Waiter configuration options.
36-
* @param input : the input to DescribeCertificateAuthorityAuditReportCommand for polling.
39+
* @deprecated Use waitUntilAuditReportCreated instead. waitForAuditReportCreated does not throw error in non-success cases.
3740
*/
3841
export const waitForAuditReportCreated = async (
3942
params: WaiterConfiguration<ACMPCAClient>,
@@ -42,3 +45,16 @@ export const waitForAuditReportCreated = async (
4245
const serviceDefaults = { minDelay: 3, maxDelay: 120 };
4346
return createWaiter({ ...serviceDefaults, ...params }, input, checkState);
4447
};
48+
/**
49+
* Wait until a Audit Report is created
50+
* @param params - Waiter configuration options.
51+
* @param input - The input to DescribeCertificateAuthorityAuditReportCommand for polling.
52+
*/
53+
export const waitUntilAuditReportCreated = async (
54+
params: WaiterConfiguration<ACMPCAClient>,
55+
input: DescribeCertificateAuthorityAuditReportCommandInput
56+
): Promise<WaiterResult> => {
57+
const serviceDefaults = { minDelay: 3, maxDelay: 120 };
58+
const result = await createWaiter({ ...serviceDefaults, ...params }, input, checkState);
59+
return checkExceptions(result);
60+
};

Diff for: clients/client-acm-pca/waiters/waitForCertificateAuthorityCSRCreated.ts

+21-6
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,28 @@ import {
33
GetCertificateAuthorityCsrCommand,
44
GetCertificateAuthorityCsrCommandInput,
55
} from "../commands/GetCertificateAuthorityCsrCommand";
6-
import { WaiterConfiguration, WaiterResult, WaiterState, createWaiter } from "@aws-sdk/util-waiter";
6+
import { WaiterConfiguration, WaiterResult, WaiterState, checkExceptions, createWaiter } from "@aws-sdk/util-waiter";
77

88
const checkState = async (
99
client: ACMPCAClient,
1010
input: GetCertificateAuthorityCsrCommandInput
1111
): Promise<WaiterResult> => {
12+
let reason;
1213
try {
1314
let result: any = await client.send(new GetCertificateAuthorityCsrCommand(input));
14-
return { state: WaiterState.SUCCESS };
15+
reason = result;
16+
return { state: WaiterState.SUCCESS, reason };
1517
} catch (exception) {
18+
reason = exception;
1619
if (exception.name && exception.name == "RequestInProgressException") {
17-
return { state: WaiterState.RETRY };
20+
return { state: WaiterState.RETRY, reason };
1821
}
1922
}
20-
return { state: WaiterState.RETRY };
23+
return { state: WaiterState.RETRY, reason };
2124
};
2225
/**
2326
* Wait until a Certificate Authority CSR is created
24-
* @param params : Waiter configuration options.
25-
* @param input : the input to GetCertificateAuthorityCsrCommand for polling.
27+
* @deprecated Use waitUntilCertificateAuthorityCSRCreated instead. waitForCertificateAuthorityCSRCreated does not throw error in non-success cases.
2628
*/
2729
export const waitForCertificateAuthorityCSRCreated = async (
2830
params: WaiterConfiguration<ACMPCAClient>,
@@ -31,3 +33,16 @@ export const waitForCertificateAuthorityCSRCreated = async (
3133
const serviceDefaults = { minDelay: 3, maxDelay: 120 };
3234
return createWaiter({ ...serviceDefaults, ...params }, input, checkState);
3335
};
36+
/**
37+
* Wait until a Certificate Authority CSR is created
38+
* @param params - Waiter configuration options.
39+
* @param input - The input to GetCertificateAuthorityCsrCommand for polling.
40+
*/
41+
export const waitUntilCertificateAuthorityCSRCreated = async (
42+
params: WaiterConfiguration<ACMPCAClient>,
43+
input: GetCertificateAuthorityCsrCommandInput
44+
): Promise<WaiterResult> => {
45+
const serviceDefaults = { minDelay: 3, maxDelay: 120 };
46+
const result = await createWaiter({ ...serviceDefaults, ...params }, input, checkState);
47+
return checkExceptions(result);
48+
};
+21-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
import { ACMPCAClient } from "../ACMPCAClient";
22
import { GetCertificateCommand, GetCertificateCommandInput } from "../commands/GetCertificateCommand";
3-
import { WaiterConfiguration, WaiterResult, WaiterState, createWaiter } from "@aws-sdk/util-waiter";
3+
import { WaiterConfiguration, WaiterResult, WaiterState, checkExceptions, createWaiter } from "@aws-sdk/util-waiter";
44

55
const checkState = async (client: ACMPCAClient, input: GetCertificateCommandInput): Promise<WaiterResult> => {
6+
let reason;
67
try {
78
let result: any = await client.send(new GetCertificateCommand(input));
8-
return { state: WaiterState.SUCCESS };
9+
reason = result;
10+
return { state: WaiterState.SUCCESS, reason };
911
} catch (exception) {
12+
reason = exception;
1013
if (exception.name && exception.name == "RequestInProgressException") {
11-
return { state: WaiterState.RETRY };
14+
return { state: WaiterState.RETRY, reason };
1215
}
1316
}
14-
return { state: WaiterState.RETRY };
17+
return { state: WaiterState.RETRY, reason };
1518
};
1619
/**
1720
* Wait until a certificate is issued
18-
* @param params : Waiter configuration options.
19-
* @param input : the input to GetCertificateCommand for polling.
21+
* @deprecated Use waitUntilCertificateIssued instead. waitForCertificateIssued does not throw error in non-success cases.
2022
*/
2123
export const waitForCertificateIssued = async (
2224
params: WaiterConfiguration<ACMPCAClient>,
@@ -25,3 +27,16 @@ export const waitForCertificateIssued = async (
2527
const serviceDefaults = { minDelay: 3, maxDelay: 120 };
2628
return createWaiter({ ...serviceDefaults, ...params }, input, checkState);
2729
};
30+
/**
31+
* Wait until a certificate is issued
32+
* @param params - Waiter configuration options.
33+
* @param input - The input to GetCertificateCommand for polling.
34+
*/
35+
export const waitUntilCertificateIssued = async (
36+
params: WaiterConfiguration<ACMPCAClient>,
37+
input: GetCertificateCommandInput
38+
): Promise<WaiterResult> => {
39+
const serviceDefaults = { minDelay: 3, maxDelay: 120 };
40+
const result = await createWaiter({ ...serviceDefaults, ...params }, input, checkState);
41+
return checkExceptions(result);
42+
};

Diff for: clients/client-acm/waiters/waitForCertificateValidated.ts

+23-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { ACMClient } from "../ACMClient";
22
import { DescribeCertificateCommand, DescribeCertificateCommandInput } from "../commands/DescribeCertificateCommand";
3-
import { WaiterConfiguration, WaiterResult, WaiterState, createWaiter } from "@aws-sdk/util-waiter";
3+
import { WaiterConfiguration, WaiterResult, WaiterState, checkExceptions, createWaiter } from "@aws-sdk/util-waiter";
44

55
const checkState = async (client: ACMClient, input: DescribeCertificateCommandInput): Promise<WaiterResult> => {
6+
let reason;
67
try {
78
let result: any = await client.send(new DescribeCertificateCommand(input));
9+
reason = result;
810
try {
911
let returnComparator = () => {
1012
let flat_1: any[] = [].concat(...result.Certificate.DomainValidationOptions);
@@ -18,7 +20,7 @@ const checkState = async (client: ACMClient, input: DescribeCertificateCommandIn
1820
allStringEq_5 = allStringEq_5 && element_4 == "SUCCESS";
1921
}
2022
if (allStringEq_5) {
21-
return { state: WaiterState.SUCCESS };
23+
return { state: WaiterState.SUCCESS, reason };
2224
}
2325
} catch (e) {}
2426
try {
@@ -31,7 +33,7 @@ const checkState = async (client: ACMClient, input: DescribeCertificateCommandIn
3133
};
3234
for (let anyStringEq_4 of returnComparator()) {
3335
if (anyStringEq_4 == "PENDING_VALIDATION") {
34-
return { state: WaiterState.RETRY };
36+
return { state: WaiterState.RETRY, reason };
3537
}
3638
}
3739
} catch (e) {}
@@ -40,20 +42,20 @@ const checkState = async (client: ACMClient, input: DescribeCertificateCommandIn
4042
return result.Certificate.Status;
4143
};
4244
if (returnComparator() === "FAILED") {
43-
return { state: WaiterState.FAILURE };
45+
return { state: WaiterState.FAILURE, reason };
4446
}
4547
} catch (e) {}
4648
} catch (exception) {
49+
reason = exception;
4750
if (exception.name && exception.name == "ResourceNotFoundException") {
48-
return { state: WaiterState.FAILURE };
51+
return { state: WaiterState.FAILURE, reason };
4952
}
5053
}
51-
return { state: WaiterState.RETRY };
54+
return { state: WaiterState.RETRY, reason };
5255
};
5356
/**
5457
*
55-
* @param params : Waiter configuration options.
56-
* @param input : the input to DescribeCertificateCommand for polling.
58+
* @deprecated Use waitUntilCertificateValidated instead. waitForCertificateValidated does not throw error in non-success cases.
5759
*/
5860
export const waitForCertificateValidated = async (
5961
params: WaiterConfiguration<ACMClient>,
@@ -62,3 +64,16 @@ export const waitForCertificateValidated = async (
6264
const serviceDefaults = { minDelay: 60, maxDelay: 120 };
6365
return createWaiter({ ...serviceDefaults, ...params }, input, checkState);
6466
};
67+
/**
68+
*
69+
* @param params - Waiter configuration options.
70+
* @param input - The input to DescribeCertificateCommand for polling.
71+
*/
72+
export const waitUntilCertificateValidated = async (
73+
params: WaiterConfiguration<ACMClient>,
74+
input: DescribeCertificateCommandInput
75+
): Promise<WaiterResult> => {
76+
const serviceDefaults = { minDelay: 60, maxDelay: 120 };
77+
const result = await createWaiter({ ...serviceDefaults, ...params }, input, checkState);
78+
return checkExceptions(result);
79+
};

Diff for: clients/client-appstream/waiters/waitForFleetStarted.ts

+24-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { AppStreamClient } from "../AppStreamClient";
22
import { DescribeFleetsCommand, DescribeFleetsCommandInput } from "../commands/DescribeFleetsCommand";
3-
import { WaiterConfiguration, WaiterResult, WaiterState, createWaiter } from "@aws-sdk/util-waiter";
3+
import { WaiterConfiguration, WaiterResult, WaiterState, checkExceptions, createWaiter } from "@aws-sdk/util-waiter";
44

55
const checkState = async (client: AppStreamClient, input: DescribeFleetsCommandInput): Promise<WaiterResult> => {
6+
let reason;
67
try {
78
let result: any = await client.send(new DescribeFleetsCommand(input));
9+
reason = result;
810
try {
911
let returnComparator = () => {
1012
let flat_1: any[] = [].concat(...result.Fleets);
@@ -18,7 +20,7 @@ const checkState = async (client: AppStreamClient, input: DescribeFleetsCommandI
1820
allStringEq_5 = allStringEq_5 && element_4 == "ACTIVE";
1921
}
2022
if (allStringEq_5) {
21-
return { state: WaiterState.SUCCESS };
23+
return { state: WaiterState.SUCCESS, reason };
2224
}
2325
} catch (e) {}
2426
try {
@@ -31,7 +33,7 @@ const checkState = async (client: AppStreamClient, input: DescribeFleetsCommandI
3133
};
3234
for (let anyStringEq_4 of returnComparator()) {
3335
if (anyStringEq_4 == "PENDING_DEACTIVATE") {
34-
return { state: WaiterState.FAILURE };
36+
return { state: WaiterState.FAILURE, reason };
3537
}
3638
}
3739
} catch (e) {}
@@ -45,17 +47,18 @@ const checkState = async (client: AppStreamClient, input: DescribeFleetsCommandI
4547
};
4648
for (let anyStringEq_4 of returnComparator()) {
4749
if (anyStringEq_4 == "INACTIVE") {
48-
return { state: WaiterState.FAILURE };
50+
return { state: WaiterState.FAILURE, reason };
4951
}
5052
}
5153
} catch (e) {}
52-
} catch (exception) {}
53-
return { state: WaiterState.RETRY };
54+
} catch (exception) {
55+
reason = exception;
56+
}
57+
return { state: WaiterState.RETRY, reason };
5458
};
5559
/**
5660
*
57-
* @param params : Waiter configuration options.
58-
* @param input : the input to DescribeFleetsCommand for polling.
61+
* @deprecated Use waitUntilFleetStarted instead. waitForFleetStarted does not throw error in non-success cases.
5962
*/
6063
export const waitForFleetStarted = async (
6164
params: WaiterConfiguration<AppStreamClient>,
@@ -64,3 +67,16 @@ export const waitForFleetStarted = async (
6467
const serviceDefaults = { minDelay: 30, maxDelay: 120 };
6568
return createWaiter({ ...serviceDefaults, ...params }, input, checkState);
6669
};
70+
/**
71+
*
72+
* @param params - Waiter configuration options.
73+
* @param input - The input to DescribeFleetsCommand for polling.
74+
*/
75+
export const waitUntilFleetStarted = async (
76+
params: WaiterConfiguration<AppStreamClient>,
77+
input: DescribeFleetsCommandInput
78+
): Promise<WaiterResult> => {
79+
const serviceDefaults = { minDelay: 30, maxDelay: 120 };
80+
const result = await createWaiter({ ...serviceDefaults, ...params }, input, checkState);
81+
return checkExceptions(result);
82+
};

Diff for: clients/client-appstream/waiters/waitForFleetStopped.ts

+24-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { AppStreamClient } from "../AppStreamClient";
22
import { DescribeFleetsCommand, DescribeFleetsCommandInput } from "../commands/DescribeFleetsCommand";
3-
import { WaiterConfiguration, WaiterResult, WaiterState, createWaiter } from "@aws-sdk/util-waiter";
3+
import { WaiterConfiguration, WaiterResult, WaiterState, checkExceptions, createWaiter } from "@aws-sdk/util-waiter";
44

55
const checkState = async (client: AppStreamClient, input: DescribeFleetsCommandInput): Promise<WaiterResult> => {
6+
let reason;
67
try {
78
let result: any = await client.send(new DescribeFleetsCommand(input));
9+
reason = result;
810
try {
911
let returnComparator = () => {
1012
let flat_1: any[] = [].concat(...result.Fleets);
@@ -18,7 +20,7 @@ const checkState = async (client: AppStreamClient, input: DescribeFleetsCommandI
1820
allStringEq_5 = allStringEq_5 && element_4 == "INACTIVE";
1921
}
2022
if (allStringEq_5) {
21-
return { state: WaiterState.SUCCESS };
23+
return { state: WaiterState.SUCCESS, reason };
2224
}
2325
} catch (e) {}
2426
try {
@@ -31,7 +33,7 @@ const checkState = async (client: AppStreamClient, input: DescribeFleetsCommandI
3133
};
3234
for (let anyStringEq_4 of returnComparator()) {
3335
if (anyStringEq_4 == "PENDING_ACTIVATE") {
34-
return { state: WaiterState.FAILURE };
36+
return { state: WaiterState.FAILURE, reason };
3537
}
3638
}
3739
} catch (e) {}
@@ -45,17 +47,18 @@ const checkState = async (client: AppStreamClient, input: DescribeFleetsCommandI
4547
};
4648
for (let anyStringEq_4 of returnComparator()) {
4749
if (anyStringEq_4 == "ACTIVE") {
48-
return { state: WaiterState.FAILURE };
50+
return { state: WaiterState.FAILURE, reason };
4951
}
5052
}
5153
} catch (e) {}
52-
} catch (exception) {}
53-
return { state: WaiterState.RETRY };
54+
} catch (exception) {
55+
reason = exception;
56+
}
57+
return { state: WaiterState.RETRY, reason };
5458
};
5559
/**
5660
*
57-
* @param params : Waiter configuration options.
58-
* @param input : the input to DescribeFleetsCommand for polling.
61+
* @deprecated Use waitUntilFleetStopped instead. waitForFleetStopped does not throw error in non-success cases.
5962
*/
6063
export const waitForFleetStopped = async (
6164
params: WaiterConfiguration<AppStreamClient>,
@@ -64,3 +67,16 @@ export const waitForFleetStopped = async (
6467
const serviceDefaults = { minDelay: 30, maxDelay: 120 };
6568
return createWaiter({ ...serviceDefaults, ...params }, input, checkState);
6669
};
70+
/**
71+
*
72+
* @param params - Waiter configuration options.
73+
* @param input - The input to DescribeFleetsCommand for polling.
74+
*/
75+
export const waitUntilFleetStopped = async (
76+
params: WaiterConfiguration<AppStreamClient>,
77+
input: DescribeFleetsCommandInput
78+
): Promise<WaiterResult> => {
79+
const serviceDefaults = { minDelay: 30, maxDelay: 120 };
80+
const result = await createWaiter({ ...serviceDefaults, ...params }, input, checkState);
81+
return checkExceptions(result);
82+
};

0 commit comments

Comments
 (0)