def get_dns_ip(self, zone_uuid: str) -> str: """Get the DNS A @ record.""" url = '{}/zones/{}/records'.format(self.api, zone_uuid) headers = {'X-Api-Key': self.api_secret} response = get(url, headers=headers) try: tld_a_record = [ entry for entry in response if entry['rrset_type'] == 'A' and entry['rrset_name'] == '@' ] ip_record = tld_a_record[0]['rrset_values'][0] self.validate_subdomain_entries(response) message = 'Discovered IP address of {} for {} DNS A @ record' logger.info(message.format(ip_record, self.domain)) return ip_record except (KeyError, IndexError): message = 'Could not find A record for {}'.format(self.domain) logger.critical(message) exit(EXIT_CODE_1_BAD)
def get_dynamic_ip(self) -> str: """Retrieve the dynamic IP address.""" response = get(self.ip_provider) message = 'Discovered dynamic IP of {} for {}' logger.info(message.format(response['ip'], self.domain)) return response['ip']
def get_zone_uuid(self) -> List[str]: """Get the DNS zone UUID.""" url = '{}/domains/{}'.format(self.api, self.domain) headers = {'X-Api-Key': self.api_secret} response = get(url, headers=headers) try: zone_uuid = response['zone_uuid'] message = 'Discovered Gandi zone UUID of {} for {}' logger.info(message.format(zone_uuid, self.domain)) return zone_uuid except KeyError as exception: message = 'Missing {} from {}' logger.critical(message.format(str(exception), dumps(response))) exit(EXIT_CODE_1_BAD)
def get_dns_ip(self, zone_uuid: str, dns_type: str) -> str: """Get the DNS A (or AAAA for ipv6) @ record.""" url = '{}/zones/{}/records'.format(self.api, zone_uuid) headers = {'X-Api-Key': self.api_secret} response = get(url, headers=headers) tld_a_record = [ entry for entry in response if entry['rrset_type'] == dns_type and entry['rrset_name'] == '@' ] ip_record = '' if len(tld_a_record) > 0: ip_record = tld_a_record[0]['rrset_values'][0] self.validate_subdomain_entries(response) message = 'Discovered IP address of {} for {} DNS {} @ record' logger.info(message.format(ip_record, self.domain, dns_type)) return ip_record