def _find_managed_zone_id(self, domain): """ Find the managed zone for a given domain. :param str domain: The domain for which to find the managed zone. :returns: The ID of the managed zone, if found. :rtype: str :raises certbot.errors.PluginError: if the managed zone cannot be found. """ zone_dns_name_guesses = dns_common.base_domain_name_guesses(domain) mz = self.dns.managedZones() # managedZones | pylint: disable=no-member for zone_name in zone_dns_name_guesses: try: request = mz.list(project=self.project_id, dnsName=zone_name + '.') response = request.execute() zones = response['managedZones'] except googleapiclient_errors.Error as e: raise errors.PluginError( 'Encountered error finding managed zone: {0}'.format(e)) for zone in zones: zone_id = zone['id'] if 'privateVisibilityConfig' not in zone: logger.debug('Found id of %s for %s using name %s', zone_id, domain, zone_name) return zone_id raise errors.PluginError( 'Unable to determine managed zone for {0} using zone names: {1}.'. format(domain, zone_dns_name_guesses))
def get_zone_id_by_domain(self, domain): """ Requests all dns zones from your Hetzner account and searches for a specific one to determine the ID of it :param domain: Name of dns zone where the record should be searched :return: The ID of the zone that is SLD and TLD of ``domain`` - if found :raises ._MalformedResponseException: If the response is missing expected values or is invalid JSON :raises ._ZoneNotFoundException: If no zone with the SLD and TLD of ``domain`` is found in your Hetzner account :raises ._NotAuthorizedException: If Hetzner does not accept the authorization credentials :raises requests.exceptions.ConnectionError: If the API request fails :rtype: str """ domain_name_guesses = dns_common.base_domain_name_guesses(domain) zones_response = requests.get( url="{0}/zones".format(HETZNER_API_ENDPOINT), headers=self._headers, ) if zones_response.status_code == 401: raise _NotAuthorizedException() try: zones = zones_response.json()['zones'] # Find the most specific domain listed in the available zones for guess in domain_name_guesses: for zone in zones: if zone['name'] == guess: return zone['id'] except (KeyError, UnicodeDecodeError, ValueError) as exception: raise _MalformedResponseException(exception) raise _ZoneNotFoundException(domain)
def _find_zone_and_host(self, domain): """ Find the zone and host for a given domain. :param str domain: The domain for which to find the zone_id. :returns: The zone name and host name, if found. :raises certbot.errors.PluginError: if no zone_id is found. """ zone_name_guesses = dns_common.base_domain_name_guesses(domain) for zone_name in zone_name_guesses: try: cloudns_api.validation.is_domain_name(zone_name) except cloudns_api.validation.ValidationError: continue logger.debug(f"Looking up zone {zone_name}.") try: self._api_request(cloudns_api.zone.get, domain_name=zone_name) except ApiErrorResponse: logger.debug(f"Zone {zone_name} not found") else: logger.debug(f"Found zone {zone_name} for {domain}.") return zone_name, domain[:-len(zone_name) - 1] raise errors.PluginError( f"Unable to find zone for {domain} using zone names: " f"{', '.join(zone_name_guesses)}.\n Please confirm that the " f"domain name has been entered correctly and is already " f"associated with the supplied ClouDNS account.")
def _find_domain_id(self, domain): """ Find the domain_id for a given domain. :param str domain: The domain for which to find the domain_id. :raises errors.PluginError: if the domain_id cannot be found. """ domain_name_guesses = dns_common.base_domain_name_guesses(domain) for domain_name in domain_name_guesses: try: if hasattr(self.provider, 'options'): # For Lexicon 2.x self.provider.options['domain'] = domain_name else: # For Lexicon 3.x self.provider.domain = domain_name self.provider.authenticate() return # If `authenticate` doesn't throw an exception, we've found the right name except HTTPError as e: result = self._handle_http_error(e, domain_name) if result: raise result except Exception as e: # pylint: disable=broad-except result = self._handle_general_error(e, domain_name) if result: raise result raise errors.PluginError('Unable to determine zone identifier for {0} using zone names: {1}' .format(domain, domain_name_guesses))
def _find_domain(self, domain_name): """ Find the domain object for a given domain name. :param str domain_name: The domain name for which to find the corresponding Domain. :returns: The Domain, if found. :rtype: `~digitalocean.Domain` :raises certbot.errors.PluginError: if no matching Domain is found. """ domain_name_guesses = dns_common.base_domain_name_guesses(domain_name) domains = self.manager.get_all_domains() for guess in domain_name_guesses: matches = [domain for domain in domains if domain.name == guess] if matches: domain = matches[0] logger.debug('Found base domain for %s using name %s', domain_name, guess) return domain raise errors.PluginError( 'Unable to determine base domain for {0} using names: {1}.'.format( domain_name, domain_name_guesses))
def _find_domain(self, record_name): """ If 'base_domain' option is specified check if the requested domain matches this base domain and return it. If not explicitly specified find the closest domain with an SOA record for the given domain name. :param str record_name: The record name for which to find the base domain. :returns: The domain, if found. :rtype: str :raises certbot.errors.PluginError: if no SOA record can be found. """ if self.base_domain: if not record_name.endswith(self.base_domain): raise errors.PluginError( 'Requested domain {0} does not match specified base ' 'domain {1}.'.format(record_name, self.base_domain)) else: return self.base_domain else: domain_name_guesses = dns_common.base_domain_name_guesses( record_name) # Loop through until we find an authoritative SOA record for guess in domain_name_guesses: if self._query_soa(guess): return guess raise errors.PluginError( 'Unable to determine base domain for {0} using names: {1}.'. format(record_name, domain_name_guesses))
def get_base_domain(self, record): """ Extrat the "sub_domain" and "base_domain" for DNSPOD from given record :param str record: The record name (typically beginning with "_acme-challenge."). :returns: The sub_domain and domain, if found. :rtype: (str, str) :raises certbot.errors.PluginError: if no sub_domain is found. """ domain_name_guesses = dns_common.base_domain_name_guesses(record) domains = self._find_all_domains() for guess in domain_name_guesses: matches = [domain for domain in domains if domain == guess] if len(matches) > 0: domain = matches[0] logger.debug('Found base domain for %s using name %s', record, guess) sub_domain = record.rpartition("." + domain)[0] base_domain = domain logger.debug(u"%s => %s + %s", record, sub_domain, base_domain) return sub_domain, base_domain raise errors.PluginError( 'Unable to determine base domain for {0} using names: {1}.'.format( record, domain_name_guesses))
def _find_domain(self, domain_name): """ Find the base domain name for a given domain name. :param str domain_name: The domain name for which to find the corresponding base domain. :returns: The base domain name, if found. :rtype: str :raises certbot.errors.PluginError: if no matching domain is found. """ domain_name_guesses = dns_common.base_domain_name_guesses(domain_name) for guess in domain_name_guesses: logging.debug('Testing {0} for domain {1}...'.format(guess, domain_name)) try: info = self.inwx.domain.info({'domain': guess})['resData'] except: continue if not 'status' in info: raise errors.PluginError('No status for INWX domain {0}'.format(guess)) if 'OK' != info['status']: raise errors.PluginError('Not OK status for INWX domain {0}'.format(guess)) return guess raise errors.PluginError('Unable to determine base domain for {0} using names: {1}.'.format(domain_name, domain_name_guesses))
def add_txt_record(self, domain, record_name, record_content, record_ttl): """ Add a TXT record using the supplied information. :param str domain: The domain to use to look up the CFProxy zone. :param str record_name: The record name (typically beginning with '_acme-challenge.'). :param str record_content: The record content (typically the challenge validation). :param int record_ttl: The record TTL (number of seconds that the record may be cached). :raises certbot.errors.PluginError: if an error occurs communicating with the CFProxy API """ zone_alts = dns_common.base_domain_name_guesses(domain) for alt in zone_alts: data = { 'rectype': 'TXT', 'zone': alt, 'rec': record_name, 'value': record_content, 'ttl': record_ttl, 'user': self.user, 'key': self.key } try: logger.debug('Attempting to add record to zone %s: %s', domain, data) r = requests.post(self.api_ep + "/add", json=data) if r.json()['success']: return except requests.exceptions.RequestException as e: logger.error('Encountered Error adding TXT record: %d %s', e, e) raise errors.PluginError( 'Error communicating with the CFProxy API: {0}'.format(e))
def _find_managed_zone_id(self, domain): """ Find the managed zone for a given domain. :param str domain: The domain for which to find the managed zone. :returns: The ID of the managed zone, if found. :rtype: str :raises certbot.errors.PluginError: if the managed zone cannot be found. """ zone_dns_name_guesses = dns_common.base_domain_name_guesses(domain) mz = self.dns.managedZones() # managedZones | pylint: disable=no-member for zone_name in zone_dns_name_guesses: try: request = mz.list(project=self.project_id, dnsName=zone_name + '.') response = request.execute() zones = response['managedZones'] except googleapiclient_errors.Error as e: raise errors.PluginError('Encountered error finding managed zone: {0}' .format(e)) if len(zones) > 0: zone_id = zones[0]['id'] logger.debug('Found id of %s for %s using name %s', zone_id, domain, zone_name) return zone_id raise errors.PluginError('Unable to determine managed zone for {0} using zone names: {1}.' .format(domain, zone_dns_name_guesses))
def _find_managed_zone(self, domain): """ Find the managed zone for a given domain. :param str domain: The domain for which to find the managed zone. :returns: The name of the managed zone, if found. :rtype: str :raises certbot.errors.PluginError: if the managed zone cannot be found. """ try: azure_zones = self.dns_client.zones.list() # TODO - catch errors azure_zones_list = [] while True: for zone in azure_zones.current_page: azure_zones_list.append(zone.name) azure_zones.next() except StopIteration: pass except CloudError as e: logger.error('Error finding zone: %s', e) raise errors.PluginError( 'Error finding zone form the Azure DNS API: {0}'.format(e)) zone_dns_name_guesses = dns_common.base_domain_name_guesses(domain) for zone_name in zone_dns_name_guesses: if zone_name in azure_zones_list: return zone_name raise errors.PluginError( 'Unable to determine managed zone for {0} using zone names: {1}.'. format(domain, zone_dns_name_guesses))
def _find_managed_zone_id(self, domain): """ Find the managed zone for a given domain. :param str domain: The domain for which to find the managed zone. :returns: The ID of the managed zone, if found. :rtype: str :raises certbot.errors.PluginError: if the managed zone cannot be found. """ zone_dns_name_guesses = dns_common.base_domain_name_guesses(domain) purchases_list = self._api_request("purchase", "GET", "") for purchase in purchases_list["data"]: purchase_detail = self._api_request( "/purchase/details/" + purchase, "GET", "") if "domain_id" in purchase_detail["data"]: domain_detail = self._api_request( "/domain/details/" + str(purchase_detail["data"]["domain_id"]), "GET", "") for zone_name in zone_dns_name_guesses: # get the zone id if zone_name == domain_detail["data"]["domain_name"]: logger.debug("looking for zone: %s", zone_name) zone_id = domain_detail["data"]["id"] return zone_id, zone_name else: pass return None, None
def _find_domain_id(self, domain): """ Find the domain_id for a given domain. :param str domain: The domain for which to find the domain_id. :raises errors.PluginError: if the domain_id cannot be found. """ domain_name_guesses = dns_common.base_domain_name_guesses(domain) for domain_name in domain_name_guesses: try: if hasattr(self.provider, 'options'): # For Lexicon 2.x self.provider.options['domain'] = domain_name else: # For Lexicon 3.x self.provider.domain = domain_name self.provider.authenticate() return # If `authenticate` doesn't throw an exception, we've found the right name except HTTPError as e: result = self._handle_http_error(e, domain_name) if result: raise result except Exception as e: # pylint: disable=broad-except result = self._handle_general_error(e, domain_name) if result: raise result # pylint: disable=raising-bad-type raise errors.PluginError('Unable to determine zone identifier for {0} using zone names: {1}' .format(domain, domain_name_guesses))
def _find_zone_id(self, domain): """ Find the zone_id for a given domain. :param str domain: The domain for which to find the zone_id. :returns: The zone_id, if found. :rtype: str :raises certbot.errors.PluginError: if no zone_id is found. """ zone_name_guesses = dns_common.base_domain_name_guesses(domain) zones = [] # type: List[Dict[str, Any]] code = msg = None for zone_name in zone_name_guesses: params = {'name': zone_name, 'per_page': 1} try: zones = self.cf.zones.get(params=params) # zones | pylint: disable=no-member except CloudFlare.exceptions.CloudFlareAPIError as e: code = int(e) msg = str(e) hint = None if code == 6003: hint = ( 'Did you copy your entire API token/key? To use Cloudflare tokens, ' 'you\'ll need the python package cloudflare>=2.3.1.{}'. format(' This certbot is running cloudflare ' + str(CloudFlare.__version__) if hasattr( CloudFlare, '__version__') else '')) elif code == 9103: hint = 'Did you enter the correct email address and Global key?' elif code == 9109: hint = 'Did you enter a valid Cloudflare Token?' if hint: raise errors.PluginError( 'Error determining zone_id: {0} {1}. Please confirm ' 'that you have supplied valid Cloudflare API credentials. ({2})' .format(code, msg, hint)) else: logger.debug( 'Unrecognised CloudFlareAPIError while finding zone_id: %d %s. ' 'Continuing with next zone guess...', e, e) if zones: zone_id = zones[0]['id'] logger.debug('Found zone_id of %s for %s using name %s', zone_id, domain, zone_name) return zone_id raise errors.PluginError( 'Unable to determine zone_id for {0} using zone names: {1}. ' 'Please confirm that the domain name has been entered correctly ' 'and is already associated with the supplied Cloudflare account.{2}' .format( domain, zone_name_guesses, ' The error from Cloudflare was:' ' {0} {1}'.format(code, msg) if code is not None else ''))
def _get_base_domain(cfg, domain): for candidate_base_domain in dns_common.base_domain_name_guesses(domain): response = _request(cfg, 'GET', ('domains', candidate_base_domain)) if response.ok: data = _get_json(response) fqdn = data.get('fqdn') if fqdn: return _BaseDomain(fqdn=fqdn) return None
def _find_domain(self, domain_name): domain_name_guesses = dns_common.base_domain_name_guesses(domain_name) domains = self._get_dnspod_client().domain_list() for guess in domain_name_guesses: if guess in domains: return guess raise errors.PluginError( "Unable to determine base domain for {0} using names: {1}.".format( domain_name, domain_name_guesses))
def _find_zone_name(self, domain_name): domain_name_guesses = dns_common.base_domain_name_guesses(domain_name) for domain in domain_name_guesses: try: self.client.get_zone(zone_name_or_id=domain) return domain except ServiceError as e: if e.status == 404: pass return None
def _find_domain(self, domain_name): domain_name_guesses = dns_common.base_domain_name_guesses(domain_name) domain_names = {domain['domain'] for domain in self.get_domains()} for guess in domain_name_guesses: if guess in domain_names: logger.debug('Found base domain for %s using name %s', domain_name, guess) return guess raise errors.PluginError( 'Unable to determine base domain for {} using names: {}.'.format( domain_name, domain_name_guesses))
def _find_domain_id(self, domain): domain_name_guesses = dns_common.base_domain_name_guesses(domain) for domain_name in domain_name_guesses: r = self._request('DescribeDomains', { 'KeyWord': domain_name, }) for d in r['Domains']['Domain']: if d['DomainName'] == domain_name: return domain_name raise errors.PluginError('Unable to determine zone identifier for {0} using zone names: {1}' .format(domain, domain_name_guesses))
def find_cloudflare_zone_id(self, cf, domain): zone_name_guesses = dns_common.base_domain_name_guesses(domain) zones = [] code = msg = None for zone_name in zone_name_guesses: params = {'name': zone_name, 'per_page': 1} try: zones = cf.zones.get(params=params) except CloudFlareAPIError as e: code = int(e) msg = str(e) hint = None if code == 6003: hint = 'Did you copy your entire API token/key?' elif code == 9103: hint = 'Did you enter the correct email address and Global key?' elif code == 9109: hint = 'Did you enter a valid Cloudflare Token?' if hint: raise CallError( f'Error determining zone_id: {code} {msg}. Please confirm that you have supplied ' f'valid Cloudflare API credentials. ({hint})') else: self.middleware.logger.debug( 'Unrecognised CloudFlareAPIError while finding zone_id: %d %s. ' 'Continuing with next zone guess...', e, e) if zones: zone_id = zones[0]['id'] return zone_id common_msg = f'Unable to determine zone_id for {domain} using zone names: {zone_name_guesses}' if msg is not None: if 'com.cloudflare.api.account.zone.list' in msg: raise CallError( f'{common_msg}. Please confirm that the domain name has been entered correctly ' 'and your Cloudflare Token has access to the domain.') else: raise CallError( f'{common_msg}. The error from Cloudflare was: {code} {msg}.' ) else: raise CallError( f'{common_msg}. Please confirm that the domain name has been entered correctly ' 'and is already associated with the supplied Cloudflare account.' )
def _find_zone(self, domain): try: zones = self.ovh.get('/domain/zone') except ovh.exceptions.APIError as e: raise errors.PluginError( "Error retrieving DNS zones: {0}".format(e)) for guess in dns_common.base_domain_name_guesses(domain): if guess in zones: return guess raise errors.PluginError( "Unable to determine DNS zone for {0}." "Please confirm that the domain name has been entered correctly " "and is already associated with the supplied OVH account.".format( domain))
def _find_zone_id(self, domain): """ Find the zone_id for a given domain. :param str domain: The domain for which to find the zone_id. :returns: The zone_id, if found. :rtype: str :raises certbot.errors.PluginError: if no zone_id is found. """ zone_name_guesses = dns_common.base_domain_name_guesses(domain) for zone_name in zone_name_guesses: params = {'name': zone_name, 'per_page': 1} try: zones = self.cf.zones.get(params=params) # zones | pylint: disable=no-member except CloudFlare.exceptions.CloudFlareAPIError as e: code = int(e) hint = None if code == 0: hint = ('Unable to determine zone_id for %s', zone_name) continue elif code == 6003: hint = 'Did you copy your entire API token/key?' elif code == 9103: hint = 'Did you enter the correct email address?' elif code == 9109: hint = 'Does your API token have "Zone DNS Edit" permissions for these zones?' raise errors.PluginError( 'Error determining zone_id: {0} {1}. Please confirm that ' 'you have supplied valid Cloudflare API credentials.{2}'. format(code, e, ' ({0})'.format(hint) if hint else '')) if zones: zone_id = zones[0]['id'] logger.debug('Found zone_id of %s for %s using name %s', zone_id, domain, zone_name) return zone_id raise errors.PluginError( 'Unable to determine zone_id for {0} using zone names: {1}. ' 'Please confirm that the domain name has been entered correctly ' 'and is already associated with the supplied Cloudflare account.'. format(domain, zone_name_guesses))
def _authenticate(self): LOGGER.debug('IN: _authenticate') url = '/v1/domains?limit=100' next_url = url domains_found = [] while next_url is not None: LOGGER.debug("in authenticate: Next-url %s" % (next_url)) response = self._get(next_url) json_result = response.json() if '_links' in json_result and 'next' in json_result['_links'] \ and 'href' in json_result['_links']['next']: next_url = json_result['_links']['next']['href'] else: next_url = None # find our domain # all domain at checkdomain all_domains = json_result['_embedded']['domains'] # all possible domain names domain_name_guesses = dns_common.base_domain_name_guesses( self.domain) for guess in domain_name_guesses: LOGGER.debug("trying: %s" % guess) domains_found = [x for x in all_domains if x['name'] == guess] if (len(domains_found) > 0): break if (len(domains_found) > 0): break if (len(domains_found) > 0): self.domain_id = domains_found[0]['id'] self.domain = domains_found[0]['name'] print("Found domain id %d for domain name %s" % (self.domain_id, self.domain)) else: print("Nothing found") raise Exception('Domain not found')
def main(): domains_str = os.environ['RENEWED_DOMAINS'] domains_lst = domains_str.split() for domain in domains_lst: print("") print("Start domain {} checking".format(domain)) zone_name_guesses = dns_common.base_domain_name_guesses(domain) zone_domain = None for temp_zone_domain in zone_name_guesses: temp_config_file = "{}/{}.conf".format(CERTBOT_CONF_DIR, temp_zone_domain) logger.debug("Checking zone {} -- {}".format(temp_zone_domain, temp_config_file)) if path.isfile(temp_config_file): zone_domain = temp_zone_domain break if zone_domain is None: raise Exception("It wasn't possible to continue. There is no config file for domain {}.".format(domain)) upload_certificate(zone_domain)
def _find_domain(self, record_name): """ Find the closest domain with an SOA record for a given domain name. :param str record_name: The record name for which to find the closest SOA record. :returns: The domain, if found. :rtype: str :raises certbot.errors.PluginError: if no SOA record can be found. """ domain_name_guesses = dns_common.base_domain_name_guesses(record_name) # Loop through until we find an authoritative SOA record for guess in domain_name_guesses: if self._query_soa(guess): return guess raise errors.PluginError('Unable to determine base domain for {0} using names: {1}.' .format(record_name, domain_name_guesses))
def _find_domain(self, domain_name): """ Find the closest domain with an SOA record for a given domain name. :param str domain_name: The domain name for which to find the closest SOA record. :returns: The domain, if found. :rtype: str :raises certbot.errors.PluginError: if no SOA record can be found. """ domain_name_guesses = dns_common.base_domain_name_guesses(domain_name) # Loop through until we find an authoritative SOA record for guess in domain_name_guesses: if self._query_soa(guess): return guess raise errors.PluginError('Unable to determine base domain for {0} using names: {1}.' .format(domain_name, domain_name_guesses))
def _find_domain(self, domain_name): """ Find the domain object for a given domain name. :param str domain_name: The domain name for which to find the corresponding Domain. :returns: The Domain, if found. :rtype: `str` :raises certbot.errors.PluginError: if no matching Domain is found. """ domain_name_guesses = dns_common.base_domain_name_guesses(domain_name) domains = self._fetch_domains() for guess in domain_name_guesses: if guess in domains: self.logger.debug('Found base domain for %s using name %s', domain_name, guess) return guess raise errors.PluginError('Unable to determine base domain for {0} using names: {1} and domains: {2}.' .format(domain_name, domain_name_guesses, domains))
def _find_zone_id(self, domain): """ Find the zone_id for a given domain. :param str domain: The domain for which to find the zone_id. :returns: The zone_id, if found. :rtype: str :raises certbot.errors.PluginError: if no zone_id is found. """ zone_name_guesses = dns_common.base_domain_name_guesses(domain) for zone_name in zone_name_guesses: params = {'name': zone_name, 'per_page': 1} try: zones = self.cf.zones.get(params=params) # zones | pylint: disable=no-member except CloudFlare.exceptions.CloudFlareAPIError as e: code = int(e) hint = None if code == 6003: hint = 'Did you copy your entire API key?' elif code == 9103: hint = 'Did you enter the correct email address?' raise errors.PluginError('Error determining zone_id: {0} {1}. Please confirm that ' 'you have supplied valid Cloudflare API credentials.{2}' .format(code, e, ' ({0})'.format(hint) if hint else '')) if len(zones) > 0: zone_id = zones[0]['id'] logger.debug('Found zone_id of %s for %s using name %s', zone_id, domain, zone_name) return zone_id raise errors.PluginError('Unable to determine zone_id for {0} using zone names: {1}. ' 'Please confirm that the domain name has been entered correctly ' 'and is already associated with the supplied Cloudflare account.' .format(domain, zone_name_guesses))
def get_base_domain_name(self, full_domain_name): if self.domains_cache is not None: domains = self.domains_cache else: try: domains = self.domains_cache = self.request("GET", "/dns/list") except requests.HTTPError as err: raise VultrPluginError("Error fetching DNS domains list: " + http_error_message(err)) guess_list = dns_common.base_domain_name_guesses(full_domain_name) for guess in guess_list: for base_domain in domains: if base_domain["domain"] == guess: logger.debug( f'Using base domain "{guess}" for "{full_domain_name}"' ) return guess raise VultrPluginError( f'Could not find the (base) domain for "{full_domain_name}" (Is the domain set in your DNS?)' )
def _find_managed_zone_id(self, domain): """ Find the managed zone for a given domain. :param str domain: The domain for which to find the managed zone. :returns: The ID of the managed zone, if found. :rtype: str :raises certbot.errors.PluginError: if the managed zone cannot be found. """ zone_dns_name_guesses = dns_common.base_domain_name_guesses(domain) for zone_name in zone_dns_name_guesses: #get the zone id try: logger.debug('looking for zone: %s', zone_name) zone_id = self._api_request('dns_zone_get_id', {'origin': zone_name}) return zone_id, zone_name except errors.PluginError as e: pass return None
def _find_managed_zone_id(self, domain, record_name): """ Find the managed zone for a given domain. :param str domain: The domain for which to find the managed zone. :returns: The ID of the managed zone, if found. :rtype: str :raises certbot.errors.PluginError: if the managed zone cannot be found. """ zone_dns_name_guesses = [record_name] + dns_common.base_domain_name_guesses(domain) for zone_name in zone_dns_name_guesses: # get the zone id try: logger.debug("looking for zone: %s", zone_name) status_code, result = self._api_request("GET", "domains/search?exact={0}".format(zone_name), {}) if status_code == 200 and len(result) > 0: return result[0]['id'], result[0]['name'] except errors.PluginError as e: pass return None
def _find_managed_zone(self, domain): """ Find the managed zone for a given domain. :param str domain: The domain for which to find the managed zone. :returns: Zone :rtype: string :returns: The managed zone name, if found. """ logger.debug("EDGEDNS: _find_managed_zone. domain: {0}".format(domain)) zone_dns_name_guesses = dns_common.base_domain_name_guesses(domain) self.session.auth = self.edgegrid_auth for zone_name in zone_dns_name_guesses: # get the zone id try: logger.debug("EdgeDNS: looking for zone: {0}".format(zone_name)) result = self.session.get(self.EDGEDNSZONESURL + zone_name) if result.status_code == 200: logger.debug("EDGEDNS: _find_managed_zone found. zone: {0}".format(zone_name)) return zone_name elif result.status_code == 404: continue else: raise errors.PluginError( "EdgeDNS: API zone retrieval invocation resulted in a error: {0} {1}".format(result.status_code, result.message) ) except: logger.error(" ZONE RETRIEVAL Error: {0}".format(sys.exc_info()[0])) raise errors.PluginError( "EdgeDNS: API invocation resulted in a session error: {0}".format(sys.exc_info()[0]) ) logger.debug("EDGEDNS: _find_managed_zone NOT found.") return None
def del_txt_record(self, domain, record_name, record_content): """ Delete a TXT record using the supplied information. Note that both the record's name and content are used to ensure that similar records created concurrently (e.g., due to concurrent invocations of this plugin) are not deleted. Failures are logged, but not raised. :param str domain: The domain to use to look up the CFProxy zone. :param str record_name: The record name (typically beginning with '_acme-challenge.'). :param str record_content: The record content (typically the challenge validation). """ zone_alts = dns_common.base_domain_name_guesses(domain) for alt in zone_alts: data = { 'rectype': 'TXT', 'zone': alt, 'rec': record_name, 'value': record_content, 'user': self.user, 'key': self.key } try: logger.debug('Attempting to add record to zone %s: %s', domain, data) r = requests.post(self.api_ep + "/delete", json=data) if r.json()['success']: return except requests.exceptions.RequestException as e: logger.error('Encountered Error adding TXT record: %d %s', e, e) raise errors.PluginError( 'Error communicating with the CFProxy API: {0}'.format(e))
def _find_domain(self, domain_name): """ Find the domain object for a given domain name. :param str domain_name: The domain name for which to find the corresponding Domain. :returns: The Domain, if found. :rtype: `~digitalocean.Domain` :raises certbot.errors.PluginError: if no matching Domain is found. """ domain_name_guesses = dns_common.base_domain_name_guesses(domain_name) domains = self.manager.get_all_domains() for guess in domain_name_guesses: matches = [domain for domain in domains if domain.name == guess] if matches: domain = matches[0] logger.debug('Found base domain for %s using name %s', domain_name, guess) return domain raise errors.PluginError('Unable to determine base domain for {0} using names: {1}.' .format(domain_name, domain_name_guesses))
def test_simple_case(self): self.assertTrue( 'example.com' in dns_common.base_domain_name_guesses("example.com") )
def test_sub_domain(self): self.assertTrue( 'example.com' in dns_common.base_domain_name_guesses("foo.bar.baz.example.com") )
def test_second_level_domain(self): self.assertTrue('example.co.uk' in dns_common.base_domain_name_guesses( "foo.bar.baz.example.co.uk"))
def test_second_level_domain(self): self.assertTrue( 'example.co.uk' in dns_common.base_domain_name_guesses("foo.bar.baz.example.co.uk") )