mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Generate the zone name following the spec of Google Cloud DNS
Zone name must begin with a letter, end with a letter or digit, and only contain lowercase letters, digits or dashes, and be 63 characters or less. For instance, a reverse zone of IPv6 may violate the spec on the first character and the length of the zone name.
This commit is contained in:
@@ -127,9 +127,12 @@ class GoogleCloudProvider(BaseProvider):
|
||||
:type return: new google.cloud.dns.ManagedZone
|
||||
"""
|
||||
# Zone name must begin with a letter, end with a letter or digit,
|
||||
# and only contain lowercase letters, digits or dashes
|
||||
# and only contain lowercase letters, digits or dashes,
|
||||
# and be 63 characters or less
|
||||
zone_name = '{}-{}'.format(
|
||||
dns_name[:-1].replace('.', '-'), uuid4().hex)
|
||||
dns_name.replace('.', '-'), uuid4().hex)[:63]
|
||||
if not zone_name[:1].isalpha():
|
||||
zone_name = 'zone-{}'.format(zone_name[:58])
|
||||
|
||||
gcloud_zone = self.gcloud_client.zone(
|
||||
name=zone_name,
|
||||
|
@@ -427,3 +427,18 @@ class TestGoogleCloudProvider(TestCase):
|
||||
|
||||
mock_zone.create.assert_called()
|
||||
provider.gcloud_client.zone.assert_called()
|
||||
|
||||
def test__create_zone_ip6_arpa(self):
|
||||
def _create_dummy_zone(name, dns_name):
|
||||
return DummyGoogleCloudZone(name=name, dns_name=dns_name)
|
||||
|
||||
provider = self._get_provider()
|
||||
|
||||
provider.gcloud_client = Mock()
|
||||
provider.gcloud_client.zone = Mock(side_effect=_create_dummy_zone)
|
||||
|
||||
mock_zone = \
|
||||
provider._create_gcloud_zone('0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa')
|
||||
|
||||
self.assertRegexpMatches(mock_zone.name, '^[a-z][a-z0-9-]*[a-z0-9]$')
|
||||
self.assertEqual(len(mock_zone.name), 63)
|
||||
|
Reference in New Issue
Block a user