Using base32 encoding to generate DNS records
The Designate driver generate record names by hashing and 64-base encoding the instance ID. The problem is that 64-base encoding can generate hyphens and upper/lower case letters. Hyphens are illegal when it is at the beginning of the name. Name is also case insensitive. So the best solution is to use BASE-32 encoding. Change-Id: Ie98a0a50a609207df041c5f0bc2f622701ee9848 Closes-Bug: #1262789
This commit is contained in:
parent
e20e29bf4b
commit
56dda9825b
@ -140,7 +140,7 @@ class DesignateInstanceEntryFactory(driver.DnsInstanceEntryFactory):
|
||||
def create_entry(self, instance):
|
||||
zone = DesignateDnsZone(id=DNS_DOMAIN_ID, name=DNS_DOMAIN_NAME)
|
||||
# Constructing the hostname by hashing the instance ID.
|
||||
name = base64.urlsafe_b64encode(hashlib.md5(instance).digest())[:11]
|
||||
name = base64.b32encode(hashlib.md5(instance).digest())[:11]
|
||||
hostname = ("%s.%s" % (name, zone.name))
|
||||
#Removing the leading dot if present
|
||||
if hostname.endswith('.'):
|
||||
|
@ -188,7 +188,7 @@ class DesignateInstanceEntryFactoryTest(testtools.TestCase):
|
||||
driver.DNS_DOMAIN_ID = '00000000-0000-0000-0000-000000000000'
|
||||
driver.DNS_DOMAIN_NAME = 'trove.com'
|
||||
driver.DNS_TTL = 3600
|
||||
hashed_id = base64.urlsafe_b64encode(hashlib.md5(instance_id).digest())
|
||||
hashed_id = base64.b32encode(hashlib.md5(instance_id).digest())
|
||||
hashed_id_concat = hashed_id[:11]
|
||||
exp_hostname = ("%s.%s" % (hashed_id_concat, driver.DNS_DOMAIN_NAME))
|
||||
factory = driver.DesignateInstanceEntryFactory()
|
||||
@ -205,7 +205,7 @@ class DesignateInstanceEntryFactoryTest(testtools.TestCase):
|
||||
driver.DNS_DOMAIN_ID = '00000000-0000-0000-0000-000000000000'
|
||||
driver.DNS_DOMAIN_NAME = 'trove.com.'
|
||||
driver.DNS_TTL = 3600
|
||||
hashed_id = base64.urlsafe_b64encode(hashlib.md5(instance_id).digest())
|
||||
hashed_id = base64.b32encode(hashlib.md5(instance_id).digest())
|
||||
hashed_id_concat = hashed_id[:11]
|
||||
exp_hostname = ("%s.%s" %
|
||||
(hashed_id_concat, driver.DNS_DOMAIN_NAME))[:-1]
|
||||
|
Loading…
x
Reference in New Issue
Block a user