Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Resource refactor #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ build
.vagrant
.eggs
*.egg-info
__pycache__

# Installer logs
pip-log.txt
Expand Down
18 changes: 9 additions & 9 deletions cinq_collector_dns/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from dns import zone as dns_zone, query
from dns.rdatatype import to_text as type_to_text


class DNSCollector(BaseCollector):
name = 'DNS'
ns = 'collector_dns'
Expand Down Expand Up @@ -61,7 +62,7 @@ def process_zones(self, zones, account):
for data in zones:
if data['zone_id'] in existing_zones:
zone = DNSZone.get(data['zone_id'])
if zone.update(data):
if zone.update_resource(properties={'comment': data['comment']}, tags=data['tags']):
self.log.debug('Change detected for DNS zone {}/{}'.format(
account.account_name,
zone.name
Expand Down Expand Up @@ -109,10 +110,10 @@ def process_zones(self, zones, account):
for data in zone['records']:
if data['id'] in existing_records:
record = existing_records[data['id']]
if record.update(data):
self.log.debug('Changed detected for DNSRecord {}/{}/{}'.format(
if record.update_resource(properties={'value': data['value']}):
self.log.debug('Change detected for DNSRecord {}/{}/{}'.format(
account.account_name,
zone.name,
zone['name'],
data['name']
))
db.session.add(record.resource)
Expand Down Expand Up @@ -203,7 +204,6 @@ def get_cloudflare_records(self, *, account):

for zobj in self.__cloudflare_list_zones(account=account):
try:
self.log.debug('Processing DNS zone CloudFlare/{}'.format(zobj['name']))
zone = {
'zone_id': get_resource_id('cfz', zobj['name']),
'name': zobj['name'],
Expand All @@ -213,7 +213,7 @@ def get_cloudflare_records(self, *, account):
'records': []
}

for record in self.__cloudflare_list_zone_records(account=account, zoneID=zobj['id']):
for record in self.__cloudflare_list_zone_records(account=account, zone_id=zobj['id']):
zone['records'].append({
'id': get_resource_id('cfr', zobj['id'], ['{}={}'.format(k, v) for k, v in record.items()]),
'zone_id': zone['zone_id'],
Expand Down Expand Up @@ -290,13 +290,13 @@ def __cloudflare_list_zones(self, *, account, **kwargs):

return zones

def __cloudflare_list_zone_records(self, *, account, zoneID, **kwargs):
def __cloudflare_list_zone_records(self, *, account, zone_id, **kwargs):
"""Helper function to list all records on a CloudFlare DNS Zone. Returns a `dict` containing the records and
their information.

Args:
account (:obj:`CloudFlareAccount`): A CloudFlare Account object
zoneID (`int`): Internal CloudFlare ID of the DNS zone
zone_id (`int`): Internal CloudFlare ID of the DNS zone
**kwargs (`dict`): Additional arguments to be consumed by the API endpoint

Returns:
Expand All @@ -310,7 +310,7 @@ def __cloudflare_list_zone_records(self, *, account, zoneID, **kwargs):
kwargs['page'] = page
response = self.__cloudflare_request(
account=account,
path='/zones/{}/dns_records'.format(zoneID),
path='/zones/{}/dns_records'.format(zone_id),
args=kwargs
)
info = response['result_info']
Expand Down