Update Error Handling

Change-Id: Iaf38f552dd17bb7c305bd6d2a543cf2a7941039a
This commit is contained in:
Graham Hayes 2018-04-27 17:04:00 +01:00
parent 038d7888e4
commit 6e6c761e74
No known key found for this signature in database
GPG Key ID: 1B263DC59F4AEFD5
2 changed files with 30 additions and 10 deletions

View File

@ -4,16 +4,26 @@ certbot-dns-openstack
OpenStack DNS Authenticator plugin for Certbot OpenStack DNS Authenticator plugin for Certbot
Please fill here a long description which must be at least 3 lines wrapped on To Install:
80 cols, so that distribution package maintainers can use it in their packages.
Note that this is a hard requirement. ``pip install certbot-dns-openstack``
To run:
``certbot -a certbot-dns-openstack:dns-openstack certonly -d example.com``
This uses ``os-client-config`` ``clouds.yaml`` for configuring the user access
which by default will look in ``~/.config/openstack/clouds.yaml``,
and ``/etc/openstack/clouds.yaml``. If your ``clouds.yaml`` file is stored else
where, you can add by adding
``--certbot-dns-openstack:dns-openstack-config /path/to/clouds.yaml`` to the
command.
* Free software: Apache license * Free software: Apache license
* Documentation: https://docs.openstack.org/certbot-dns-openstack/latest
* Source: https://git.openstack.org/cgit/openstack/certbot-dns-openstack * Source: https://git.openstack.org/cgit/openstack/certbot-dns-openstack
* Bugs: https://bugs.launchpad.net/certbot-dns-openstack * Bugs: https://bugs.launchpad.net/certbot-dns-openstack
Features Features
-------- --------
* TODO * dns-01 ACME challenge

View File

@ -16,6 +16,7 @@ import logging
import zope.interface import zope.interface
from certbot import interfaces from certbot import interfaces
from certbot import errors
from certbot.plugins import dns_common from certbot.plugins import dns_common
from openstack.config import loader from openstack.config import loader
@ -40,7 +41,7 @@ class Authenticator(dns_common.DNSAuthenticator):
def add_parser_arguments(cls, add): # pylint: disable=arguments-differ def add_parser_arguments(cls, add): # pylint: disable=arguments-differ
super(Authenticator, cls).add_parser_arguments( super(Authenticator, cls).add_parser_arguments(
add, default_propagation_seconds=30) add, default_propagation_seconds=30)
add('client_config', help='OpenStack Client Config file.') add('config', help='OpenStack Client Config file.')
add('cloud', help='OpenStack to use.') add('cloud', help='OpenStack to use.')
def more_info(self): # pylint: disable=missing-docstring,no-self-use def more_info(self): # pylint: disable=missing-docstring,no-self-use
@ -48,7 +49,7 @@ class Authenticator(dns_common.DNSAuthenticator):
'dns-01 challenge using the OpenStack DNS API.' 'dns-01 challenge using the OpenStack DNS API.'
def _setup_credentials(self): def _setup_credentials(self):
config_file = self.conf('client_config') or '' config_file = self.conf('config') or ''
config = loader.OpenStackConfig( config = loader.OpenStackConfig(
config_files=loader.CONFIG_FILES + [config_file]) config_files=loader.CONFIG_FILES + [config_file])
self.cloud = connection.Connection( self.cloud = connection.Connection(
@ -58,10 +59,19 @@ class Authenticator(dns_common.DNSAuthenticator):
) )
def _perform(self, domain, validation_name, validation): def _perform(self, domain, validation_name, validation):
self.zone = self.cloud.get_zone(domain + '.') domain_name_guesses = dns_common.base_domain_name_guesses(domain)
for domain in domain_name_guesses:
self.zone = self.cloud.get_zone(domain + '.')
if self.zone is not None:
break
if self.zone is None:
raise errors.PluginError(
'Unable to determine zone identifier for {0} using '
'zone names: {1}'.format(domain, domain_name_guesses))
self.recordset = self.cloud.create_recordset( self.recordset = self.cloud.create_recordset(
self.zone['id'], validation_name + '.', "TXT", [validation]) self.zone['id'], validation_name + '.', "TXT", [validation])
def _cleanup(self, domain, validation_name, validation): def _cleanup(self, domain, validation_name, validation):
self.cloud.delete_recordset( if getattr(self, 'recordset', False):
self.zone['id'], self.recordset['id']) self.cloud.delete_recordset(
self.zone['id'], self.recordset['id'])