python3-cyberfusion-external-providers-ip-ranges 2.1.1.3__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.
@@ -0,0 +1,131 @@
1
+ """Empty file to turn this into a package."""
2
+
3
+ import os
4
+ from abc import ABCMeta, abstractmethod
5
+ from typing import List
6
+
7
+ import requests
8
+
9
+ from cyberfusion.FermSupport.configuration import Configuration
10
+
11
+
12
+ def get_ferm_base_path() -> str:
13
+ """Get ferm base path."""
14
+ return os.path.join(
15
+ os.path.sep,
16
+ "etc",
17
+ "ferm",
18
+ "vars.d",
19
+ )
20
+
21
+
22
+ class ExternalProviderIPRangeHandlerInterface(metaclass=ABCMeta):
23
+ """Interface for external provider IP range handlers."""
24
+
25
+ def __init__( # noqa: B027
26
+ self,
27
+ ) -> None:
28
+ """Do nothing."""
29
+
30
+ @property
31
+ @abstractmethod
32
+ def name(self) -> str:
33
+ """Get external provider name."""
34
+
35
+ @property
36
+ @abstractmethod
37
+ def ip_ranges(self) -> List[str]:
38
+ """Get IP ranges."""
39
+
40
+
41
+ class AtlassianIPRangeHandler(ExternalProviderIPRangeHandlerInterface):
42
+ """Class for external provider IP range handler."""
43
+
44
+ @property
45
+ def name(self) -> str:
46
+ """Get external provider name."""
47
+ return "atlassian"
48
+
49
+ @property
50
+ def ip_ranges(self) -> List[str]:
51
+ """Get IP ranges."""
52
+ result = []
53
+
54
+ request = requests.get("https://ip-ranges.atlassian.com/")
55
+ request.raise_for_status()
56
+ data = request.json()
57
+
58
+ for item in data["items"]:
59
+ result.append(item["cidr"])
60
+
61
+ return result
62
+
63
+
64
+ class GoogleCloudIPRangeHandler(ExternalProviderIPRangeHandlerInterface):
65
+ """Class for external provider IP range handler."""
66
+
67
+ @property
68
+ def name(self) -> str:
69
+ """Get external provider name."""
70
+ return "google_cloud"
71
+
72
+ @property
73
+ def ip_ranges(self) -> List[str]:
74
+ """Get IP ranges."""
75
+ result = []
76
+
77
+ request = requests.get("https://www.gstatic.com/ipranges/cloud.json")
78
+ request.raise_for_status()
79
+ data = request.json()
80
+
81
+ for item in data["prefixes"]:
82
+ if "ipv6Prefix" in item:
83
+ result.append(item["ipv6Prefix"])
84
+ else:
85
+ result.append(item["ipv4Prefix"])
86
+
87
+ return result
88
+
89
+
90
+ class BuddyIPRangeHandler(ExternalProviderIPRangeHandlerInterface):
91
+ """Class for external provider IP range handler."""
92
+
93
+ @property
94
+ def name(self) -> str:
95
+ """Get external provider name."""
96
+ return "buddy"
97
+
98
+ @property
99
+ def ip_ranges(self) -> List[str]:
100
+ """Get IP ranges."""
101
+ result = []
102
+
103
+ request = requests.get("https://buddy.works/api/ips")
104
+ request.raise_for_status()
105
+ data = request.json()
106
+
107
+ for item in data["buddy"] + data["windows"] + data["ios"]:
108
+ result.append(item)
109
+
110
+ return result
111
+
112
+
113
+ def main() -> None:
114
+ """Spawn relevant class for CLI function."""
115
+ configuration = Configuration(
116
+ path=os.path.join(
117
+ get_ferm_base_path(),
118
+ "external-providers-ip-ranges.conf",
119
+ )
120
+ )
121
+
122
+ handlers = [
123
+ BuddyIPRangeHandler(),
124
+ GoogleCloudIPRangeHandler(),
125
+ AtlassianIPRangeHandler(),
126
+ ]
127
+
128
+ for handler in handlers:
129
+ configuration.add_variable(name=handler.name, values=handler.ip_ranges)
130
+
131
+ configuration.save()
@@ -0,0 +1,49 @@
1
+ Metadata-Version: 2.1
2
+ Name: python3-cyberfusion-external-providers-ip-ranges
3
+ Version: 2.1.1.3
4
+ Summary: Scripts to add IP ranges of external providers to ferm.
5
+ Author-email: Cyberfusion <support@cyberfusion.io>
6
+ Project-URL: Source, https://github.com/CyberfusionIO/python3-cyberfusion-external-providers-ip-ranges
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: requests ==2.28.1
9
+ Requires-Dist: python3-cyberfusion-common ~=2.0
10
+ Requires-Dist: python3-cyberfusion-ferm-support ~=1.1
11
+
12
+ # python3-cyberfusion-external-providers-ip-ranges
13
+
14
+ Scripts to add IP ranges of external providers to [ferm](http://ferm.foo-projects.org/) variables.
15
+
16
+ ## Supported providers
17
+
18
+ * Google Cloud
19
+ * Atlassian
20
+ * [Buddy](https://buddy.works/)
21
+
22
+ # Install
23
+
24
+ ## PyPI
25
+
26
+ Run the following command to install the package from PyPI:
27
+
28
+ pip3 install python3-cyberfusion-external-providers-ip-ranges
29
+
30
+ ## Debian
31
+
32
+ Run the following commands to build a Debian package:
33
+
34
+ mk-build-deps -i -t 'apt -o Debug::pkgProblemResolver=yes --no-install-recommends -y'
35
+ dpkg-buildpackage -us -uc
36
+
37
+ # Configure
38
+
39
+ No configuration is supported.
40
+
41
+ # Usage
42
+
43
+ Run the following command for help:
44
+
45
+ external-providers-ip-ranges-cli -h
46
+
47
+ ## Cron
48
+
49
+ The Debian package installs a cron. This cron runs the command above per supported provider.
@@ -0,0 +1,6 @@
1
+ cyberfusion/ExternalProvidersIPRanges/__init__.py,sha256=VwK8FtKIMEReyDRvxON3PE06vxSohIYH-eGqu0pEkXE,3157
2
+ python3_cyberfusion_external_providers_ip_ranges-2.1.1.3.dist-info/METADATA,sha256=-kxxadheB-qg5MfTQexuA8lgscZr8CIMLE_LZQQNtmE,1294
3
+ python3_cyberfusion_external_providers_ip_ranges-2.1.1.3.dist-info/WHEEL,sha256=Mdi9PDNwEZptOjTlUcAth7XJDFtKrHYaQMPulZeBCiQ,91
4
+ python3_cyberfusion_external_providers_ip_ranges-2.1.1.3.dist-info/entry_points.txt,sha256=-otWzA8lyatw2UrkX1OxFOmMd9fO_xqX94SCMB8YjvA,96
5
+ python3_cyberfusion_external_providers_ip_ranges-2.1.1.3.dist-info/top_level.txt,sha256=ss011q9S6SL_KIIyq7iujFmIYa0grSjlnInO7cDkeag,12
6
+ python3_cyberfusion_external_providers_ip_ranges-2.1.1.3.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (73.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ external-providers-ip-ranges-cli = cyberfusion.ExternalProvidersIPRanges:main