Skip to content

Commit d7a04dd

Browse files
Vandita2020Vandita Patidarkddejong
authored
adding isolated regions (#4103)
* adding isolated regions --------- Co-authored-by: Vandita Patidar <[email protected]> Co-authored-by: Kevin DeJong <[email protected]>
1 parent 5c3151a commit d7a04dd

File tree

10 files changed

+19635
-0
lines changed

10 files changed

+19635
-0
lines changed

src/cfnlint/data/schemas/providers/eu_isoe_west_1/__init__.py

+2,792
Large diffs are not rendered by default.

src/cfnlint/data/schemas/providers/us_iso_east_1/__init__.py

+2,792
Large diffs are not rendered by default.

src/cfnlint/data/schemas/providers/us_iso_west_1/__init__.py

+2,792
Large diffs are not rendered by default.

src/cfnlint/data/schemas/providers/us_isob_east_1/__init__.py

+2,792
Large diffs are not rendered by default.

src/cfnlint/data/schemas/providers/us_isob_west_1/__init__.py

+2,792
Large diffs are not rendered by default.

src/cfnlint/data/schemas/providers/us_isof_east_1/__init__.py

+2,792
Large diffs are not rendered by default.

src/cfnlint/data/schemas/providers/us_isof_south_1/__init__.py

+2,792
Large diffs are not rendered by default.

src/cfnlint/helpers.py

+7
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@
115115
"us-gov-west-1": ["us-gov-west-1a", "us-gov-west-1b", "us-gov-west-1c"],
116116
"us-west-1": ["us-west-1a", "us-west-1c"],
117117
"us-west-2": ["us-west-2a", "us-west-2b", "us-west-2c", "us-west-2d"],
118+
# Isolated regions
119+
"us-iso-east-1": ["us-iso-east-1a", "us-iso-east-1b", "us-iso-east-1c"],
120+
"us-iso-west-1": ["us-iso-west-1a", "us-iso-west-1b", "us-iso-west-1c"],
121+
"us-isob-east-1": ["us-isob-east-1a", "us-isob-east-1b", "us-isob-east-1c"],
122+
"us-isof-east-1": ["us-isof-east-1a", "us-isof-east-1b", "us-isof-east-1c"],
123+
"us-isof-south-1": ["us-isof-south-1a", "us-isof-south-1b", "us-isof-south-1c"],
124+
"eu-isoe-west-1": ["eu-isoe-west-1a", "eu-isoe-west-1b", "eu-isoe-west-1c"],
118125
}
119126

120127
REGIONS = list(AVAILABILITY_ZONES.keys())

src/cfnlint/schema/manager.py

+26
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,32 @@ def _update_provider_schema(self, region: str, force: bool = False) -> None:
282282

283283
multiprocessing_logger.debug("Downloading template %s into %s", url, directory)
284284

285+
if "iso" in region:
286+
all_types = ["AWS::CDK::Metadata", "Module"]
287+
cached = ["Module"]
288+
filenames = [
289+
f
290+
for f in os.listdir(directory_pr)
291+
if os.path.isfile(os.path.join(directory_pr, f)) and f != "__init__.py"
292+
]
293+
for filename in filenames:
294+
with open(f"{directory_pr}{filename}", "r+", encoding="utf-8") as fh:
295+
spec = json.load(fh)
296+
all_types.append(spec["typeName"])
297+
cached.append(filename)
298+
299+
with open(f"{directory}__init__.py", encoding="utf-8", mode="w") as f:
300+
f.write("from __future__ import annotations\n\n")
301+
f.write("# pylint: disable=too-many-lines\ntypes: list[str] = [\n")
302+
for rt in sorted(all_types):
303+
f.write(f' "{rt}",\n')
304+
f.write(
305+
"]\n\n# pylint: disable=too-many-lines\ncached: list[str] = [\n"
306+
)
307+
for cache_file in sorted(cached):
308+
f.write(f' "{cache_file}",\n')
309+
f.write("]\n")
310+
285311
# Check to see if we already have the latest version, and if so stop
286312
if not (url_has_newer_version(url) or force):
287313
return

test/unit/module/schema/test_manager.py

+58
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,55 @@ def test_update_resource_spec_cache(
162162
mock_filecmp_cmp.assert_called_once()
163163
mock_os_remove.assert_called_once()
164164

165+
@patch("cfnlint.schema.manager.json.dump")
166+
@patch("cfnlint.schema.manager.REGIONS", ["us-east-1"])
167+
@patch("cfnlint.schema.manager.os.listdir")
168+
@patch("cfnlint.schema.manager.os.path.isfile")
169+
def test_update_resource_for_iso_region(
170+
self,
171+
mock_os_path_isfile,
172+
mock_os_listdir,
173+
mock_json_dump,
174+
):
175+
"""Success update resource spec with cache"""
176+
schema = self.schemas["aws-lambda-codesigningconfig"]
177+
178+
mock_os_listdir.return_value = [
179+
"aws_lambda_codesigningconfig.json",
180+
"__init__.py",
181+
]
182+
mock_os_path_isfile.side_effect = [True, True, True, True]
183+
builtin_module_name = "builtins"
184+
185+
with patch(
186+
"{}.open".format(builtin_module_name), mock_open(read_data=schema)
187+
) as mock_builtin_open:
188+
self.manager._update_provider_schema("us-iso-west-1", False)
189+
mock_json_dump.assert_not_called()
190+
mock_os_listdir.assert_has_calls(
191+
[
192+
call(f"{self.manager._root.path_relative}/us_east_1/"),
193+
]
194+
)
195+
mock_builtin_open.assert_has_calls(
196+
[
197+
call().__enter__(),
198+
call().write("from __future__ import annotations\n\n"),
199+
call().write(
200+
"# pylint: disable=too-many-lines\ntypes: list[str] = [\n"
201+
),
202+
call().write(' "AWS::CDK::Metadata",\n'),
203+
call().write(' "AWS::Lambda::CodeSigningConfig",\n'),
204+
call().write(' "Module",\n'),
205+
call().write(
206+
"]\n\n# pylint: disable=too-many-lines\ncached: list[str] = [\n"
207+
),
208+
call().write(' "Module",\n'),
209+
call().write(' "aws_lambda_codesigningconfig.json",\n'),
210+
call().write("]\n"),
211+
]
212+
)
213+
165214
@patch("cfnlint.schema.manager.url_has_newer_version")
166215
@patch("cfnlint.schema.manager.get_url_retrieve")
167216
@patch("cfnlint.schema.manager.json.dump")
@@ -272,6 +321,15 @@ def test_removed_types(self):
272321
with self.assertRaises(ResourceNotFoundError):
273322
self.manager.get_resource_schema(region, rt)
274323

324+
def test_getting_us_east_1_schema_in_iso(self):
325+
rt = "AWS::EC2::VPC"
326+
327+
schema_us_east_1 = self.manager.get_resource_schema("us-east-1", rt)
328+
schema_iso = self.manager.get_resource_schema("us-iso-east-1", rt)
329+
330+
self.assertDictEqual(schema_us_east_1.schema, schema_iso.schema)
331+
self.assertTrue(schema_iso.is_cached)
332+
275333
def test_type_normalization(self):
276334

277335
rt = "MyCompany::MODULE"

0 commit comments

Comments
 (0)