1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00

Handling PR Review comments.

- Added Specific exceptions
- str() instead of concatenation
- removed zone not found warning
This commit is contained in:
Maikel Poot
2019-09-30 13:18:57 +02:00
parent a035ee8c84
commit 637c254778
2 changed files with 23 additions and 10 deletions

View File

@@ -15,6 +15,18 @@ from transip.service.domain import DomainService
from transip.service.objects import DnsEntry from transip.service.objects import DnsEntry
class TransipException(Exception):
pass
class TransipConfigException(TransipException):
pass
class TransipNewZoneException(TransipException):
pass
class TransipProvider(BaseProvider): class TransipProvider(BaseProvider):
''' '''
Transip DNS provider Transip DNS provider
@@ -55,7 +67,9 @@ class TransipProvider(BaseProvider):
elif key is not None: elif key is not None:
self._client = DomainService(account, private_key=key) self._client = DomainService(account, private_key=key)
else: else:
raise Exception('Missing `key` of `key_file` parameter in config') raise TransipConfigException(
'Missing `key` of `key_file` parameter in config'
)
self.account = account self.account = account
self.key = key self.key = key
@@ -74,13 +88,12 @@ class TransipProvider(BaseProvider):
zoneInfo = self._client.get_info(zone.name[:-1]) zoneInfo = self._client.get_info(zone.name[:-1])
except WebFault as e: except WebFault as e:
if e.fault.faultcode == '102' and target is False: if e.fault.faultcode == '102' and target is False:
self.log.warning( # Zone not found in account, and not a target so just
'populate: (%s) Zone %s not found in account ', # leave an empty zone.
e.fault.faultcode, zone.name)
return exists return exists
elif e.fault.faultcode == '102' and target is True: elif e.fault.faultcode == '102' and target is True:
self.log.warning('populate: Transip can\'t create new zones') self.log.warning('populate: Transip can\'t create new zones')
raise Exception( raise TransipNewZoneException(
('populate: ({}) Transip used ' + ('populate: ({}) Transip used ' +
'as target for non-existing zone: {}').format( 'as target for non-existing zone: {}').format(
e.fault.faultcode, zone.name)) e.fault.faultcode, zone.name))
@@ -146,7 +159,7 @@ class TransipProvider(BaseProvider):
self.log.warning(('_apply: Set DNS returned ' + self.log.warning(('_apply: Set DNS returned ' +
'one or more errors: {}').format( 'one or more errors: {}').format(
e.fault.faultstring)) e.fault.faultstring))
raise Exception(200, e.fault.faultstring) raise TransipException(200, e.fault.faultstring)
self._currentZone = {} self._currentZone = {}
@@ -220,7 +233,7 @@ class TransipProvider(BaseProvider):
def _parse_to_fqdn(self, value): def _parse_to_fqdn(self, value):
# Enforce switch from suds.sax.text.Text to string # Enforce switch from suds.sax.text.Text to string
value = '' + value value = str(value)
# TransIP allows '@' as value to alias the root record. # TransIP allows '@' as value to alias the root record.
# this provider won't set an '@' value, but can be an existing record # this provider won't set an '@' value, but can be an existing record
@@ -245,7 +258,7 @@ class TransipProvider(BaseProvider):
_values = [] _values = []
for record in records: for record in records:
# Enforce switch from suds.sax.text.Text to string # Enforce switch from suds.sax.text.Text to string
_values.append('' + record['content']) _values.append(str(record['content']))
return { return {
'ttl': self._get_lowest_ttl(records), 'ttl': self._get_lowest_ttl(records),

View File

@@ -170,7 +170,7 @@ N4OiVz1I3rbZGYa396lpxO6ku8yCglisL1yrSP6DdEUp66ntpKVd
zone = Zone('notfound.unit.tests.', []) zone = Zone('notfound.unit.tests.', [])
provider.populate(zone, True) provider.populate(zone, True)
self.assertEquals(str('Exception'), self.assertEquals(str('TransipNewZoneException'),
str(ctx.exception.__class__.__name__)) str(ctx.exception.__class__.__name__))
self.assertEquals( self.assertEquals(
@@ -271,5 +271,5 @@ N4OiVz1I3rbZGYa396lpxO6ku8yCglisL1yrSP6DdEUp66ntpKVd
# Changes should not be set due to an Exception # Changes should not be set due to an Exception
self.assertEqual([], changes) self.assertEqual([], changes)
self.assertEquals(str('Exception'), self.assertEquals(str('TransipException'),
str(ctx.exception.__class__.__name__)) str(ctx.exception.__class__.__name__))