From 6e6c761e7458bd8b8ad9e110db80a40b9f0db18d Mon Sep 17 00:00:00 2001 From: Graham Hayes Date: Fri, 27 Apr 2018 17:04:00 +0100 Subject: [PATCH] Update Error Handling Change-Id: Iaf38f552dd17bb7c305bd6d2a543cf2a7941039a --- README.rst | 20 +++++++++++++++----- certbot_dns_openstack/dns_openstack.py | 20 +++++++++++++++----- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/README.rst b/README.rst index be0ff52..9a5e918 100644 --- a/README.rst +++ b/README.rst @@ -4,16 +4,26 @@ certbot-dns-openstack OpenStack DNS Authenticator plugin for Certbot -Please fill here a long description which must be at least 3 lines wrapped on -80 cols, so that distribution package maintainers can use it in their packages. -Note that this is a hard requirement. +To Install: + +``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 -* Documentation: https://docs.openstack.org/certbot-dns-openstack/latest * Source: https://git.openstack.org/cgit/openstack/certbot-dns-openstack * Bugs: https://bugs.launchpad.net/certbot-dns-openstack Features -------- -* TODO +* dns-01 ACME challenge diff --git a/certbot_dns_openstack/dns_openstack.py b/certbot_dns_openstack/dns_openstack.py index b7831d8..a7e42d2 100644 --- a/certbot_dns_openstack/dns_openstack.py +++ b/certbot_dns_openstack/dns_openstack.py @@ -16,6 +16,7 @@ import logging import zope.interface from certbot import interfaces +from certbot import errors from certbot.plugins import dns_common from openstack.config import loader @@ -40,7 +41,7 @@ class Authenticator(dns_common.DNSAuthenticator): def add_parser_arguments(cls, add): # pylint: disable=arguments-differ super(Authenticator, cls).add_parser_arguments( 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.') 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.' def _setup_credentials(self): - config_file = self.conf('client_config') or '' + config_file = self.conf('config') or '' config = loader.OpenStackConfig( config_files=loader.CONFIG_FILES + [config_file]) self.cloud = connection.Connection( @@ -58,10 +59,19 @@ class Authenticator(dns_common.DNSAuthenticator): ) 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.zone['id'], validation_name + '.', "TXT", [validation]) def _cleanup(self, domain, validation_name, validation): - self.cloud.delete_recordset( - self.zone['id'], self.recordset['id']) + if getattr(self, 'recordset', False): + self.cloud.delete_recordset( + self.zone['id'], self.recordset['id'])