From 6346e44c9d83d83ac26a88178b9dba0d2157411a Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Tue, 14 Mar 2017 19:52:36 +0000 Subject: [PATCH 1/2] Be flexible with Route53 Hosted Zone IDs with /hostedzone/ prefix We will continue to store just the unique ID, but since the AWS API returns /hostedzone/, we should accept attempts to pass that back. For example, both just the ID as well as /hostedzone/ work for specifying the HostedZoneId of a ResourceRecordSet in CloudFormation. So we should support that too. Signed-off-by: Scott Greene --- moto/route53/models.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/moto/route53/models.py b/moto/route53/models.py index 15679f0e3..e3896a1c3 100644 --- a/moto/route53/models.py +++ b/moto/route53/models.py @@ -277,7 +277,7 @@ class Route53Backend(BaseBackend): return self.zones.values() def get_hosted_zone(self, id_): - return self.zones.get(id_) + return self.zones.get(id_.lstrip("/hostedzone/")) def get_hosted_zone_by_name(self, name): for zone in self.get_all_hosted_zones(): @@ -285,10 +285,7 @@ class Route53Backend(BaseBackend): return zone def delete_hosted_zone(self, id_): - zone = self.zones.get(id_) - if zone: - del self.zones[id_] - return zone + return self.zones.pop(id_.lstrip("/hostedzone/"), None) def create_health_check(self, health_check_args): health_check_id = str(uuid.uuid4()) From f2b7ba03b4cd8d46621dafbe4da98a69c1b775ee Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Fri, 17 Mar 2017 02:45:58 +0000 Subject: [PATCH 2/2] Forgot that lstrip works on character sets, not substrings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I suppose this is one way to do it. I could have also split and taken the last element. Not sure which is best. 🤔 --- moto/route53/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/moto/route53/models.py b/moto/route53/models.py index e3896a1c3..b823cb915 100644 --- a/moto/route53/models.py +++ b/moto/route53/models.py @@ -277,7 +277,7 @@ class Route53Backend(BaseBackend): return self.zones.values() def get_hosted_zone(self, id_): - return self.zones.get(id_.lstrip("/hostedzone/")) + return self.zones.get(id_.replace("/hostedzone/", "")) def get_hosted_zone_by_name(self, name): for zone in self.get_all_hosted_zones(): @@ -285,7 +285,7 @@ class Route53Backend(BaseBackend): return zone def delete_hosted_zone(self, id_): - return self.zones.pop(id_.lstrip("/hostedzone/"), None) + return self.zones.pop(id_.replace("/hostedzone/", ""), None) def create_health_check(self, health_check_args): health_check_id = str(uuid.uuid4())