Skip to content

Commit c616d66

Browse files
committed
fix lint issues
1 parent 0f8b474 commit c616d66

File tree

5 files changed

+43
-28
lines changed

5 files changed

+43
-28
lines changed

samtranslator/model/api/api_generator.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ def _construct_api_domain( # noqa: PLR0912, PLR0915
612612

613613
return ApiDomainResponse(domain, basepath_resource_list, record_set_group)
614614

615-
def _construct_api_domain_v2(
615+
def _construct_api_domain_v2( # noqa: PLR0912, PLR0915
616616
self, rest_api: ApiGatewayRestApi, route53_record_set_groups: Any
617617
) -> ApiDomainResponseV2:
618618
"""
@@ -671,12 +671,7 @@ def _construct_api_domain_v2(
671671

672672
basepath_resource_list: List[ApiGatewayBasePathMappingV2] = []
673673
if basepaths is None:
674-
basepath_mapping = ApiGatewayBasePathMappingV2(
675-
self.logical_id + "BasePathMapping", attributes=self.passthrough_resource_attributes
676-
)
677-
basepath_mapping.DomainNameArn = ref(domain_name_arn)
678-
basepath_mapping.RestApiId = ref(rest_api.logical_id)
679-
basepath_mapping.Stage = ref(rest_api.logical_id + ".Stage")
674+
basepath_mapping = self._create_basepath_mapping(domain_name_arn, rest_api)
680675
basepath_resource_list.extend([basepath_mapping])
681676
else:
682677
sam_expect(basepaths, self.logical_id, "Domain.BasePath").to_be_a_list_of(ExpectedType.STRING)
@@ -723,18 +718,22 @@ def _construct_api_domain_v2(
723718
)
724719

725720
if not record_set_group:
726-
record_set_group = Route53RecordSetGroup(logical_id, attributes=self.passthrough_resource_attributes)
727-
if "HostedZoneId" in route53:
728-
record_set_group.HostedZoneId = route53.get("HostedZoneId")
729-
if "HostedZoneName" in route53:
730-
record_set_group.HostedZoneName = route53.get("HostedZoneName")
731-
record_set_group.RecordSets = []
721+
record_set_group = self._get_record_set_group(logical_id, route53)
732722
route53_record_set_groups[logical_id] = record_set_group
733723

734724
record_set_group.RecordSets += self._construct_record_sets_for_domain(self.domain, domain_name, route53)
735725

736726
return ApiDomainResponseV2(domain, basepath_resource_list, record_set_group)
737727

728+
def _get_record_set_group(self, logical_id: str, route53: Dict[str, Any]) -> Route53RecordSetGroup:
729+
record_set_group = Route53RecordSetGroup(logical_id, attributes=self.passthrough_resource_attributes)
730+
if "HostedZoneId" in route53:
731+
record_set_group.HostedZoneId = route53.get("HostedZoneId")
732+
if "HostedZoneName" in route53:
733+
record_set_group.HostedZoneName = route53.get("HostedZoneName")
734+
record_set_group.RecordSets = []
735+
return record_set_group
736+
738737
def _construct_single_record_set_group(
739738
self, domain: Dict[str, Any], api_domain_name: str, route53: Any
740739
) -> Route53RecordSetGroup:
@@ -799,6 +798,17 @@ def _construct_alias_target(self, domain: Dict[str, Any], api_domain_name: str,
799798
alias_target["DNSName"] = route53.get("DistributionDomainName")
800799
return alias_target
801800

801+
def _create_basepath_mapping(
802+
self, domain_name_arn: PassThrough, rest_api: ApiGatewayRestApi
803+
) -> ApiGatewayBasePathMappingV2:
804+
basepath_mapping = ApiGatewayBasePathMappingV2(
805+
self.logical_id + "BasePathMapping", attributes=self.passthrough_resource_attributes
806+
)
807+
basepath_mapping.DomainNameArn = ref(domain_name_arn)
808+
basepath_mapping.RestApiId = ref(rest_api.logical_id)
809+
basepath_mapping.Stage = ref(rest_api.logical_id + ".Stage")
810+
return basepath_mapping
811+
802812
@cw_timer(prefix="Generator", name="Api")
803813
def to_cloudformation(
804814
self, redeploy_restapi_parameters: Optional[Any], route53_record_set_groups: Dict[str, Route53RecordSetGroup]
@@ -808,8 +818,11 @@ def to_cloudformation(
808818
:returns: a tuple containing the RestApi, Deployment, and Stage for an empty Api.
809819
:rtype: tuple
810820
"""
821+
api_domain_response: ApiDomainResponseV2 | ApiDomainResponse
822+
domain: Resource | None
823+
basepath_mapping: List[ApiGatewayBasePathMapping] | List[ApiGatewayBasePathMappingV2] | None
811824
rest_api = self._construct_rest_api()
812-
if self.endpoint_configuration == "PRIVATE":
825+
if self.endpoint_configuration and self.endpoint_configuration.get("Type") == "PRIVATE":
813826
api_domain_response = self._construct_api_domain_v2(rest_api, route53_record_set_groups)
814827
domain = api_domain_response.domain
815828
basepath_mapping = api_domain_response.apigw_basepath_mapping_list
@@ -840,7 +853,9 @@ def to_cloudformation(
840853
List[Resource],
841854
Tuple[Resource],
842855
List[LambdaPermission],
856+
List[Resource],
843857
List[ApiGatewayBasePathMapping],
858+
List[ApiGatewayBasePathMappingV2],
844859
],
845860
] = []
846861

tests/translator/input/api_with_custom_domains_private.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ Resources:
4444
Types:
4545
- PRIVATE
4646
SecurityPolicy: TLS_1_2
47-
RegionalCertificateArn: !Ref CertificateArn
47+
CertificateArn: !Ref CertificateArn
4848

4949
ApiMapping:
5050
Type: AWS::ApiGateway::BasePathMappingV2
5151
Properties:
52-
DomainName: !Ref ApiDomainName
52+
DomainNameArn: !Ref ApiDomainName
5353
RestApiId: !Ref MyApi
5454
Stage: prod
5555

tests/translator/output/api_with_custom_domains_private.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
"Resources": {
3434
"ApiDomainName": {
3535
"Properties": {
36+
"CertificateArn": {
37+
"Ref": "CertificateArn"
38+
},
3639
"DomainName": {
3740
"Ref": "DomainName"
3841
},
@@ -41,16 +44,13 @@
4144
"PRIVATE"
4245
]
4346
},
44-
"RegionalCertificateArn": {
45-
"Ref": "CertificateArn"
46-
},
4747
"SecurityPolicy": "TLS_1_2"
4848
},
4949
"Type": "AWS::ApiGateway::DomainNameV2"
5050
},
5151
"ApiMapping": {
5252
"Properties": {
53-
"DomainName": {
53+
"DomainNameArn": {
5454
"Ref": "ApiDomainName"
5555
},
5656
"RestApiId": {

tests/translator/output/aws-cn/api_with_custom_domains_private.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
"Resources": {
3434
"ApiDomainName": {
3535
"Properties": {
36+
"CertificateArn": {
37+
"Ref": "CertificateArn"
38+
},
3639
"DomainName": {
3740
"Ref": "DomainName"
3841
},
@@ -41,16 +44,13 @@
4144
"PRIVATE"
4245
]
4346
},
44-
"RegionalCertificateArn": {
45-
"Ref": "CertificateArn"
46-
},
4747
"SecurityPolicy": "TLS_1_2"
4848
},
4949
"Type": "AWS::ApiGateway::DomainNameV2"
5050
},
5151
"ApiMapping": {
5252
"Properties": {
53-
"DomainName": {
53+
"DomainNameArn": {
5454
"Ref": "ApiDomainName"
5555
},
5656
"RestApiId": {

tests/translator/output/aws-us-gov/api_with_custom_domains_private.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
"Resources": {
3434
"ApiDomainName": {
3535
"Properties": {
36+
"CertificateArn": {
37+
"Ref": "CertificateArn"
38+
},
3639
"DomainName": {
3740
"Ref": "DomainName"
3841
},
@@ -41,16 +44,13 @@
4144
"PRIVATE"
4245
]
4346
},
44-
"RegionalCertificateArn": {
45-
"Ref": "CertificateArn"
46-
},
4747
"SecurityPolicy": "TLS_1_2"
4848
},
4949
"Type": "AWS::ApiGateway::DomainNameV2"
5050
},
5151
"ApiMapping": {
5252
"Properties": {
53-
"DomainName": {
53+
"DomainNameArn": {
5454
"Ref": "ApiDomainName"
5555
},
5656
"RestApiId": {

0 commit comments

Comments
 (0)