@@ -40,7 +40,7 @@ import {
4040 retryWhileGatewayRoleChangesPropagate ,
4141 type GatewayTargetRoleConfiguration ,
4242} from "./gatewayExecutionRole" ;
43- import { swapInlinePolicyForOperation } from "./inlinePolicySwap" ;
43+ import { InlinePolicySwap } from "./inlinePolicySwap" ;
4444import { toClientConfig } from "./utils" ;
4545
4646export class GatewayClient implements CoreGatewayClient {
@@ -60,39 +60,25 @@ export class GatewayClient implements CoreGatewayClient {
6060
6161 const iam = this . clients . iam ( { region : options . region } ) ;
6262 const role = await ensureGatewayExecutionRole ( iam , input . name ! , options . region , input ) ;
63- const response = await swapInlinePolicyForOperation (
64- iam ,
65- {
66- roleName : role . roleName ,
67- policyNamePrefix : GATEWAY_EXECUTION_POLICY_NAME ,
68- policyDocument : role . candidatePolicyDocument ( ) ,
69- } ,
70- async ( ) => {
71- const created = await retryWhileGatewayRoleChangesPropagate ( ( ) =>
72- control . send (
73- new CreateGatewayCommand (
74- buildGatewayCreateRequest ( { ...input , roleArn : role . roleArn } ) ,
75- ) ,
76- ) ,
77- ) ;
78- if ( ! created . gatewayArn ) {
79- throw new Error ( "CreateGateway response did not include the Gateway ARN" ) ;
80- }
81- return created ;
82- } ,
83- ) ;
84- return swapInlinePolicyForOperation (
85- iam ,
86- {
87- roleName : role . roleName ,
88- policyNamePrefix : GATEWAY_EXECUTION_POLICY_NAME ,
89- policyDocument : role . candidatePolicyDocument ( response . gatewayArn ! ) ,
90- } ,
91- async ( ) => {
92- await role . updateTrust ( response . gatewayArn ! ) ;
93- return response ;
94- } ,
95- ) ;
63+ const policySwap = new InlinePolicySwap ( iam , {
64+ roleName : role . roleName ,
65+ policyNamePrefix : GATEWAY_EXECUTION_POLICY_NAME ,
66+ } ) ;
67+ const response = await policySwap . run ( role . candidatePolicyDocument ( ) , async ( ) => {
68+ const created = await retryWhileGatewayRoleChangesPropagate ( ( ) =>
69+ control . send (
70+ new CreateGatewayCommand ( buildGatewayCreateRequest ( { ...input , roleArn : role . roleArn } ) ) ,
71+ ) ,
72+ ) ;
73+ if ( ! created . gatewayArn ) {
74+ throw new Error ( "CreateGateway response did not include the Gateway ARN" ) ;
75+ }
76+ return created ;
77+ } ) ;
78+ return policySwap . run ( role . candidatePolicyDocument ( response . gatewayArn ! ) , async ( ) => {
79+ await role . updateTrust ( response . gatewayArn ! ) ;
80+ return response ;
81+ } ) ;
9682 }
9783
9884 async getGateway ( id : string , options : CoreOptions ) : Promise < GetGatewayResponse > {
@@ -160,17 +146,13 @@ export class GatewayClient implements CoreGatewayClient {
160146 undefined ,
161147 request ,
162148 ) ;
163- return swapInlinePolicyForOperation (
164- iam ,
165- {
166- roleName : role . roleName ,
167- policyNamePrefix : GATEWAY_EXECUTION_POLICY_NAME ,
168- policyDocument : role . candidatePolicyDocument ( configurations ) ,
169- } ,
170- ( ) =>
171- retryWhileGatewayRoleChangesPropagate ( ( ) =>
172- control . send ( new CreateGatewayTargetCommand ( request ) ) ,
173- ) ,
149+ return new InlinePolicySwap ( iam , {
150+ roleName : role . roleName ,
151+ policyNamePrefix : GATEWAY_EXECUTION_POLICY_NAME ,
152+ } ) . run ( role . candidatePolicyDocument ( configurations ) , ( ) =>
153+ retryWhileGatewayRoleChangesPropagate ( ( ) =>
154+ control . send ( new CreateGatewayTargetCommand ( request ) ) ,
155+ ) ,
174156 ) ;
175157 }
176158
0 commit comments