python3-cyberfusion-powerdns-secondary-cleaner 1.1__tar.gz
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.
- python3_cyberfusion_powerdns_secondary_cleaner-1.1/PKG-INFO +53 -0
- python3_cyberfusion_powerdns_secondary_cleaner-1.1/README.md +42 -0
- python3_cyberfusion_powerdns_secondary_cleaner-1.1/pyproject.toml +23 -0
- python3_cyberfusion_powerdns_secondary_cleaner-1.1/setup.cfg +12 -0
- python3_cyberfusion_powerdns_secondary_cleaner-1.1/src/cyberfusion/PowerDNSSecondaryCleaner/CLI.py +64 -0
- python3_cyberfusion_powerdns_secondary_cleaner-1.1/src/cyberfusion/PowerDNSSecondaryCleaner/__init__.py +1 -0
- python3_cyberfusion_powerdns_secondary_cleaner-1.1/src/cyberfusion/PowerDNSSecondaryCleaner/powerdns_api.py +59 -0
- python3_cyberfusion_powerdns_secondary_cleaner-1.1/src/python3_cyberfusion_powerdns_secondary_cleaner.egg-info/PKG-INFO +53 -0
- python3_cyberfusion_powerdns_secondary_cleaner-1.1/src/python3_cyberfusion_powerdns_secondary_cleaner.egg-info/SOURCES.txt +12 -0
- python3_cyberfusion_powerdns_secondary_cleaner-1.1/src/python3_cyberfusion_powerdns_secondary_cleaner.egg-info/dependency_links.txt +1 -0
- python3_cyberfusion_powerdns_secondary_cleaner-1.1/src/python3_cyberfusion_powerdns_secondary_cleaner.egg-info/entry_points.txt +2 -0
- python3_cyberfusion_powerdns_secondary_cleaner-1.1/src/python3_cyberfusion_powerdns_secondary_cleaner.egg-info/requires.txt +3 -0
- python3_cyberfusion_powerdns_secondary_cleaner-1.1/src/python3_cyberfusion_powerdns_secondary_cleaner.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python3-cyberfusion-powerdns-secondary-cleaner
|
|
3
|
+
Version: 1.1
|
|
4
|
+
Summary: Use powerdns-secondary-cleaner to delete zones on secondary PowerDNS server that were deleted on primary PowerDNS server.
|
|
5
|
+
Author-email: Cyberfusion <support@cyberfusion.io>
|
|
6
|
+
Project-URL: Source, https://github.com/CyberfusionIO/python3-cyberfusion-powerdns-secondary-cleaner
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: docopt==0.6.2
|
|
9
|
+
Requires-Dist: schema==0.7.7
|
|
10
|
+
Requires-Dist: requests==2.32.3
|
|
11
|
+
|
|
12
|
+
# python3-cyberfusion-powerdns-secondary-cleaner
|
|
13
|
+
|
|
14
|
+
Use powerdns-secondary-cleaner to delete zones on secondary PowerDNS server that were deleted on primary PowerDNS server.
|
|
15
|
+
|
|
16
|
+
The PowerDNS API is used for both the primary and secondary, so the program can run anywhere. Be it on the primary, secondary or elsewhere.
|
|
17
|
+
|
|
18
|
+
# Install
|
|
19
|
+
|
|
20
|
+
## PyPI
|
|
21
|
+
|
|
22
|
+
Run the following command to install the package from PyPI:
|
|
23
|
+
|
|
24
|
+
pip3 install python3-cyberfusion-powerdns-secondary-cleaner
|
|
25
|
+
|
|
26
|
+
## Debian
|
|
27
|
+
|
|
28
|
+
Run the following commands to build a Debian package:
|
|
29
|
+
|
|
30
|
+
mk-build-deps -i -t 'apt -o Debug::pkgProblemResolver=yes --no-install-recommends -y'
|
|
31
|
+
dpkg-buildpackage -us -uc
|
|
32
|
+
|
|
33
|
+
# Configure
|
|
34
|
+
|
|
35
|
+
No configuration is supported.
|
|
36
|
+
|
|
37
|
+
# Usage
|
|
38
|
+
|
|
39
|
+
Syntax:
|
|
40
|
+
|
|
41
|
+
powerdns-secondary-cleaner --primary-api-url=<primary-api-url> --primary-api-key=<primary-api-key> --secondary-api-url=<secondary-api-url> --secondary-api-key=<secondary-api-key> [--dry-run]
|
|
42
|
+
|
|
43
|
+
Example when running on primary:
|
|
44
|
+
|
|
45
|
+
powerdns-secondary-cleaner --primary-api-url=http://localhost:8081 --primary-api-key=example --secondary-api-url=http://secondary.test:8081 --secondary-api-key=example
|
|
46
|
+
|
|
47
|
+
Example when running on secondary:
|
|
48
|
+
|
|
49
|
+
powerdns-secondary-cleaner --secondary-api-url=http://localhost:8081 --secondary-api-key=example --primary-api-url=http://primary.test:8081 --primary-api-key=example
|
|
50
|
+
|
|
51
|
+
Only show which zones would be deleted on secondary:
|
|
52
|
+
|
|
53
|
+
powerdns-secondary-cleaner ... --dry-run
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# python3-cyberfusion-powerdns-secondary-cleaner
|
|
2
|
+
|
|
3
|
+
Use powerdns-secondary-cleaner to delete zones on secondary PowerDNS server that were deleted on primary PowerDNS server.
|
|
4
|
+
|
|
5
|
+
The PowerDNS API is used for both the primary and secondary, so the program can run anywhere. Be it on the primary, secondary or elsewhere.
|
|
6
|
+
|
|
7
|
+
# Install
|
|
8
|
+
|
|
9
|
+
## PyPI
|
|
10
|
+
|
|
11
|
+
Run the following command to install the package from PyPI:
|
|
12
|
+
|
|
13
|
+
pip3 install python3-cyberfusion-powerdns-secondary-cleaner
|
|
14
|
+
|
|
15
|
+
## Debian
|
|
16
|
+
|
|
17
|
+
Run the following commands to build a Debian package:
|
|
18
|
+
|
|
19
|
+
mk-build-deps -i -t 'apt -o Debug::pkgProblemResolver=yes --no-install-recommends -y'
|
|
20
|
+
dpkg-buildpackage -us -uc
|
|
21
|
+
|
|
22
|
+
# Configure
|
|
23
|
+
|
|
24
|
+
No configuration is supported.
|
|
25
|
+
|
|
26
|
+
# Usage
|
|
27
|
+
|
|
28
|
+
Syntax:
|
|
29
|
+
|
|
30
|
+
powerdns-secondary-cleaner --primary-api-url=<primary-api-url> --primary-api-key=<primary-api-key> --secondary-api-url=<secondary-api-url> --secondary-api-key=<secondary-api-key> [--dry-run]
|
|
31
|
+
|
|
32
|
+
Example when running on primary:
|
|
33
|
+
|
|
34
|
+
powerdns-secondary-cleaner --primary-api-url=http://localhost:8081 --primary-api-key=example --secondary-api-url=http://secondary.test:8081 --secondary-api-key=example
|
|
35
|
+
|
|
36
|
+
Example when running on secondary:
|
|
37
|
+
|
|
38
|
+
powerdns-secondary-cleaner --secondary-api-url=http://localhost:8081 --secondary-api-key=example --primary-api-url=http://primary.test:8081 --primary-api-key=example
|
|
39
|
+
|
|
40
|
+
Only show which zones would be deleted on secondary:
|
|
41
|
+
|
|
42
|
+
powerdns-secondary-cleaner ... --dry-run
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "python3-cyberfusion-powerdns-secondary-cleaner"
|
|
7
|
+
version = "1.1"
|
|
8
|
+
description = "Use powerdns-secondary-cleaner to delete zones on secondary PowerDNS server that were deleted on primary PowerDNS server."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [
|
|
11
|
+
{ name = "Cyberfusion", email = "support@cyberfusion.io" },
|
|
12
|
+
]
|
|
13
|
+
dependencies = [
|
|
14
|
+
"docopt==0.6.2",
|
|
15
|
+
"schema==0.7.7",
|
|
16
|
+
"requests==2.32.3",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
"Source" = "https://github.com/CyberfusionIO/python3-cyberfusion-powerdns-secondary-cleaner"
|
|
21
|
+
|
|
22
|
+
[project.scripts]
|
|
23
|
+
powerdns-secondary-cleaner = "cyberfusion.PowerDNSSecondaryCleaner.CLI:main"
|
python3_cyberfusion_powerdns_secondary_cleaner-1.1/src/cyberfusion/PowerDNSSecondaryCleaner/CLI.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""powerdns-secondary-cleaner.
|
|
2
|
+
|
|
3
|
+
Usage:
|
|
4
|
+
powerdns-secondary-cleaner --primary-api-url=<primary-api-url> --primary-api-key=<primary-api-key> --secondary-api-url=<secondary-api-url> --secondary-api-key=<secondary-api-key> [--dry-run]
|
|
5
|
+
|
|
6
|
+
Options:
|
|
7
|
+
-h --help Show this screen.
|
|
8
|
+
--primary-api-url=<primary-api-url> URL of primary PowerDNS server API.
|
|
9
|
+
--primary-api-key=<primary-api-key> Key for primary PowerDNS server API.
|
|
10
|
+
--secondary-api-url=<secondary-api-url> URL of secondary PowerDNS server API.
|
|
11
|
+
--secondary-api-key=<secondary-api-key> Key for secondary PowerDNS server API.
|
|
12
|
+
--dry-run Only show which zones would be deleted on secondary.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import docopt
|
|
16
|
+
from schema import Schema
|
|
17
|
+
|
|
18
|
+
from cyberfusion.PowerDNSSecondaryCleaner.powerdns_api import PowerDNSAPI
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def get_args() -> docopt.Dict:
|
|
22
|
+
"""Get docopt args."""
|
|
23
|
+
return docopt.docopt(__doc__)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def main() -> None:
|
|
27
|
+
"""Spawn relevant class for CLI function."""
|
|
28
|
+
|
|
29
|
+
# Validate input
|
|
30
|
+
|
|
31
|
+
args = get_args()
|
|
32
|
+
schema = Schema(
|
|
33
|
+
{
|
|
34
|
+
"--primary-api-url": str,
|
|
35
|
+
"--primary-api-key": str,
|
|
36
|
+
"--secondary-api-url": str,
|
|
37
|
+
"--secondary-api-key": str,
|
|
38
|
+
"--dry-run": bool,
|
|
39
|
+
}
|
|
40
|
+
)
|
|
41
|
+
args = schema.validate(args)
|
|
42
|
+
|
|
43
|
+
# Run classes
|
|
44
|
+
|
|
45
|
+
primary_api = PowerDNSAPI(args["--primary-api-url"], args["--primary-api-key"])
|
|
46
|
+
primary_zones = primary_api.get_zones()
|
|
47
|
+
|
|
48
|
+
secondary_api = PowerDNSAPI(
|
|
49
|
+
args["--secondary-api-url"], args["--secondary-api-key"]
|
|
50
|
+
)
|
|
51
|
+
secondary_zones = secondary_api.get_zones()
|
|
52
|
+
|
|
53
|
+
for zone in secondary_zones:
|
|
54
|
+
if zone in primary_zones:
|
|
55
|
+
print(f"Keeping {zone.id_}")
|
|
56
|
+
|
|
57
|
+
continue
|
|
58
|
+
|
|
59
|
+
if not args["--dry-run"]:
|
|
60
|
+
print(f"Deleting {zone.id_}")
|
|
61
|
+
|
|
62
|
+
secondary_api.delete_zone(zone.id_)
|
|
63
|
+
else:
|
|
64
|
+
print(f"Would delete {zone.id_}")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Empty file to turn this into a package."""
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""Classes to use PowerDNS API."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import List
|
|
5
|
+
|
|
6
|
+
import requests
|
|
7
|
+
|
|
8
|
+
TIMEOUT = 60
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class Zone:
|
|
13
|
+
"""Represents PowerDNS zone."""
|
|
14
|
+
|
|
15
|
+
id_: str
|
|
16
|
+
|
|
17
|
+
@classmethod
|
|
18
|
+
def from_powerdns_api(cls, data: dict) -> "Zone":
|
|
19
|
+
"""Get class from API payload."""
|
|
20
|
+
return cls(id_=data["id"])
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class PowerDNSAPI:
|
|
24
|
+
"""Represents PowerDNS API."""
|
|
25
|
+
|
|
26
|
+
def __init__(self, api_url: str, api_key: str) -> None:
|
|
27
|
+
"""Set attributes."""
|
|
28
|
+
self.api_url = api_url
|
|
29
|
+
self.api_key = api_key
|
|
30
|
+
|
|
31
|
+
def _execute_get_request(self, endpoint: str) -> dict:
|
|
32
|
+
"""Execute GET request and get response."""
|
|
33
|
+
request = requests.get(
|
|
34
|
+
f"{self.api_url}/api/v1/servers/localhost/{endpoint}",
|
|
35
|
+
timeout=TIMEOUT,
|
|
36
|
+
headers={"X-API-Key": self.api_key},
|
|
37
|
+
)
|
|
38
|
+
request.raise_for_status()
|
|
39
|
+
|
|
40
|
+
return request.json()
|
|
41
|
+
|
|
42
|
+
def _execute_delete_request(self, endpoint: str) -> None:
|
|
43
|
+
"""Execute DELETE request."""
|
|
44
|
+
request = requests.delete(
|
|
45
|
+
f"{self.api_url}/api/v1/servers/localhost/{endpoint}",
|
|
46
|
+
timeout=TIMEOUT,
|
|
47
|
+
headers={"X-API-Key": self.api_key},
|
|
48
|
+
)
|
|
49
|
+
request.raise_for_status()
|
|
50
|
+
|
|
51
|
+
def get_zones(self) -> List[Zone]:
|
|
52
|
+
"""Get zones."""
|
|
53
|
+
zones = self._execute_get_request("zones")
|
|
54
|
+
|
|
55
|
+
return [Zone.from_powerdns_api(zone) for zone in zones]
|
|
56
|
+
|
|
57
|
+
def delete_zone(self, id_: str) -> None:
|
|
58
|
+
"""Delete zone."""
|
|
59
|
+
self._execute_delete_request(f"zones/{id_}")
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python3-cyberfusion-powerdns-secondary-cleaner
|
|
3
|
+
Version: 1.1
|
|
4
|
+
Summary: Use powerdns-secondary-cleaner to delete zones on secondary PowerDNS server that were deleted on primary PowerDNS server.
|
|
5
|
+
Author-email: Cyberfusion <support@cyberfusion.io>
|
|
6
|
+
Project-URL: Source, https://github.com/CyberfusionIO/python3-cyberfusion-powerdns-secondary-cleaner
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: docopt==0.6.2
|
|
9
|
+
Requires-Dist: schema==0.7.7
|
|
10
|
+
Requires-Dist: requests==2.32.3
|
|
11
|
+
|
|
12
|
+
# python3-cyberfusion-powerdns-secondary-cleaner
|
|
13
|
+
|
|
14
|
+
Use powerdns-secondary-cleaner to delete zones on secondary PowerDNS server that were deleted on primary PowerDNS server.
|
|
15
|
+
|
|
16
|
+
The PowerDNS API is used for both the primary and secondary, so the program can run anywhere. Be it on the primary, secondary or elsewhere.
|
|
17
|
+
|
|
18
|
+
# Install
|
|
19
|
+
|
|
20
|
+
## PyPI
|
|
21
|
+
|
|
22
|
+
Run the following command to install the package from PyPI:
|
|
23
|
+
|
|
24
|
+
pip3 install python3-cyberfusion-powerdns-secondary-cleaner
|
|
25
|
+
|
|
26
|
+
## Debian
|
|
27
|
+
|
|
28
|
+
Run the following commands to build a Debian package:
|
|
29
|
+
|
|
30
|
+
mk-build-deps -i -t 'apt -o Debug::pkgProblemResolver=yes --no-install-recommends -y'
|
|
31
|
+
dpkg-buildpackage -us -uc
|
|
32
|
+
|
|
33
|
+
# Configure
|
|
34
|
+
|
|
35
|
+
No configuration is supported.
|
|
36
|
+
|
|
37
|
+
# Usage
|
|
38
|
+
|
|
39
|
+
Syntax:
|
|
40
|
+
|
|
41
|
+
powerdns-secondary-cleaner --primary-api-url=<primary-api-url> --primary-api-key=<primary-api-key> --secondary-api-url=<secondary-api-url> --secondary-api-key=<secondary-api-key> [--dry-run]
|
|
42
|
+
|
|
43
|
+
Example when running on primary:
|
|
44
|
+
|
|
45
|
+
powerdns-secondary-cleaner --primary-api-url=http://localhost:8081 --primary-api-key=example --secondary-api-url=http://secondary.test:8081 --secondary-api-key=example
|
|
46
|
+
|
|
47
|
+
Example when running on secondary:
|
|
48
|
+
|
|
49
|
+
powerdns-secondary-cleaner --secondary-api-url=http://localhost:8081 --secondary-api-key=example --primary-api-url=http://primary.test:8081 --primary-api-key=example
|
|
50
|
+
|
|
51
|
+
Only show which zones would be deleted on secondary:
|
|
52
|
+
|
|
53
|
+
powerdns-secondary-cleaner ... --dry-run
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
setup.cfg
|
|
4
|
+
src/cyberfusion/PowerDNSSecondaryCleaner/CLI.py
|
|
5
|
+
src/cyberfusion/PowerDNSSecondaryCleaner/__init__.py
|
|
6
|
+
src/cyberfusion/PowerDNSSecondaryCleaner/powerdns_api.py
|
|
7
|
+
src/python3_cyberfusion_powerdns_secondary_cleaner.egg-info/PKG-INFO
|
|
8
|
+
src/python3_cyberfusion_powerdns_secondary_cleaner.egg-info/SOURCES.txt
|
|
9
|
+
src/python3_cyberfusion_powerdns_secondary_cleaner.egg-info/dependency_links.txt
|
|
10
|
+
src/python3_cyberfusion_powerdns_secondary_cleaner.egg-info/entry_points.txt
|
|
11
|
+
src/python3_cyberfusion_powerdns_secondary_cleaner.egg-info/requires.txt
|
|
12
|
+
src/python3_cyberfusion_powerdns_secondary_cleaner.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cyberfusion
|