From b42dc1fa89876804c59e9a8e7116561c1675e0ff Mon Sep 17 00:00:00 2001 From: Aayush Thapa Date: Wed, 3 Apr 2024 10:08:32 -0700 Subject: [PATCH 1/4] add new partition to arn generator --- samtranslator/metrics/method_decorator.py | 8 ++++---- samtranslator/model/api/http_api_generator.py | 4 +++- samtranslator/translator/arn_generator.py | 5 +---- tests/translator/test_arn_generator.py | 2 +- tests/translator/test_translator.py | 12 ++++++------ 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/samtranslator/metrics/method_decorator.py b/samtranslator/metrics/method_decorator.py index fa152b1b7..29bb498fb 100644 --- a/samtranslator/metrics/method_decorator.py +++ b/samtranslator/metrics/method_decorator.py @@ -85,13 +85,13 @@ def _send_cw_metric(prefix, name, execution_time_ms, func, args): # type: ignor @overload def cw_timer( *, name: Optional[str] = None, prefix: Optional[str] = None -) -> Callable[[Callable[_PT, _RT]], Callable[_PT, _RT]]: ... +) -> Callable[[Callable[_PT, _RT]], Callable[_PT, _RT]]: + ... @overload -def cw_timer( - _func: Callable[_PT, _RT], name: Optional[str] = None, prefix: Optional[str] = None -) -> Callable[_PT, _RT]: ... +def cw_timer(_func: Callable[_PT, _RT], name: Optional[str] = None, prefix: Optional[str] = None) -> Callable[_PT, _RT]: + ... def cw_timer( diff --git a/samtranslator/model/api/http_api_generator.py b/samtranslator/model/api/http_api_generator.py index f97199037..b2e9f2ec5 100644 --- a/samtranslator/model/api/http_api_generator.py +++ b/samtranslator/model/api/http_api_generator.py @@ -777,7 +777,9 @@ def _add_title(self) -> None: self.definition_body = open_api_editor.openapi @cw_timer(prefix="Generator", name="HttpApi") - def to_cloudformation(self, route53_record_set_groups: Dict[str, Route53RecordSetGroup]) -> Tuple[ + def to_cloudformation( + self, route53_record_set_groups: Dict[str, Route53RecordSetGroup] + ) -> Tuple[ ApiGatewayV2HttpApi, Optional[ApiGatewayV2Stage], Optional[ApiGatewayV2DomainName], diff --git a/samtranslator/translator/arn_generator.py b/samtranslator/translator/arn_generator.py index 852c66c74..5ab68e082 100644 --- a/samtranslator/translator/arn_generator.py +++ b/samtranslator/translator/arn_generator.py @@ -23,15 +23,12 @@ def _region_to_partition(region: str) -> str: "us-isob": "aws-iso-b", "us-gov": "aws-us-gov", "eu-isoe": "aws-iso-e", + "us-isof": "aws-iso-f", } for key, value in region_to_partition_map.items(): if region_string.startswith(key): return value - # Using the ${AWS::Partition} placeholder so that we don't have to add new regions to the static list above - if "iso" in region_string: - return "${AWS::Partition}" - return "aws" diff --git a/tests/translator/test_arn_generator.py b/tests/translator/test_arn_generator.py index d7187ccea..482d55401 100644 --- a/tests/translator/test_arn_generator.py +++ b/tests/translator/test_arn_generator.py @@ -17,7 +17,7 @@ def setUp(self): ("us-isob-east-1", "aws-iso-b"), ("eu-isoe-west-1", "aws-iso-e"), ("US-EAST-1", "aws"), - ("us-isof-east-1", "${AWS::Partition}"), + ("us-isof-east-1", "aws-iso-f"), ] ) def test_get_partition_name(self, region, expected): diff --git a/tests/translator/test_translator.py b/tests/translator/test_translator.py index 8e7e95b01..326086aa8 100644 --- a/tests/translator/test_translator.py +++ b/tests/translator/test_translator.py @@ -165,13 +165,13 @@ def _compare_transform(self, manifest, expected, partition, region): "AWSLambdaRole": f"arn:{partition}:iam::aws:policy/service-role/AWSLambdaRole", } if partition == "aws": - mock_policy_loader.load.return_value["AWSXrayWriteOnlyAccess"] = ( - "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess" - ) + mock_policy_loader.load.return_value[ + "AWSXrayWriteOnlyAccess" + ] = "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess" else: - mock_policy_loader.load.return_value["AWSXRayDaemonWriteAccess"] = ( - f"arn:{partition}:iam::aws:policy/AWSXRayDaemonWriteAccess" - ) + mock_policy_loader.load.return_value[ + "AWSXRayDaemonWriteAccess" + ] = f"arn:{partition}:iam::aws:policy/AWSXRayDaemonWriteAccess" output_fragment = transform(manifest, parameter_values, mock_policy_loader) From c328b51ae080cfb73c31b6b026e2c7f601bf4662 Mon Sep 17 00:00:00 2001 From: Aayush Thapa Date: Wed, 3 Apr 2024 10:15:27 -0700 Subject: [PATCH 2/4] format fix --- samtranslator/translator/arn_generator.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/samtranslator/translator/arn_generator.py b/samtranslator/translator/arn_generator.py index 5ab68e082..43d5dd860 100644 --- a/samtranslator/translator/arn_generator.py +++ b/samtranslator/translator/arn_generator.py @@ -29,6 +29,10 @@ def _region_to_partition(region: str) -> str: if region_string.startswith(key): return value + # Using the ${AWS::Partition} placeholder so that we don't have to add new regions to the static list above + if "iso" in region_string: + return "${AWS::Partition}" + return "aws" From 981e4e13718b22b361126a0486abfc77243b91fd Mon Sep 17 00:00:00 2001 From: Aayush Thapa Date: Wed, 3 Apr 2024 10:19:23 -0700 Subject: [PATCH 3/4] format fix --- samtranslator/metrics/method_decorator.py | 8 ++++---- samtranslator/model/api/http_api_generator.py | 4 +--- tests/translator/test_translator.py | 12 ++++++------ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/samtranslator/metrics/method_decorator.py b/samtranslator/metrics/method_decorator.py index 29bb498fb..fa152b1b7 100644 --- a/samtranslator/metrics/method_decorator.py +++ b/samtranslator/metrics/method_decorator.py @@ -85,13 +85,13 @@ def _send_cw_metric(prefix, name, execution_time_ms, func, args): # type: ignor @overload def cw_timer( *, name: Optional[str] = None, prefix: Optional[str] = None -) -> Callable[[Callable[_PT, _RT]], Callable[_PT, _RT]]: - ... +) -> Callable[[Callable[_PT, _RT]], Callable[_PT, _RT]]: ... @overload -def cw_timer(_func: Callable[_PT, _RT], name: Optional[str] = None, prefix: Optional[str] = None) -> Callable[_PT, _RT]: - ... +def cw_timer( + _func: Callable[_PT, _RT], name: Optional[str] = None, prefix: Optional[str] = None +) -> Callable[_PT, _RT]: ... def cw_timer( diff --git a/samtranslator/model/api/http_api_generator.py b/samtranslator/model/api/http_api_generator.py index b2e9f2ec5..f97199037 100644 --- a/samtranslator/model/api/http_api_generator.py +++ b/samtranslator/model/api/http_api_generator.py @@ -777,9 +777,7 @@ def _add_title(self) -> None: self.definition_body = open_api_editor.openapi @cw_timer(prefix="Generator", name="HttpApi") - def to_cloudformation( - self, route53_record_set_groups: Dict[str, Route53RecordSetGroup] - ) -> Tuple[ + def to_cloudformation(self, route53_record_set_groups: Dict[str, Route53RecordSetGroup]) -> Tuple[ ApiGatewayV2HttpApi, Optional[ApiGatewayV2Stage], Optional[ApiGatewayV2DomainName], diff --git a/tests/translator/test_translator.py b/tests/translator/test_translator.py index 326086aa8..8e7e95b01 100644 --- a/tests/translator/test_translator.py +++ b/tests/translator/test_translator.py @@ -165,13 +165,13 @@ def _compare_transform(self, manifest, expected, partition, region): "AWSLambdaRole": f"arn:{partition}:iam::aws:policy/service-role/AWSLambdaRole", } if partition == "aws": - mock_policy_loader.load.return_value[ - "AWSXrayWriteOnlyAccess" - ] = "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess" + mock_policy_loader.load.return_value["AWSXrayWriteOnlyAccess"] = ( + "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess" + ) else: - mock_policy_loader.load.return_value[ - "AWSXRayDaemonWriteAccess" - ] = f"arn:{partition}:iam::aws:policy/AWSXRayDaemonWriteAccess" + mock_policy_loader.load.return_value["AWSXRayDaemonWriteAccess"] = ( + f"arn:{partition}:iam::aws:policy/AWSXRayDaemonWriteAccess" + ) output_fragment = transform(manifest, parameter_values, mock_policy_loader) From 16897fe242775a3ce968223ce909d42e13e52c32 Mon Sep 17 00:00:00 2001 From: Aayush Thapa Date: Wed, 3 Apr 2024 11:18:37 -0700 Subject: [PATCH 4/4] remove unused code --- samtranslator/translator/arn_generator.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/samtranslator/translator/arn_generator.py b/samtranslator/translator/arn_generator.py index 43d5dd860..5ab68e082 100644 --- a/samtranslator/translator/arn_generator.py +++ b/samtranslator/translator/arn_generator.py @@ -29,10 +29,6 @@ def _region_to_partition(region: str) -> str: if region_string.startswith(key): return value - # Using the ${AWS::Partition} placeholder so that we don't have to add new regions to the static list above - if "iso" in region_string: - return "${AWS::Partition}" - return "aws"