-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client-ec2): Adds support for waiters that automatically poll fo…
…r a deleted NAT Gateway until it reaches the deleted state.
- Loading branch information
awstools
committed
Apr 22, 2022
1 parent
e7c061d
commit 047c131
Showing
11 changed files
with
165 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
clients/client-ec2/src/waiters/waitForNatGatewayDeleted.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { checkExceptions, createWaiter, WaiterConfiguration, WaiterResult, WaiterState } from "@aws-sdk/util-waiter"; | ||
|
||
import { DescribeNatGatewaysCommand, DescribeNatGatewaysCommandInput } from "../commands/DescribeNatGatewaysCommand"; | ||
import { EC2Client } from "../EC2Client"; | ||
|
||
const checkState = async (client: EC2Client, input: DescribeNatGatewaysCommandInput): Promise<WaiterResult> => { | ||
let reason; | ||
try { | ||
const result: any = await client.send(new DescribeNatGatewaysCommand(input)); | ||
reason = result; | ||
try { | ||
const returnComparator = () => { | ||
const flat_1: any[] = [].concat(...result.NatGateways); | ||
const projection_3 = flat_1.map((element_2: any) => { | ||
return element_2.State; | ||
}); | ||
return projection_3; | ||
}; | ||
let allStringEq_5 = returnComparator().length > 0; | ||
for (const element_4 of returnComparator()) { | ||
allStringEq_5 = allStringEq_5 && element_4 == "deleted"; | ||
} | ||
if (allStringEq_5) { | ||
return { state: WaiterState.SUCCESS, reason }; | ||
} | ||
} catch (e) {} | ||
} catch (exception) { | ||
reason = exception; | ||
if (exception.name && exception.name == "NatGatewayNotFound") { | ||
return { state: WaiterState.SUCCESS, reason }; | ||
} | ||
} | ||
return { state: WaiterState.RETRY, reason }; | ||
}; | ||
/** | ||
* | ||
* @deprecated Use waitUntilNatGatewayDeleted instead. waitForNatGatewayDeleted does not throw error in non-success cases. | ||
*/ | ||
export const waitForNatGatewayDeleted = async ( | ||
params: WaiterConfiguration<EC2Client>, | ||
input: DescribeNatGatewaysCommandInput | ||
): Promise<WaiterResult> => { | ||
const serviceDefaults = { minDelay: 15, maxDelay: 120 }; | ||
return createWaiter({ ...serviceDefaults, ...params }, input, checkState); | ||
}; | ||
/** | ||
* | ||
* @param params - Waiter configuration options. | ||
* @param input - The input to DescribeNatGatewaysCommand for polling. | ||
*/ | ||
export const waitUntilNatGatewayDeleted = async ( | ||
params: WaiterConfiguration<EC2Client>, | ||
input: DescribeNatGatewaysCommandInput | ||
): Promise<WaiterResult> => { | ||
const serviceDefaults = { minDelay: 15, maxDelay: 120 }; | ||
const result = await createWaiter({ ...serviceDefaults, ...params }, input, checkState); | ||
return checkExceptions(result); | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.