-
Notifications
You must be signed in to change notification settings - Fork 53
/
common.py
81 lines (63 loc) · 3.46 KB
/
common.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from typing import Any, Dict, Sequence
from ..auth import ErrataItemType, DNSProviderBase
from ..lib import dns_challenge
class BaseDns(DNSProviderBase):
"""
Shim for legacy DNS provider interface.
"""
def __init__(self, **kwargs: Any) -> None:
if "chal_types" not in kwargs:
kwargs["chal_types"] = ["dns-01"]
if "LOG_LEVEL" not in kwargs:
kwargs["LOG_LEVEL"] = "WARNING"
super().__init__(**kwargs)
### shim methods
def setup(self, challenges: Sequence[Dict[str, str]]) -> Sequence[ErrataItemType]:
for chal in challenges:
self.create_dns_record(chal["ident_value"], dns_challenge(chal["key_auth"]))
return []
def unpropagated(self, challenges: Sequence[Dict[str, str]]) -> Sequence[ErrataItemType]:
return []
def clear(self, challenges: Sequence[Dict[str, str]]) -> Sequence[ErrataItemType]:
for chal in challenges:
self.delete_dns_record(chal["ident_value"], dns_challenge(chal["key_auth"]))
return []
### legacy DNS methods
def create_dns_record(self, domain_name, domain_dns_value):
"""
Method that creates/adds a dns TXT record for a domain/subdomain name on
a chosen DNS provider.
:param domain_name: :string: The domain/subdomain name whose dns record ought to be
created/added on a chosen DNS provider.
:param domain_dns_value: :string: The value/content of the TXT record that will be
created/added for the given domain/subdomain
This method should return None
Basic Usage:
If the value of the `domain_name` variable is example.com and the value of
`domain_dns_value` is HAJA_4MkowIFByHhFaP8u035skaM91lTKplKld
Then, your implementation of this method ought to create a DNS TXT record
whose name is '_acme-challenge' + '.' + domain_name + '.' (ie: _acme-challenge.example.com. )
and whose value/content is HAJA_4MkowIFByHhFaP8u035skaM91lTKplKld
Using a dns client like dig(https://linux.die.net/man/1/dig) to do a dns lookup should result
in something like:
dig TXT _acme-challenge.example.com
...
;; ANSWER SECTION:
_acme-challenge.example.com. 120 IN TXT "HAJA_4MkowIFByHhFaP8u035skaM91lTKplKld"
_acme-challenge.singularity.brandur.org. 120 IN TXT "9C0DqKC_4MkowIFByHhFaP8u0Zv4z7Wz2IHM91lTKec"
Optionally, you may also use an online dns client like: https://toolbox.googleapps.com/apps/dig/#TXT/
Please consult your dns provider on how/format of their DNS TXT records.
You may also want to consult the cloudflare DNS implementation that is found in this repository.
"""
raise NotImplementedError("create_dns_record method must be implemented.")
def delete_dns_record(self, domain_name, domain_dns_value):
"""
Method that deletes/removes a dns TXT record for a domain/subdomain name on
a chosen DNS provider.
:param domain_name: :string: The domain/subdomain name whose dns record ought to be
deleted/removed on a chosen DNS provider.
:param domain_dns_value: :string: The value/content of the TXT record that will be
deleted/removed for the given domain/subdomain
This method should return None
"""
raise NotImplementedError("delete_dns_record method must be implemented.")