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

Adding NS1 URLFWD support and testing

This commit is contained in:
Brian E Clow
2021-05-27 15:43:36 -07:00
parent 9be1195d47
commit 21fcff920e
2 changed files with 40 additions and 2 deletions

View File

@@ -234,7 +234,7 @@ class Ns1Provider(BaseProvider):
SUPPORTS_GEO = True
SUPPORTS_DYNAMIC = True
SUPPORTS = set(('A', 'AAAA', 'ALIAS', 'CAA', 'CNAME', 'MX', 'NAPTR',
'NS', 'PTR', 'SPF', 'SRV', 'TXT'))
'NS', 'PTR', 'SPF', 'SRV', 'TXT', 'URLFWD'))
ZONE_NOT_FOUND_MESSAGE = 'server error: zone not found'
@@ -749,6 +749,23 @@ class Ns1Provider(BaseProvider):
'values': values,
}
def _data_for_URLFWD(self, _type, record):
values = []
for answer in record['short_answers']:
path, target, code, masking, query = answer.split(' ', 4)
values.append({
'path': path,
'target': target,
'code': code,
'masking': masking,
'query': query,
})
return {
'ttl': record['ttl'],
'type': _type,
'values': values,
}
def populate(self, zone, target=False, lenient=False):
self.log.debug('populate: name=%s, target=%s, lenient=%s',
zone.name,
@@ -1244,6 +1261,11 @@ class Ns1Provider(BaseProvider):
for v in record.values]
return {'answers': values, 'ttl': record.ttl}, None
def _params_for_URLFWD(self, record):
values = [(v.path, v.target, v.code, v.masking, v.query)
for v in record.values]
return {'answers': values, 'ttl': record.ttl}, None
def _get_ns1_filters(self, ns1_zone_name):
ns1_filters = {}
ns1_zone = {}

View File

@@ -109,6 +109,17 @@ class TestNs1Provider(TestCase):
'value': 'ca.unit.tests',
},
}))
expected.add(Record.new(zone, 'urlfwd', {
'ttl': 41,
'type': 'URLFWD',
'value': {
'path': '/',
'target': 'http://foo.unit.tests',
'code': 301,
'masking': 2,
'query': 0,
},
}))
ns1_records = [{
'type': 'A',
@@ -164,6 +175,11 @@ class TestNs1Provider(TestCase):
'ttl': 40,
'short_answers': ['0 issue ca.unit.tests'],
'domain': 'unit.tests.',
}, {
'type': 'URLFWD',
'ttl': 41,
'short_answers': ['/ http://foo.unit.tests 301 2 0'],
'domain': 'urlfwd.unit.tests.',
}]
@patch('ns1.rest.records.Records.retrieve')
@@ -345,7 +361,7 @@ class TestNs1Provider(TestCase):
# Test out the create rate-limit handling, then 9 successes
record_create_mock.side_effect = [
RateLimitException('boo', period=0),
] + ([None] * 9)
] + ([None] * 10)
got_n = provider.apply(plan)
self.assertEquals(expected_n, got_n)