@@ -102,9 +102,13 @@ def temporary_ini_file():
102
102
yield str (path )
103
103
104
104
105
- def get_cloudformation_exports (region_name , endpoint_url , role_arn , profile_name ):
105
+ def get_cloudformation_exports (
106
+ region_name , endpoint_url , role_arn , profile_name , headers
107
+ ):
106
108
session = create_sdk_session (region_name , profile_name )
107
- temp_credentials = get_temporary_credentials (session , role_arn = role_arn )
109
+ temp_credentials = get_temporary_credentials (
110
+ session , role_arn = role_arn , headers = headers
111
+ )
108
112
cfn_client = session .client (
109
113
"cloudformation" , endpoint_url = endpoint_url , ** temp_credentials
110
114
)
@@ -132,13 +136,13 @@ def __retrieve_args(match):
132
136
133
137
134
138
def render_template (
135
- overrides_string , region_name , endpoint_url , role_arn , profile_name
139
+ overrides_string , region_name , endpoint_url , role_arn , profile_name , headers
136
140
):
137
141
regex = r"{{([-A-Za-z0-9:\s]+?)}}"
138
142
variables = set (str (match ).strip () for match in re .findall (regex , overrides_string ))
139
143
if variables :
140
144
exports = get_cloudformation_exports (
141
- region_name , endpoint_url , role_arn , profile_name
145
+ region_name , endpoint_url , role_arn , profile_name , headers
142
146
)
143
147
invalid_exports = variables - exports .keys ()
144
148
if len (invalid_exports ) > 0 :
@@ -166,15 +170,20 @@ def filter_overrides(overrides, project):
166
170
return overrides
167
171
168
172
169
- def get_overrides (root , region_name , endpoint_url , role_arn , profile_name ):
173
+ def get_overrides (root , region_name , endpoint_url , role_arn , profile_name , headers ):
170
174
if not root :
171
175
return empty_override ()
172
176
173
177
path = root / "overrides.json"
174
178
try :
175
179
with path .open ("r" , encoding = "utf-8" ) as f :
176
180
overrides_raw = render_template (
177
- f .read (), region_name , endpoint_url , role_arn , profile_name
181
+ f .read (),
182
+ region_name ,
183
+ endpoint_url ,
184
+ role_arn ,
185
+ profile_name ,
186
+ headers = headers ,
178
187
)
179
188
except FileNotFoundError :
180
189
LOG .debug ("Override file '%s' not found. No overrides will be applied" , path )
@@ -203,15 +212,22 @@ def get_overrides(root, region_name, endpoint_url, role_arn, profile_name):
203
212
204
213
# pylint: disable=R0914
205
214
# flake8: noqa: C901
206
- def get_hook_overrides (root , region_name , endpoint_url , role_arn , profile_name ):
215
+ def get_hook_overrides (
216
+ root , region_name , endpoint_url , role_arn , profile_name , headers
217
+ ):
207
218
if not root :
208
219
return empty_hook_override ()
209
220
210
221
path = root / "overrides.json"
211
222
try :
212
223
with path .open ("r" , encoding = "utf-8" ) as f :
213
224
overrides_raw = render_template (
214
- f .read (), region_name , endpoint_url , role_arn , profile_name
225
+ f .read (),
226
+ region_name ,
227
+ endpoint_url ,
228
+ role_arn ,
229
+ profile_name ,
230
+ headers = headers ,
215
231
)
216
232
except FileNotFoundError :
217
233
LOG .debug ("Override file '%s' not found. No overrides will be applied" , path )
@@ -258,7 +274,7 @@ def get_hook_overrides(root, region_name, endpoint_url, role_arn, profile_name):
258
274
259
275
260
276
# pylint: disable=R0914,too-many-arguments
261
- def get_inputs (root , region_name , endpoint_url , value , role_arn , profile_name ):
277
+ def get_inputs (root , region_name , endpoint_url , value , role_arn , profile_name , headers ):
262
278
inputs = {}
263
279
if not root :
264
280
return None
@@ -280,7 +296,12 @@ def get_inputs(root, region_name, endpoint_url, value, role_arn, profile_name):
280
296
file_path = path / file
281
297
with file_path .open ("r" , encoding = "utf-8" ) as f :
282
298
overrides_raw = render_template (
283
- f .read (), region_name , endpoint_url , role_arn , profile_name
299
+ f .read (),
300
+ region_name ,
301
+ endpoint_url ,
302
+ role_arn ,
303
+ profile_name ,
304
+ headers = headers ,
284
305
)
285
306
overrides = {}
286
307
for pointer , obj in overrides_raw .items ():
@@ -355,6 +376,7 @@ def get_contract_plugin_client(args, project, overrides, inputs):
355
376
project .type_name ,
356
377
args .log_group_name ,
357
378
args .log_role_arn ,
379
+ headers = {"account_id" : args .source_account , "source_arn" : args .source_arn },
358
380
executable_entrypoint = project .executable_entrypoint ,
359
381
docker_image = args .docker_image ,
360
382
typeconfig = args .typeconfig ,
@@ -378,6 +400,7 @@ def get_contract_plugin_client(args, project, overrides, inputs):
378
400
project .type_name ,
379
401
args .log_group_name ,
380
402
args .log_role_arn ,
403
+ headers = {"account_id" : args .source_account , "source_arn" : args .source_arn },
381
404
typeconfig = args .typeconfig ,
382
405
executable_entrypoint = project .executable_entrypoint ,
383
406
docker_image = args .docker_image ,
@@ -402,6 +425,7 @@ def test(args):
402
425
args .cloudformation_endpoint_url ,
403
426
args .role_arn ,
404
427
args .profile ,
428
+ headers = {"account_id" : args .source_account , "source_arn" : args .source_arn },
405
429
)
406
430
else :
407
431
overrides = get_overrides (
@@ -410,6 +434,7 @@ def test(args):
410
434
args .cloudformation_endpoint_url ,
411
435
args .role_arn ,
412
436
args .profile ,
437
+ headers = {"account_id" : args .source_account , "source_arn" : args .source_arn },
413
438
)
414
439
filter_overrides (overrides , project )
415
440
@@ -422,6 +447,7 @@ def test(args):
422
447
index ,
423
448
args .role_arn ,
424
449
args .profile ,
450
+ headers = {"account_id" : args .source_account , "source_arn" : args .source_arn },
425
451
)
426
452
if not inputs :
427
453
break
@@ -509,6 +535,15 @@ def setup_subparser(subparsers, parents):
509
535
" '~/.cfn-cli/typeConfiguration.json.'"
510
536
),
511
537
)
538
+ parser .add_argument (
539
+ "--source-account" ,
540
+ help = "Source Account key used for Assume Role to Run Contract Tests" ,
541
+ )
542
+
543
+ parser .add_argument (
544
+ "--source-arn" ,
545
+ help = "Source Type Version Arn key used for Assume Role to Run Contract Tests" ,
546
+ )
512
547
513
548
514
549
def _sam_arguments (parser ):
0 commit comments