cloudfloordns.client.sync.record

 1# from dataclasses import dataclass, field
 2from typing import List
 3
 4from cloudfloordns.models import Record
 5
 6
 7class Records:
 8    def __init__(self, client) -> None:
 9        self._client = client
10
11    def create(self, domain: str, record: Record, timeout=None):
12        url = f"/dns/zone/{domain}/record"
13        return self._client.post(
14            url,
15            data=record.model_dump(),
16            timeout=timeout,
17        )
18
19    def update(self, domain: str, record_id: str, record: Record, timeout=None):
20        url = f"/dns/zone/{domain}/record/{record_id}"
21        return self._client.patch(
22            url,
23            data=record.model_dump(exclude_unset=True),
24            timeout=timeout,
25        )
26
27    def delete(self, domain: str, record_id: str, timeout=None):
28        url = f"/dns/zone/{domain}/record/{record_id}"
29        return self._client.delete(
30            url,
31            timeout=timeout,
32        )
33
34    def _raw_list(self, domain: str, timeout=None) -> List[dict]:
35        url = f"/dns/zone/{domain}/record"
36        try:
37            return self._client.get(
38                url,
39                timeout=timeout,
40            )
41        except Exception as e:
42            if "No record available for this domain" in str(e):
43                return []
44            raise
45
46    def list(self, domain: str, timeout=None) -> List[Record]:
47        res = self._raw_list(domain, timeout=timeout)
48        return [Record(**d) for d in res]
49
50    def raw_get(self, domain: str, record_id, timeout=None):
51        res = self._raw_list(
52            domain,
53            timeout=timeout,
54        )
55        return next((r for r in res if r["id"] == record_id), None)
56
57    def get(self, domain: str, record_id, timeout=None):
58        res = self.list(
59            domain,
60            timeout=timeout,
61        )
62        return next((r for r in res if r.id == record_id), None)
63
64
65__all__ = [
66    "Records",
67]
class Records:
 8class Records:
 9    def __init__(self, client) -> None:
10        self._client = client
11
12    def create(self, domain: str, record: Record, timeout=None):
13        url = f"/dns/zone/{domain}/record"
14        return self._client.post(
15            url,
16            data=record.model_dump(),
17            timeout=timeout,
18        )
19
20    def update(self, domain: str, record_id: str, record: Record, timeout=None):
21        url = f"/dns/zone/{domain}/record/{record_id}"
22        return self._client.patch(
23            url,
24            data=record.model_dump(exclude_unset=True),
25            timeout=timeout,
26        )
27
28    def delete(self, domain: str, record_id: str, timeout=None):
29        url = f"/dns/zone/{domain}/record/{record_id}"
30        return self._client.delete(
31            url,
32            timeout=timeout,
33        )
34
35    def _raw_list(self, domain: str, timeout=None) -> List[dict]:
36        url = f"/dns/zone/{domain}/record"
37        try:
38            return self._client.get(
39                url,
40                timeout=timeout,
41            )
42        except Exception as e:
43            if "No record available for this domain" in str(e):
44                return []
45            raise
46
47    def list(self, domain: str, timeout=None) -> List[Record]:
48        res = self._raw_list(domain, timeout=timeout)
49        return [Record(**d) for d in res]
50
51    def raw_get(self, domain: str, record_id, timeout=None):
52        res = self._raw_list(
53            domain,
54            timeout=timeout,
55        )
56        return next((r for r in res if r["id"] == record_id), None)
57
58    def get(self, domain: str, record_id, timeout=None):
59        res = self.list(
60            domain,
61            timeout=timeout,
62        )
63        return next((r for r in res if r.id == record_id), None)
Records(client)
 9    def __init__(self, client) -> None:
10        self._client = client
def create( self, domain: str, record: cloudfloordns.models.record.Record, timeout=None):
12    def create(self, domain: str, record: Record, timeout=None):
13        url = f"/dns/zone/{domain}/record"
14        return self._client.post(
15            url,
16            data=record.model_dump(),
17            timeout=timeout,
18        )
def update( self, domain: str, record_id: str, record: cloudfloordns.models.record.Record, timeout=None):
20    def update(self, domain: str, record_id: str, record: Record, timeout=None):
21        url = f"/dns/zone/{domain}/record/{record_id}"
22        return self._client.patch(
23            url,
24            data=record.model_dump(exclude_unset=True),
25            timeout=timeout,
26        )
def delete(self, domain: str, record_id: str, timeout=None):
28    def delete(self, domain: str, record_id: str, timeout=None):
29        url = f"/dns/zone/{domain}/record/{record_id}"
30        return self._client.delete(
31            url,
32            timeout=timeout,
33        )
def list( self, domain: str, timeout=None) -> List[cloudfloordns.models.record.Record]:
47    def list(self, domain: str, timeout=None) -> List[Record]:
48        res = self._raw_list(domain, timeout=timeout)
49        return [Record(**d) for d in res]
def raw_get(self, domain: str, record_id, timeout=None):
51    def raw_get(self, domain: str, record_id, timeout=None):
52        res = self._raw_list(
53            domain,
54            timeout=timeout,
55        )
56        return next((r for r in res if r["id"] == record_id), None)
def get(self, domain: str, record_id, timeout=None):
58    def get(self, domain: str, record_id, timeout=None):
59        res = self.list(
60            domain,
61            timeout=timeout,
62        )
63        return next((r for r in res if r.id == record_id), None)