summaryrefslogtreecommitdiffstats
path: root/pkb_client/client/dns.py
diff options
context:
space:
mode:
Diffstat (limited to 'pkb_client/client/dns.py')
-rw-r--r--pkb_client/client/dns.py43
1 files changed, 36 insertions, 7 deletions
diff --git a/pkb_client/client/dns.py b/pkb_client/client/dns.py
index 85ae971..8bedad2 100644
--- a/pkb_client/client/dns.py
+++ b/pkb_client/client/dns.py
@@ -1,6 +1,6 @@
from dataclasses import dataclass
from enum import Enum
-from typing import Optional
+from typing import Optional, Any
class DNSRecordType(str, Enum):
@@ -33,7 +33,14 @@ class DNSRecord:
notes: str
@staticmethod
- def from_dict(d):
+ def from_dict(d: dict[str, Any]) -> "DNSRecord":
+ """
+ Create a DNSRecord instance from a dictionary representation.
+
+ :param d: Dictionary containing DNS record data.
+ :return: DNSRecord instance.
+ """
+
# 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(
@@ -46,6 +53,23 @@ class DNSRecord:
notes=d["notes"],
)
+ def to_dict(self) -> dict[str, Any]:
+ """
+ Convert the DNSRecord instance to a dictionary representation.
+
+ :return: Dictionary containing DNS record data.
+ """
+
+ return {
+ "id": self.id,
+ "name": self.name,
+ "type": str(self.type),
+ "content": self.content,
+ "ttl": self.ttl,
+ "prio": self.prio,
+ "notes": self.notes,
+ }
+
class DNSRestoreMode(Enum):
clear = 0
@@ -56,8 +80,13 @@ class DNSRestoreMode(Enum):
return self.name
@staticmethod
- def from_string(a):
- try:
- return DNSRestoreMode[a]
- except KeyError:
- return a
+ def from_string(a: str) -> "DNSRestoreMode":
+ """
+ Convert a string to a DNSRestoreMode enum member.
+
+ :param a: String representation of the restore mode.
+ :return: Corresponding DNSRestoreMode enum member.
+ :raises KeyError: If the string does not match any enum member.
+ """
+
+ return DNSRestoreMode[a]