fb-pdnstools 1.0.0__py3-none-any.whl → 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fb_pdnstools/__init__.py +76 -34
- fb_pdnstools/base_handler.py +119 -102
- fb_pdnstools/bulk_rm_app.py +242 -152
- fb_pdnstools/bulk_rm_cfg.py +33 -19
- fb_pdnstools/common.py +13 -13
- fb_pdnstools/errors.py +15 -15
- fb_pdnstools/record.py +407 -241
- fb_pdnstools/server.py +81 -44
- fb_pdnstools/xlate.py +57 -36
- fb_pdnstools/zone.py +600 -369
- fb_pdnstools-1.1.0.data/data/share/locale/de/LC_MESSAGES/fb_pdnstools.mo +0 -0
- fb_pdnstools-1.1.0.data/data/share/locale/en/LC_MESSAGES/fb_pdnstools.mo +0 -0
- fb_pdnstools-1.1.0.dist-info/METADATA +53 -0
- fb_pdnstools-1.1.0.dist-info/RECORD +17 -0
- {fb_pdnstools-1.0.0.dist-info → fb_pdnstools-1.1.0.dist-info}/WHEEL +1 -2
- fb_pdnstools-1.1.0.dist-info/entry_points.txt +3 -0
- fb_pdnstools/local_version.py +0 -17
- fb_pdnstools-1.0.0.data/scripts/pdns-bulk-remove +0 -68
- fb_pdnstools-1.0.0.dist-info/METADATA +0 -40
- fb_pdnstools-1.0.0.dist-info/RECORD +0 -17
- fb_pdnstools-1.0.0.dist-info/top_level.txt +0 -1
- {fb_pdnstools-1.0.0.dist-info → fb_pdnstools-1.1.0.dist-info/licenses}/LICENSE +0 -0
fb_pdnstools/bulk_rm_cfg.py
CHANGED
|
@@ -23,7 +23,7 @@ from . import DEFAULT_API_PREFIX
|
|
|
23
23
|
from . import DEFAULT_PORT
|
|
24
24
|
from .xlate import XLATOR
|
|
25
25
|
|
|
26
|
-
__version__ =
|
|
26
|
+
__version__ = "1.0.0"
|
|
27
27
|
LOG = logging.getLogger(__name__)
|
|
28
28
|
|
|
29
29
|
_ = XLATOR.gettext
|
|
@@ -41,15 +41,23 @@ class PdnsBulkRmConfigError(ConfigError):
|
|
|
41
41
|
class PdnsBulkRmCfg(BaseConfiguration):
|
|
42
42
|
"""A class for providing a configuration for the GetVmApplication class."""
|
|
43
43
|
|
|
44
|
-
default_pdns_master =
|
|
44
|
+
default_pdns_master = "master.pp-dns.com"
|
|
45
45
|
default_pdns_api_port = DEFAULT_PORT
|
|
46
46
|
default_pdns_api_https = False
|
|
47
47
|
default_pdns_api_prefix = DEFAULT_API_PREFIX
|
|
48
48
|
|
|
49
49
|
# -------------------------------------------------------------------------
|
|
50
50
|
def __init__(
|
|
51
|
-
self,
|
|
52
|
-
|
|
51
|
+
self,
|
|
52
|
+
appname=None,
|
|
53
|
+
verbose=0,
|
|
54
|
+
version=__version__,
|
|
55
|
+
base_dir=None,
|
|
56
|
+
encoding=None,
|
|
57
|
+
config_dir=None,
|
|
58
|
+
config_file=None,
|
|
59
|
+
initialized=False,
|
|
60
|
+
):
|
|
53
61
|
"""Initialize the PdnsBulkRmCfg object."""
|
|
54
62
|
self.pdns_master = self.default_pdns_master
|
|
55
63
|
self.pdns_api_port = self.default_pdns_api_port
|
|
@@ -58,8 +66,14 @@ class PdnsBulkRmCfg(BaseConfiguration):
|
|
|
58
66
|
self.pdns_api_prefix = self.default_pdns_api_prefix
|
|
59
67
|
|
|
60
68
|
super(PdnsBulkRmCfg, self).__init__(
|
|
61
|
-
appname=appname,
|
|
62
|
-
|
|
69
|
+
appname=appname,
|
|
70
|
+
verbose=verbose,
|
|
71
|
+
version=version,
|
|
72
|
+
base_dir=base_dir,
|
|
73
|
+
encoding=encoding,
|
|
74
|
+
config_dir=config_dir,
|
|
75
|
+
config_file=config_file,
|
|
76
|
+
initialized=False,
|
|
63
77
|
)
|
|
64
78
|
|
|
65
79
|
if initialized:
|
|
@@ -78,12 +92,12 @@ class PdnsBulkRmCfg(BaseConfiguration):
|
|
|
78
92
|
"""
|
|
79
93
|
res = super(PdnsBulkRmCfg, self).as_dict(short=short)
|
|
80
94
|
|
|
81
|
-
res[
|
|
95
|
+
res["pdns_api_key"] = None
|
|
82
96
|
if self.pdns_api_key:
|
|
83
97
|
if self.verbose > 4:
|
|
84
|
-
res[
|
|
98
|
+
res["pdns_api_key"] = self.pdns_api_key
|
|
85
99
|
else:
|
|
86
|
-
res[
|
|
100
|
+
res["pdns_api_key"] = "*******"
|
|
87
101
|
|
|
88
102
|
return res
|
|
89
103
|
|
|
@@ -92,34 +106,34 @@ class PdnsBulkRmCfg(BaseConfiguration):
|
|
|
92
106
|
"""Evaluate configuration in the section with the given name."""
|
|
93
107
|
super(PdnsBulkRmCfg, self).eval_config_section(config, section_name)
|
|
94
108
|
|
|
95
|
-
if section_name.lower() in (
|
|
109
|
+
if section_name.lower() in ("pdns", "powerdns"):
|
|
96
110
|
self._eval_config_pdns(config, section_name)
|
|
97
111
|
return
|
|
98
112
|
|
|
99
113
|
if self.verbose > 1:
|
|
100
|
-
LOG.debug(_(
|
|
114
|
+
LOG.debug(_("Unhandled configuration section {!r}.").format(section_name))
|
|
101
115
|
|
|
102
116
|
# -------------------------------------------------------------------------
|
|
103
117
|
def _eval_config_pdns(self, config, section_name):
|
|
104
118
|
|
|
105
119
|
if self.verbose > 1:
|
|
106
|
-
LOG.debug(_(
|
|
120
|
+
LOG.debug(_("Checking config section {!r} ...").format(section_name))
|
|
107
121
|
|
|
108
|
-
re_api_key = re.compile(r
|
|
109
|
-
re_api_prefix = re.compile(r
|
|
122
|
+
re_api_key = re.compile(r"^\s*(?:api[_-]?)?key\s*", re.IGNORECASE)
|
|
123
|
+
re_api_prefix = re.compile(r"^\s*(?:api[_-]?)?prefix\s*", re.IGNORECASE)
|
|
110
124
|
|
|
111
|
-
for
|
|
125
|
+
for key, value in config.items(section_name):
|
|
112
126
|
|
|
113
|
-
if key.lower() ==
|
|
127
|
+
if key.lower() == "master":
|
|
114
128
|
self.pdns_master = value
|
|
115
129
|
continue
|
|
116
|
-
elif key.lower() ==
|
|
130
|
+
elif key.lower() == "port":
|
|
117
131
|
self.pdns_api_port = int(value)
|
|
118
132
|
continue
|
|
119
133
|
elif re_api_key.match(key) and str(value).strip():
|
|
120
134
|
self.pdns_api_key = str(value).strip()
|
|
121
135
|
continue
|
|
122
|
-
elif key.lower() ==
|
|
136
|
+
elif key.lower() == "https":
|
|
123
137
|
self.pdns_api_https = to_bool(value)
|
|
124
138
|
continue
|
|
125
139
|
elif re_api_prefix.match(key):
|
|
@@ -130,7 +144,7 @@ class PdnsBulkRmCfg(BaseConfiguration):
|
|
|
130
144
|
|
|
131
145
|
# =============================================================================
|
|
132
146
|
|
|
133
|
-
if __name__ ==
|
|
147
|
+
if __name__ == "__main__":
|
|
134
148
|
|
|
135
149
|
pass
|
|
136
150
|
|
fb_pdnstools/common.py
CHANGED
|
@@ -16,7 +16,7 @@ import logging
|
|
|
16
16
|
# Own modules
|
|
17
17
|
from .xlate import XLATOR
|
|
18
18
|
|
|
19
|
-
__version__ =
|
|
19
|
+
__version__ = "1.0.0"
|
|
20
20
|
|
|
21
21
|
_ = XLATOR.gettext
|
|
22
22
|
|
|
@@ -28,7 +28,7 @@ SECONDS_PER_MINUTE = 60
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
# =============================================================================
|
|
31
|
-
def seconds2human(value, fs=
|
|
31
|
+
def seconds2human(value, fs=" ", all_fields=False):
|
|
32
32
|
"""
|
|
33
33
|
Convert the given value as seconds into a human readable format.
|
|
34
34
|
|
|
@@ -62,24 +62,24 @@ def seconds2human(value, fs=' ', all_fields=False):
|
|
|
62
62
|
elif isinstance(value, float):
|
|
63
63
|
int_val = int(value + 0.5)
|
|
64
64
|
elif value is None:
|
|
65
|
-
msg = _(
|
|
65
|
+
msg = _("A None type for seconds cannot be converted in seconds.")
|
|
66
66
|
raise TypeError(msg)
|
|
67
67
|
else:
|
|
68
68
|
try:
|
|
69
69
|
int_val = int(value)
|
|
70
70
|
except (TypeError, ValueError) as e:
|
|
71
|
-
msg = _(
|
|
71
|
+
msg = _("The value {val!r} cannot be interpreted as seconds: {e}")
|
|
72
72
|
raise ValueError(msg.format(val=value, e=e))
|
|
73
73
|
|
|
74
74
|
if int_val == 0:
|
|
75
75
|
if all_fields:
|
|
76
|
-
return
|
|
76
|
+
return "0d" + fs + "0h" + fs + "0m" + fs + "0s"
|
|
77
77
|
else:
|
|
78
|
-
return
|
|
78
|
+
return "0s"
|
|
79
79
|
|
|
80
|
-
result =
|
|
80
|
+
result = ""
|
|
81
81
|
if int_val < 0:
|
|
82
|
-
result =
|
|
82
|
+
result = "-"
|
|
83
83
|
int_val *= -1
|
|
84
84
|
|
|
85
85
|
days = int_val // SECONDS_PER_DAY
|
|
@@ -88,7 +88,7 @@ def seconds2human(value, fs=' ', all_fields=False):
|
|
|
88
88
|
if days or all_fields:
|
|
89
89
|
if result:
|
|
90
90
|
result += fs
|
|
91
|
-
result +=
|
|
91
|
+
result += "{}d".format(days)
|
|
92
92
|
|
|
93
93
|
hours = rest_days // SECONDS_PER_HOUR
|
|
94
94
|
rest_hours = rest_days % SECONDS_PER_HOUR
|
|
@@ -96,7 +96,7 @@ def seconds2human(value, fs=' ', all_fields=False):
|
|
|
96
96
|
if hours or all_fields:
|
|
97
97
|
if result:
|
|
98
98
|
result += fs
|
|
99
|
-
result +=
|
|
99
|
+
result += "{}h".format(hours)
|
|
100
100
|
|
|
101
101
|
minutes = rest_hours // SECONDS_PER_MINUTE
|
|
102
102
|
seconds = rest_hours % SECONDS_PER_MINUTE
|
|
@@ -104,19 +104,19 @@ def seconds2human(value, fs=' ', all_fields=False):
|
|
|
104
104
|
if minutes or all_fields:
|
|
105
105
|
if result:
|
|
106
106
|
result += fs
|
|
107
|
-
result +=
|
|
107
|
+
result += "{}m".format(minutes)
|
|
108
108
|
|
|
109
109
|
if seconds or all_fields:
|
|
110
110
|
if result:
|
|
111
111
|
result += fs
|
|
112
|
-
result +=
|
|
112
|
+
result += "{}s".format(seconds)
|
|
113
113
|
|
|
114
114
|
return result
|
|
115
115
|
|
|
116
116
|
|
|
117
117
|
# =============================================================================
|
|
118
118
|
|
|
119
|
-
if __name__ ==
|
|
119
|
+
if __name__ == "__main__":
|
|
120
120
|
|
|
121
121
|
pass
|
|
122
122
|
|
fb_pdnstools/errors.py
CHANGED
|
@@ -18,7 +18,7 @@ from .xlate import XLATOR
|
|
|
18
18
|
|
|
19
19
|
_ = XLATOR.gettext
|
|
20
20
|
|
|
21
|
-
__version__ =
|
|
21
|
+
__version__ = "1.0.0"
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
# =============================================================================
|
|
@@ -47,8 +47,7 @@ class PDNSNoRecordsToRemove(PowerDNSZoneError):
|
|
|
47
47
|
# -------------------------------------------------------------------------
|
|
48
48
|
def __str__(self):
|
|
49
49
|
"""Typecast into a string."""
|
|
50
|
-
msg = _(
|
|
51
|
-
self.zone_name)
|
|
50
|
+
msg = _("No Resource Record Sets found to remove from zone {!r}.").format(self.zone_name)
|
|
52
51
|
return msg
|
|
53
52
|
|
|
54
53
|
|
|
@@ -85,7 +84,7 @@ class PowerDNSWrongSoaDataError(PowerDNSRecordSetError):
|
|
|
85
84
|
# -------------------------------------------------------------------------
|
|
86
85
|
def __str__(self):
|
|
87
86
|
"""Typecast into a string."""
|
|
88
|
-
msg = _(
|
|
87
|
+
msg = _("Could not interprete SOA data: {!r}.").format(self.data)
|
|
89
88
|
return msg
|
|
90
89
|
|
|
91
90
|
|
|
@@ -104,10 +103,11 @@ class PDNSApiError(PowerDNSHandlerError):
|
|
|
104
103
|
def __str__(self):
|
|
105
104
|
"""Typecast into a string."""
|
|
106
105
|
if self.uri:
|
|
107
|
-
msg = _(
|
|
108
|
-
code=self.code, uri=self.uri, msg=self.msg
|
|
106
|
+
msg = _("Got a {code} error code from {uri!r}: {msg}").format(
|
|
107
|
+
code=self.code, uri=self.uri, msg=self.msg
|
|
108
|
+
)
|
|
109
109
|
else:
|
|
110
|
-
msg = _(
|
|
110
|
+
msg = _("Got a {code} error code: {msg}").format(code=self.code, msg=self.msg)
|
|
111
111
|
|
|
112
112
|
return msg
|
|
113
113
|
|
|
@@ -169,24 +169,24 @@ class PDNSRequestError(PowerDNSHandlerError):
|
|
|
169
169
|
# -------------------------------------------------------------------------
|
|
170
170
|
def __str__(self):
|
|
171
171
|
"""Typecast into a string."""
|
|
172
|
-
msg = _(
|
|
172
|
+
msg = _("Got an error requesting {uri!r}: {msg}").format(uri=self.uri, msg=self.msg)
|
|
173
173
|
if self.request:
|
|
174
|
-
cls =
|
|
174
|
+
cls = ""
|
|
175
175
|
if not isinstance(self.request, str):
|
|
176
|
-
cls = self.request.__class__.__name__ +
|
|
177
|
-
msg +=
|
|
176
|
+
cls = self.request.__class__.__name__ + " - "
|
|
177
|
+
msg += " / Request: {c}{e}".format(c=cls, e=self.request)
|
|
178
178
|
if self.response:
|
|
179
|
-
cls =
|
|
179
|
+
cls = ""
|
|
180
180
|
if not isinstance(self.response, str):
|
|
181
|
-
cls = self.response.__class__.__name__ +
|
|
182
|
-
msg +=
|
|
181
|
+
cls = self.response.__class__.__name__ + " - "
|
|
182
|
+
msg += " / Response: {c}{e}".format(c=cls, e=self.response)
|
|
183
183
|
|
|
184
184
|
return msg
|
|
185
185
|
|
|
186
186
|
|
|
187
187
|
# =============================================================================
|
|
188
188
|
|
|
189
|
-
if __name__ ==
|
|
189
|
+
if __name__ == "__main__":
|
|
190
190
|
|
|
191
191
|
pass
|
|
192
192
|
|