Debian Codegraph @

ansible_collections/community/dns/plugins/module_utils/_zone.py

raw
1 # Copyright (c) 2017-2021 Felix Fontein
2 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 # Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
6 # Do not use this from other collections or standalone plugins/modules!
7
8 from __future__ import annotations
9
10 import typing as t
11
12 from ansible_collections.community.dns.plugins.module_utils._record import RecordIDT
13 from ansible_collections.community.dns.plugins.module_utils._record_set import (
14 RecordSetIDT,
15 )
16
17 if t.TYPE_CHECKING:
18 from collections.abc import Mapping # pragma: no cover
19
20 from ._record import DNSRecord # pragma: no cover
21 from ._record_set import DNSRecordSet # pragma: no cover
22
23
24 ZoneIDT = t.TypeVar("ZoneIDT")
25 ZoneIDT_co = t.TypeVar("ZoneIDT_co", covariant=True)
26
27
28 class IDNSZone(t.Protocol, t.Generic[ZoneIDT_co]):
29 @property
30 def id(self) -> ZoneIDT_co: ...
31
32 @property
33 def name(self) -> str: ...
34
35 @property
36 def info(self) -> Mapping[str, t.Any]: ...
37
38
39 class DNSZone(t.Generic[ZoneIDT]):
40 def __init__(
41 self,
42 *,
43 zone_id: ZoneIDT,
44 name: str,
45 info: dict[str, t.Any] | None = None,
46 ) -> None:
47 self.id = zone_id
48 self.name = name
49 self.info: dict[str, t.Any] = info or {}
50
51 def __str__(self) -> str:
52 data = []
53 if self.id is not None:
54 data.append(f"id: {self.id}")
55 data.append(f"name: {self.name}")
56 data.append(f"info: {self.info}")
57 return "DNSZone(" + ", ".join(data) + ")"
58
59 def __repr__(self) -> str:
60 return self.__str__()
61
62
63 class DNSZoneWithRecords(t.Generic[ZoneIDT, RecordIDT]):
64 def __init__(
65 self,
66 zone: DNSZone[ZoneIDT],
67 records: list[DNSRecord[RecordIDT]],
68 ) -> None:
69 self.zone = zone
70 self.records = records
71
72 def __str__(self) -> str:
73 return f"({self.zone}, {self.records})"
74
75 def __repr__(self) -> str:
76 return f"DNSZoneWithRecords({self.zone!r}, {self.records!r})"
77
78
79 class DNSZoneWithRecordSets(t.Generic[ZoneIDT, RecordSetIDT, RecordIDT]):
80 def __init__(
81 self,
82 zone: DNSZone[ZoneIDT],
83 record_sets: list[DNSRecordSet[RecordSetIDT, RecordIDT]],
84 ) -> None:
85 self.zone = zone
86 self.record_sets = record_sets
87
88 def __str__(self) -> str:
89 return f"({self.zone}, {self.record_sets})"
90
91 def __repr__(self) -> str:
92 return f"DNSZoneWithRecordSets({self.zone!r}, {self.record_sets!r})"