summaryrefslogtreecommitdiffstats
path: root/pkb_client/client/dns.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2024-11-20 01:17:40 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2024-11-20 01:17:40 -0500
commit3e3ebe586385a83b10c8f1d0b9ba9b67c8b56d2f (patch)
tree5682f748fc9867166043734aad44e1734d16abeb /pkb_client/client/dns.py
parentfa197fe27b8a03bbf4504476f842956ece2c76c9 (diff)
New upstream version 2.0.0.upstream/2.0.0
Diffstat (limited to 'pkb_client/client/dns.py')
-rw-r--r--pkb_client/client/dns.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/pkb_client/client/dns.py b/pkb_client/client/dns.py
new file mode 100644
index 0000000..85ae971
--- /dev/null
+++ b/pkb_client/client/dns.py
@@ -0,0 +1,63 @@
+from dataclasses import dataclass
+from enum import Enum
+from typing import Optional
+
+
+class DNSRecordType(str, Enum):
+ A = "A"
+ AAAA = "AAAA"
+ MX = "MX"
+ CNAME = "CNAME"
+ ALIAS = "ALIAS"
+ TXT = "TXT"
+ NS = "NS"
+ SRV = "SRV"
+ TLSA = "TLSA"
+ CAA = "CAA"
+
+ def __str__(self):
+ return self.value
+
+
+DNS_RECORDS_WITH_PRIORITY = {DNSRecordType.MX, DNSRecordType.SRV}
+
+
+@dataclass
+class DNSRecord:
+ id: str
+ name: str
+ type: DNSRecordType
+ content: str
+ ttl: int
+ prio: Optional[int]
+ notes: str
+
+ @staticmethod
+ def from_dict(d):
+ # only use prio for supported record types since the API returns it for all records with default value 0
+ prio = int(d["prio"]) if d["type"] in DNS_RECORDS_WITH_PRIORITY else None
+ return DNSRecord(
+ id=d["id"],
+ name=d["name"],
+ type=DNSRecordType[d["type"]],
+ content=d["content"],
+ ttl=int(d["ttl"]),
+ prio=prio,
+ notes=d["notes"],
+ )
+
+
+class DNSRestoreMode(Enum):
+ clear = 0
+ replace = 1
+ keep = 2
+
+ def __str__(self):
+ return self.name
+
+ @staticmethod
+ def from_string(a):
+ try:
+ return DNSRestoreMode[a]
+ except KeyError:
+ return a