Skip to content

Commit

Permalink
Merge pull request #64 from octodns/list-zones
Browse files Browse the repository at this point in the history
Implement Provider.list_zones for dynamic zone config support
  • Loading branch information
ross authored Oct 23, 2023
2 parents 73a3b0c + 7e404f0 commit c9db2cc
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v0.0.4 - 2023-??-?? - Know your zones

* Support for Provider.list_zones to enable dynamic zone config when operating
as a source

## v0.0.3 - 2023-09-20 - All the commits fit to release

* SPF records can no longer be created,
Expand Down
3 changes: 3 additions & 0 deletions octodns_cloudflare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ def _record_for(self, zone, name, _type, records, lenient):

return record

def list_zones(self):
return sorted(self.zones.keys())

def populate(self, zone, target=False, lenient=False):
self.log.debug(
'populate: name=%s, target=%s, lenient=%s',
Expand Down
36 changes: 36 additions & 0 deletions tests/test_octodns_provider_cloudflare.py
Original file line number Diff line number Diff line change
Expand Up @@ -2108,3 +2108,39 @@ def test_account_id_filter(self):
'account.id': '334234243423aaabb334342aaa343433',
},
)

def test_list_zones(self):
provider = CloudflareProvider(
'test',
'email',
'token',
account_id='334234243423aaabb334342aaa343433',
)

# existing zone with data
with requests_mock() as mock:
base = 'https://api.cloudflare.com/client/v4/zones'

# zones
with open('tests/fixtures/cloudflare-zones-page-1.json') as fh:
mock.get(f'{base}?page=1', status_code=200, text=fh.read())
with open('tests/fixtures/cloudflare-zones-page-2.json') as fh:
mock.get(f'{base}?page=2', status_code=200, text=fh.read())
with open('tests/fixtures/cloudflare-zones-page-3.json') as fh:
mock.get(f'{base}?page=3', status_code=200, text=fh.read())
mock.get(
f'{base}?page=4',
status_code=200,
json={'result': [], 'result_info': {'count': 0, 'per_page': 0}},
)

self.assertEqual(
[
'github.com.',
'github.io.',
'githubusercontent.com.',
'unit.tests.',
'xn--gthub-zsa.com.',
],
provider.list_zones(),
)

0 comments on commit c9db2cc

Please sign in to comment.