Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

authenticator.py 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. """DNS plugin."""
  2. import collections
  3. import logging
  4. import zope.interface
  5. from acme import challenges
  6. from certbot import interfaces
  7. from certbot.plugins import common
  8. from certbot_pdns.PdnsApiAuthenticator import PdnsApiAuthenticator
  9. logger = logging.getLogger(__name__)
  10. @zope.interface.implementer(interfaces.IAuthenticator)
  11. @zope.interface.provider(interfaces.IPluginFactory)
  12. class Authenticator(common.Plugin):
  13. """PDNS Authenticator."""
  14. description = "Place challenges in DNS records"
  15. MORE_INFO = """\
  16. Authenticator plugin that performs dns-01 challenge by saving
  17. necessary validation resources to appropriate records in a PowerDNS server."""
  18. backend = None
  19. def more_info(self): # pylint: disable=missing-docstring,no-self-use
  20. return self.MORE_INFO
  21. @classmethod
  22. def add_parser_arguments(cls, add):
  23. add("certbot-pdns-config", default="/etc/letsencrypt/certbot-pdns.json",
  24. help="Path to certbot-pdns configuration file")
  25. def get_chall_pref(self, domain): # pragma: no cover
  26. # pylint: disable=missing-docstring,no-self-use,unused-argument
  27. return [challenges.DNS01]
  28. def __init__(self, *args, **kwargs):
  29. super(Authenticator, self).__init__(*args, **kwargs)
  30. self.full_roots = {}
  31. self.performed = collections.defaultdict(set)
  32. def prepare(self): # pylint: disable=missing-docstring
  33. self.backend = PdnsApiAuthenticator()
  34. conf_path = self.conf("certbot-pdns-config")
  35. self.backend.prepare(conf_path)
  36. pass
  37. def perform(self, achalls): # pylint: disable=missing-docstring
  38. responses = []
  39. zones = []
  40. for achall in achalls:
  41. response, validation = achall.response_and_validation()
  42. resp = self.backend.perform_single(achall, response, validation)
  43. responses.append(resp)
  44. domain = achall.domain
  45. zone = self.backend.find_best_matching_zone(domain)
  46. if zone not in zones:
  47. zones.append(zone)
  48. for zone in zones:
  49. self.backend.perform_notify(zone)
  50. self.backend.wait_for_propagation(achalls)
  51. return responses
  52. def cleanup(self, achalls): # pylint: disable=missing-docstring
  53. for achall in achalls:
  54. self.backend.cleanup(achall)