Skip to content

feat(clients): adding throwable waiters WaitUntil[operationState] #2302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions clients/client-acm-pca/waiters/waitForAuditReportCreated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,40 @@ import {
DescribeCertificateAuthorityAuditReportCommand,
DescribeCertificateAuthorityAuditReportCommandInput,
} from "../commands/DescribeCertificateAuthorityAuditReportCommand";
import { WaiterConfiguration, WaiterResult, WaiterState, createWaiter } from "@aws-sdk/util-waiter";
import { WaiterConfiguration, WaiterResult, WaiterState, checkExceptions, createWaiter } from "@aws-sdk/util-waiter";

const checkState = async (
client: ACMPCAClient,
input: DescribeCertificateAuthorityAuditReportCommandInput
): Promise<WaiterResult> => {
let reason;
try {
let result: any = await client.send(new DescribeCertificateAuthorityAuditReportCommand(input));
reason = result;
try {
let returnComparator = () => {
return result.AuditReportStatus;
};
if (returnComparator() === "SUCCESS") {
return { state: WaiterState.SUCCESS };
return { state: WaiterState.SUCCESS, reason };
}
} catch (e) {}
try {
let returnComparator = () => {
return result.AuditReportStatus;
};
if (returnComparator() === "FAILED") {
return { state: WaiterState.FAILURE };
return { state: WaiterState.FAILURE, reason };
}
} catch (e) {}
} catch (exception) {}
return { state: WaiterState.RETRY };
} catch (exception) {
reason = exception;
}
return { state: WaiterState.RETRY, reason };
};
/**
* Wait until a Audit Report is created
* @deprecated in favor of waitUntilAuditReportCreated. This does not throw on failure.
* @param params : Waiter configuration options.
* @param input : the input to DescribeCertificateAuthorityAuditReportCommand for polling.
*/
Expand All @@ -42,3 +47,16 @@ export const waitForAuditReportCreated = async (
const serviceDefaults = { minDelay: 3, maxDelay: 120 };
return createWaiter({ ...serviceDefaults, ...params }, input, checkState);
};
/**
* Wait until a Audit Report is created
* @param params : Waiter configuration options.
* @param input : the input to DescribeCertificateAuthorityAuditReportCommand for polling.
*/
export const waitUntilAuditReportCreated = async (
params: WaiterConfiguration<ACMPCAClient>,
input: DescribeCertificateAuthorityAuditReportCommandInput
): Promise<WaiterResult> => {
const serviceDefaults = { minDelay: 3, maxDelay: 120 };
const result = await createWaiter({ ...serviceDefaults, ...params }, input, checkState);
return checkExceptions(result);
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,28 @@ import {
GetCertificateAuthorityCsrCommand,
GetCertificateAuthorityCsrCommandInput,
} from "../commands/GetCertificateAuthorityCsrCommand";
import { WaiterConfiguration, WaiterResult, WaiterState, createWaiter } from "@aws-sdk/util-waiter";
import { WaiterConfiguration, WaiterResult, WaiterState, checkExceptions, createWaiter } from "@aws-sdk/util-waiter";

const checkState = async (
client: ACMPCAClient,
input: GetCertificateAuthorityCsrCommandInput
): Promise<WaiterResult> => {
let reason;
try {
let result: any = await client.send(new GetCertificateAuthorityCsrCommand(input));
return { state: WaiterState.SUCCESS };
reason = result;
return { state: WaiterState.SUCCESS, reason };
} catch (exception) {
reason = exception;
if (exception.name && exception.name == "RequestInProgressException") {
return { state: WaiterState.RETRY };
return { state: WaiterState.RETRY, reason };
}
}
return { state: WaiterState.RETRY };
return { state: WaiterState.RETRY, reason };
};
/**
* Wait until a Certificate Authority CSR is created
* @deprecated in favor of waitUntilCertificateAuthorityCSRCreated. This does not throw on failure.
* @param params : Waiter configuration options.
* @param input : the input to GetCertificateAuthorityCsrCommand for polling.
*/
Expand All @@ -31,3 +35,16 @@ export const waitForCertificateAuthorityCSRCreated = async (
const serviceDefaults = { minDelay: 3, maxDelay: 120 };
return createWaiter({ ...serviceDefaults, ...params }, input, checkState);
};
/**
* Wait until a Certificate Authority CSR is created
* @param params : Waiter configuration options.
* @param input : the input to GetCertificateAuthorityCsrCommand for polling.
*/
export const waitUntilCertificateAuthorityCSRCreated = async (
params: WaiterConfiguration<ACMPCAClient>,
input: GetCertificateAuthorityCsrCommandInput
): Promise<WaiterResult> => {
const serviceDefaults = { minDelay: 3, maxDelay: 120 };
const result = await createWaiter({ ...serviceDefaults, ...params }, input, checkState);
return checkExceptions(result);
};
25 changes: 21 additions & 4 deletions clients/client-acm-pca/waiters/waitForCertificateIssued.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { ACMPCAClient } from "../ACMPCAClient";
import { GetCertificateCommand, GetCertificateCommandInput } from "../commands/GetCertificateCommand";
import { WaiterConfiguration, WaiterResult, WaiterState, createWaiter } from "@aws-sdk/util-waiter";
import { WaiterConfiguration, WaiterResult, WaiterState, checkExceptions, createWaiter } from "@aws-sdk/util-waiter";

const checkState = async (client: ACMPCAClient, input: GetCertificateCommandInput): Promise<WaiterResult> => {
let reason;
try {
let result: any = await client.send(new GetCertificateCommand(input));
return { state: WaiterState.SUCCESS };
reason = result;
return { state: WaiterState.SUCCESS, reason };
} catch (exception) {
reason = exception;
if (exception.name && exception.name == "RequestInProgressException") {
return { state: WaiterState.RETRY };
return { state: WaiterState.RETRY, reason };
}
}
return { state: WaiterState.RETRY };
return { state: WaiterState.RETRY, reason };
};
/**
* Wait until a certificate is issued
* @deprecated in favor of waitUntilCertificateIssued. This does not throw on failure.
* @param params : Waiter configuration options.
* @param input : the input to GetCertificateCommand for polling.
*/
Expand All @@ -25,3 +29,16 @@ export const waitForCertificateIssued = async (
const serviceDefaults = { minDelay: 3, maxDelay: 120 };
return createWaiter({ ...serviceDefaults, ...params }, input, checkState);
};
/**
* Wait until a certificate is issued
* @param params : Waiter configuration options.
* @param input : the input to GetCertificateCommand for polling.
*/
export const waitUntilCertificateIssued = async (
params: WaiterConfiguration<ACMPCAClient>,
input: GetCertificateCommandInput
): Promise<WaiterResult> => {
const serviceDefaults = { minDelay: 3, maxDelay: 120 };
const result = await createWaiter({ ...serviceDefaults, ...params }, input, checkState);
return checkExceptions(result);
};
29 changes: 23 additions & 6 deletions clients/client-acm/waiters/waitForCertificateValidated.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { ACMClient } from "../ACMClient";
import { DescribeCertificateCommand, DescribeCertificateCommandInput } from "../commands/DescribeCertificateCommand";
import { WaiterConfiguration, WaiterResult, WaiterState, createWaiter } from "@aws-sdk/util-waiter";
import { WaiterConfiguration, WaiterResult, WaiterState, checkExceptions, createWaiter } from "@aws-sdk/util-waiter";

const checkState = async (client: ACMClient, input: DescribeCertificateCommandInput): Promise<WaiterResult> => {
let reason;
try {
let result: any = await client.send(new DescribeCertificateCommand(input));
reason = result;
try {
let returnComparator = () => {
let flat_1: any[] = [].concat(...result.Certificate.DomainValidationOptions);
Expand All @@ -18,7 +20,7 @@ const checkState = async (client: ACMClient, input: DescribeCertificateCommandIn
allStringEq_5 = allStringEq_5 && element_4 == "SUCCESS";
}
if (allStringEq_5) {
return { state: WaiterState.SUCCESS };
return { state: WaiterState.SUCCESS, reason };
}
} catch (e) {}
try {
Expand All @@ -31,7 +33,7 @@ const checkState = async (client: ACMClient, input: DescribeCertificateCommandIn
};
for (let anyStringEq_4 of returnComparator()) {
if (anyStringEq_4 == "PENDING_VALIDATION") {
return { state: WaiterState.RETRY };
return { state: WaiterState.RETRY, reason };
}
}
} catch (e) {}
Expand All @@ -40,18 +42,20 @@ const checkState = async (client: ACMClient, input: DescribeCertificateCommandIn
return result.Certificate.Status;
};
if (returnComparator() === "FAILED") {
return { state: WaiterState.FAILURE };
return { state: WaiterState.FAILURE, reason };
}
} catch (e) {}
} catch (exception) {
reason = exception;
if (exception.name && exception.name == "ResourceNotFoundException") {
return { state: WaiterState.FAILURE };
return { state: WaiterState.FAILURE, reason };
}
}
return { state: WaiterState.RETRY };
return { state: WaiterState.RETRY, reason };
};
/**
*
* @deprecated in favor of waitUntilCertificateValidated. This does not throw on failure.
* @param params : Waiter configuration options.
* @param input : the input to DescribeCertificateCommand for polling.
*/
Expand All @@ -62,3 +66,16 @@ export const waitForCertificateValidated = async (
const serviceDefaults = { minDelay: 60, maxDelay: 120 };
return createWaiter({ ...serviceDefaults, ...params }, input, checkState);
};
/**
*
* @param params : Waiter configuration options.
* @param input : the input to DescribeCertificateCommand for polling.
*/
export const waitUntilCertificateValidated = async (
params: WaiterConfiguration<ACMClient>,
input: DescribeCertificateCommandInput
): Promise<WaiterResult> => {
const serviceDefaults = { minDelay: 60, maxDelay: 120 };
const result = await createWaiter({ ...serviceDefaults, ...params }, input, checkState);
return checkExceptions(result);
};
30 changes: 24 additions & 6 deletions clients/client-appstream/waiters/waitForFleetStarted.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { AppStreamClient } from "../AppStreamClient";
import { DescribeFleetsCommand, DescribeFleetsCommandInput } from "../commands/DescribeFleetsCommand";
import { WaiterConfiguration, WaiterResult, WaiterState, createWaiter } from "@aws-sdk/util-waiter";
import { WaiterConfiguration, WaiterResult, WaiterState, checkExceptions, createWaiter } from "@aws-sdk/util-waiter";

const checkState = async (client: AppStreamClient, input: DescribeFleetsCommandInput): Promise<WaiterResult> => {
let reason;
try {
let result: any = await client.send(new DescribeFleetsCommand(input));
reason = result;
try {
let returnComparator = () => {
let flat_1: any[] = [].concat(...result.Fleets);
Expand All @@ -18,7 +20,7 @@ const checkState = async (client: AppStreamClient, input: DescribeFleetsCommandI
allStringEq_5 = allStringEq_5 && element_4 == "ACTIVE";
}
if (allStringEq_5) {
return { state: WaiterState.SUCCESS };
return { state: WaiterState.SUCCESS, reason };
}
} catch (e) {}
try {
Expand All @@ -31,7 +33,7 @@ const checkState = async (client: AppStreamClient, input: DescribeFleetsCommandI
};
for (let anyStringEq_4 of returnComparator()) {
if (anyStringEq_4 == "PENDING_DEACTIVATE") {
return { state: WaiterState.FAILURE };
return { state: WaiterState.FAILURE, reason };
}
}
} catch (e) {}
Expand All @@ -45,15 +47,18 @@ const checkState = async (client: AppStreamClient, input: DescribeFleetsCommandI
};
for (let anyStringEq_4 of returnComparator()) {
if (anyStringEq_4 == "INACTIVE") {
return { state: WaiterState.FAILURE };
return { state: WaiterState.FAILURE, reason };
}
}
} catch (e) {}
} catch (exception) {}
return { state: WaiterState.RETRY };
} catch (exception) {
reason = exception;
}
return { state: WaiterState.RETRY, reason };
};
/**
*
* @deprecated in favor of waitUntilFleetStarted. This does not throw on failure.
* @param params : Waiter configuration options.
* @param input : the input to DescribeFleetsCommand for polling.
*/
Expand All @@ -64,3 +69,16 @@ export const waitForFleetStarted = async (
const serviceDefaults = { minDelay: 30, maxDelay: 120 };
return createWaiter({ ...serviceDefaults, ...params }, input, checkState);
};
/**
*
* @param params : Waiter configuration options.
* @param input : the input to DescribeFleetsCommand for polling.
*/
export const waitUntilFleetStarted = async (
params: WaiterConfiguration<AppStreamClient>,
input: DescribeFleetsCommandInput
): Promise<WaiterResult> => {
const serviceDefaults = { minDelay: 30, maxDelay: 120 };
const result = await createWaiter({ ...serviceDefaults, ...params }, input, checkState);
return checkExceptions(result);
};
30 changes: 24 additions & 6 deletions clients/client-appstream/waiters/waitForFleetStopped.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { AppStreamClient } from "../AppStreamClient";
import { DescribeFleetsCommand, DescribeFleetsCommandInput } from "../commands/DescribeFleetsCommand";
import { WaiterConfiguration, WaiterResult, WaiterState, createWaiter } from "@aws-sdk/util-waiter";
import { WaiterConfiguration, WaiterResult, WaiterState, checkExceptions, createWaiter } from "@aws-sdk/util-waiter";

const checkState = async (client: AppStreamClient, input: DescribeFleetsCommandInput): Promise<WaiterResult> => {
let reason;
try {
let result: any = await client.send(new DescribeFleetsCommand(input));
reason = result;
try {
let returnComparator = () => {
let flat_1: any[] = [].concat(...result.Fleets);
Expand All @@ -18,7 +20,7 @@ const checkState = async (client: AppStreamClient, input: DescribeFleetsCommandI
allStringEq_5 = allStringEq_5 && element_4 == "INACTIVE";
}
if (allStringEq_5) {
return { state: WaiterState.SUCCESS };
return { state: WaiterState.SUCCESS, reason };
}
} catch (e) {}
try {
Expand All @@ -31,7 +33,7 @@ const checkState = async (client: AppStreamClient, input: DescribeFleetsCommandI
};
for (let anyStringEq_4 of returnComparator()) {
if (anyStringEq_4 == "PENDING_ACTIVATE") {
return { state: WaiterState.FAILURE };
return { state: WaiterState.FAILURE, reason };
}
}
} catch (e) {}
Expand All @@ -45,15 +47,18 @@ const checkState = async (client: AppStreamClient, input: DescribeFleetsCommandI
};
for (let anyStringEq_4 of returnComparator()) {
if (anyStringEq_4 == "ACTIVE") {
return { state: WaiterState.FAILURE };
return { state: WaiterState.FAILURE, reason };
}
}
} catch (e) {}
} catch (exception) {}
return { state: WaiterState.RETRY };
} catch (exception) {
reason = exception;
}
return { state: WaiterState.RETRY, reason };
};
/**
*
* @deprecated in favor of waitUntilFleetStopped. This does not throw on failure.
* @param params : Waiter configuration options.
* @param input : the input to DescribeFleetsCommand for polling.
*/
Expand All @@ -64,3 +69,16 @@ export const waitForFleetStopped = async (
const serviceDefaults = { minDelay: 30, maxDelay: 120 };
return createWaiter({ ...serviceDefaults, ...params }, input, checkState);
};
/**
*
* @param params : Waiter configuration options.
* @param input : the input to DescribeFleetsCommand for polling.
*/
export const waitUntilFleetStopped = async (
params: WaiterConfiguration<AppStreamClient>,
input: DescribeFleetsCommandInput
): Promise<WaiterResult> => {
const serviceDefaults = { minDelay: 30, maxDelay: 120 };
const result = await createWaiter({ ...serviceDefaults, ...params }, input, checkState);
return checkExceptions(result);
};
Loading