From 3eff0b67941cad6066cbdc68f967adc9fb024cd6 Mon Sep 17 00:00:00 2001 From: Asbjorn Kjaer Date: Sat, 8 Dec 2018 19:06:44 -0800 Subject: [PATCH 1/2] Add __pycache__ to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9b65a52..8df814d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ build .vagrant .eggs *.egg-info +__pycache__ # Installer logs pip-log.txt From 6194f29c4bb16a11503cb585e2cb1d2c715e1f2e Mon Sep 17 00:00:00 2001 From: Asbjorn Kjaer Date: Sat, 8 Dec 2018 20:04:23 -0800 Subject: [PATCH 2/2] Updating for resource refactor --- cinq_collector_dns/__init__.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cinq_collector_dns/__init__.py b/cinq_collector_dns/__init__.py index 0dfc46f..271b7fd 100644 --- a/cinq_collector_dns/__init__.py +++ b/cinq_collector_dns/__init__.py @@ -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' @@ -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 @@ -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) @@ -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'], @@ -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'], @@ -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: @@ -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']