Route53: add CallerReference to the GetHostedZone response (#6911)
This commit is contained in:
parent
368fa07ec3
commit
00cce90984
@ -4,6 +4,8 @@ import itertools
|
|||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from jinja2 import Template
|
from jinja2 import Template
|
||||||
from typing import Any, Dict, List, Optional, Tuple
|
from typing import Any, Dict, List, Optional, Tuple
|
||||||
|
|
||||||
@ -36,6 +38,12 @@ def create_route53_zone_id() -> str:
|
|||||||
return "".join([random.choice(ROUTE53_ID_CHOICE) for _ in range(0, 15)])
|
return "".join([random.choice(ROUTE53_ID_CHOICE) for _ in range(0, 15)])
|
||||||
|
|
||||||
|
|
||||||
|
def create_route53_caller_reference() -> str:
|
||||||
|
timestamp = datetime.now().strftime("%H:%M:%S.%f")
|
||||||
|
random_string = "".join(random.choice(string.ascii_letters) for _ in range(6))
|
||||||
|
return f"{random_string} {timestamp}"
|
||||||
|
|
||||||
|
|
||||||
class DelegationSet(BaseModel):
|
class DelegationSet(BaseModel):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -310,6 +318,7 @@ class FakeZone(CloudFormationModel):
|
|||||||
name: str,
|
name: str,
|
||||||
id_: str,
|
id_: str,
|
||||||
private_zone: bool,
|
private_zone: bool,
|
||||||
|
caller_reference: str,
|
||||||
comment: Optional[str] = None,
|
comment: Optional[str] = None,
|
||||||
delegation_set: Optional[DelegationSet] = None,
|
delegation_set: Optional[DelegationSet] = None,
|
||||||
):
|
):
|
||||||
@ -318,6 +327,7 @@ class FakeZone(CloudFormationModel):
|
|||||||
self.vpcs: List[Dict[str, Any]] = []
|
self.vpcs: List[Dict[str, Any]] = []
|
||||||
if comment is not None:
|
if comment is not None:
|
||||||
self.comment = comment
|
self.comment = comment
|
||||||
|
self.caller_reference = caller_reference
|
||||||
self.private_zone = private_zone
|
self.private_zone = private_zone
|
||||||
self.rrsets: List[RecordSet] = []
|
self.rrsets: List[RecordSet] = []
|
||||||
self.delegation_set = delegation_set
|
self.delegation_set = delegation_set
|
||||||
@ -503,12 +513,14 @@ class Route53Backend(BaseBackend):
|
|||||||
self,
|
self,
|
||||||
name: str,
|
name: str,
|
||||||
private_zone: bool,
|
private_zone: bool,
|
||||||
|
caller_reference: Optional[str] = None,
|
||||||
vpcid: Optional[str] = None,
|
vpcid: Optional[str] = None,
|
||||||
vpcregion: Optional[str] = None,
|
vpcregion: Optional[str] = None,
|
||||||
comment: Optional[str] = None,
|
comment: Optional[str] = None,
|
||||||
delegation_set_id: Optional[str] = None,
|
delegation_set_id: Optional[str] = None,
|
||||||
) -> FakeZone:
|
) -> FakeZone:
|
||||||
new_id = create_route53_zone_id()
|
new_id = create_route53_zone_id()
|
||||||
|
caller_reference = caller_reference or create_route53_caller_reference()
|
||||||
delegation_set = self.create_reusable_delegation_set(
|
delegation_set = self.create_reusable_delegation_set(
|
||||||
caller_reference=f"DelSet_{name}", delegation_set_id=delegation_set_id
|
caller_reference=f"DelSet_{name}", delegation_set_id=delegation_set_id
|
||||||
)
|
)
|
||||||
@ -518,6 +530,7 @@ class Route53Backend(BaseBackend):
|
|||||||
new_zone = FakeZone(
|
new_zone = FakeZone(
|
||||||
name,
|
name,
|
||||||
new_id,
|
new_id,
|
||||||
|
caller_reference=caller_reference,
|
||||||
private_zone=private_zone,
|
private_zone=private_zone,
|
||||||
comment=comment,
|
comment=comment,
|
||||||
delegation_set=delegation_set,
|
delegation_set=delegation_set,
|
||||||
|
@ -66,6 +66,7 @@ class Route53(BaseResponse):
|
|||||||
vpcregion = zone_request["VPC"].get("VPCRegion", None)
|
vpcregion = zone_request["VPC"].get("VPCRegion", None)
|
||||||
|
|
||||||
name = zone_request["Name"]
|
name = zone_request["Name"]
|
||||||
|
caller_reference = zone_request["CallerReference"]
|
||||||
|
|
||||||
if name[-1] != ".":
|
if name[-1] != ".":
|
||||||
name += "."
|
name += "."
|
||||||
@ -75,6 +76,7 @@ class Route53(BaseResponse):
|
|||||||
name,
|
name,
|
||||||
comment=comment,
|
comment=comment,
|
||||||
private_zone=private_zone,
|
private_zone=private_zone,
|
||||||
|
caller_reference=caller_reference,
|
||||||
vpcid=vpcid,
|
vpcid=vpcid,
|
||||||
vpcregion=vpcregion,
|
vpcregion=vpcregion,
|
||||||
delegation_set_id=delegation_set_id,
|
delegation_set_id=delegation_set_id,
|
||||||
@ -619,6 +621,7 @@ GET_HOSTED_ZONE_RESPONSE = """<GetHostedZoneResponse xmlns="https://route53.amaz
|
|||||||
<HostedZone>
|
<HostedZone>
|
||||||
<Id>/hostedzone/{{ zone.id }}</Id>
|
<Id>/hostedzone/{{ zone.id }}</Id>
|
||||||
<Name>{{ zone.name }}</Name>
|
<Name>{{ zone.name }}</Name>
|
||||||
|
<CallerReference>{{ zone.caller_reference }}</CallerReference>
|
||||||
<ResourceRecordSetCount>{{ zone.rrsets|count }}</ResourceRecordSetCount>
|
<ResourceRecordSetCount>{{ zone.rrsets|count }}</ResourceRecordSetCount>
|
||||||
<Config>
|
<Config>
|
||||||
{% if zone.comment %}
|
{% if zone.comment %}
|
||||||
|
@ -32,6 +32,19 @@ def test_create_hosted_zone():
|
|||||||
assert "<Name>testdns.aws.com.</Name>" in requests.get(location).text
|
assert "<Name>testdns.aws.com.</Name>" in requests.get(location).text
|
||||||
|
|
||||||
|
|
||||||
|
@mock_route53
|
||||||
|
def test_get_hosted_zone():
|
||||||
|
conn = boto3.client("route53", region_name="us-east-1")
|
||||||
|
name = "testdns.aws.com."
|
||||||
|
caller_ref = str(hash("foo"))
|
||||||
|
|
||||||
|
zone = conn.create_hosted_zone(Name=name, CallerReference=caller_ref)["HostedZone"]
|
||||||
|
|
||||||
|
res = conn.get_hosted_zone(Id=zone["Id"])
|
||||||
|
assert res["HostedZone"]["Name"] == name
|
||||||
|
assert res["HostedZone"]["CallerReference"] == caller_ref
|
||||||
|
|
||||||
|
|
||||||
@mock_route53
|
@mock_route53
|
||||||
def test_list_hosted_zones():
|
def test_list_hosted_zones():
|
||||||
conn = boto3.client("route53", region_name="us-east-1")
|
conn = boto3.client("route53", region_name="us-east-1")
|
||||||
|
Loading…
Reference in New Issue
Block a user