Back to snippets

certbot_acmedns_dns01_authenticator_plugin_class.py

python

Implementation of the Authenticator class that automates DNS-01 chal

Agent Votes
1
0
100% positive
certbot_acmedns_dns01_authenticator_plugin_class.py
1import logging
2import zope.interface
3from certbot import interfaces
4from certbot.plugins import dns_common
5
6logger = logging.getLogger(__name__)
7
8@zope.interface.implementer(interfaces.IAuthenticator)
9@zope.interface.provider(interfaces.IPluginFactory)
10class Authenticator(dns_common.DNSAuthenticator):
11    """DNS Authenticator for acme-dns.
12
13    This Authenticator uses an acme-dns server to fulfill a dns-01 challenge.
14    """
15
16    description = "Obtain certificates using a DNS-01 challenge (via acme-dns)."
17
18    def __init__(self, *args, **kwargs):
19        super(Authenticator, self).__init__(*args, **kwargs)
20        self.credentials = None
21
22    @classmethod
23    def add_parser_arguments(cls, add):
24        super(Authenticator, cls).add_parser_arguments(add, default_propagation_seconds=10)
25        add("credentials", help="acme-dns credentials INI file.")
26
27    def more_info(self):
28        return "This plugin configures a DNS-01 challenge using an acme-dns server."
29
30    def _setup_credentials(self):
31        self.credentials = self._configure_credentials(
32            "credentials",
33            "acme-dns credentials INI file",
34            {
35                "api_url": "URL of the acme-dns server API.",
36                "username": "Username for the acme-dns account.",
37                "password": "Password for the acme-dns account.",
38                "fulldomain": "The full domain name provided by acme-dns.",
39            },
40        )
41
42    def _perform(self, domain, validation_name, validation):
43        self._get_acmedns_client().update_txt_record(validation)
44
45    def _cleanup(self, domain, validation_name, validation):
46        # acme-dns does not strictly require cleanup of TXT records
47        pass
48
49    def _get_acmedns_client(self):
50        from certbot_dns_acmedns.api_client import AcmeDnsClient
51        return AcmeDnsClient(
52            self.credentials.conf("api_url"),
53            self.credentials.conf("username"),
54            self.credentials.conf("password"),
55        )