portforward 0.6.1__cp310-cp310-macosx_11_0_arm64.whl → 0.7.0__cp310-cp310-macosx_11_0_arm64.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.
Potentially problematic release.
This version of portforward might be problematic. Click here for more details.
- portforward/__init__.py +35 -13
- portforward/_portforward.cpython-310-darwin.so +0 -0
- portforward/_portforward.pyi +1 -1
- {portforward-0.6.1.dist-info → portforward-0.7.0.dist-info}/METADATA +6 -11
- portforward-0.7.0.dist-info/RECORD +9 -0
- portforward-0.6.1.dist-info/RECORD +0 -9
- {portforward-0.6.1.dist-info → portforward-0.7.0.dist-info}/WHEEL +0 -0
- {portforward-0.6.1.dist-info → portforward-0.7.0.dist-info}/license_files/AUTHORS.rst +0 -0
- {portforward-0.6.1.dist-info → portforward-0.7.0.dist-info}/license_files/LICENSE +0 -0
portforward/__init__.py
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
Easy Kubernetes Port-Forward For Python
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
-
__version__ = "0.
|
|
5
|
+
__version__ = "0.7.0"
|
|
6
6
|
|
|
7
7
|
import asyncio
|
|
8
8
|
import contextlib
|
|
9
|
+
import ipaddress
|
|
9
10
|
import os
|
|
10
11
|
from enum import Enum
|
|
11
12
|
from pathlib import Path
|
|
12
|
-
from typing import Generator, Optional
|
|
13
|
+
from typing import Generator, Optional, Union
|
|
13
14
|
|
|
14
15
|
from portforward import _portforward
|
|
15
16
|
|
|
@@ -36,6 +37,7 @@ def forward(
|
|
|
36
37
|
waiting: float = 0.1,
|
|
37
38
|
log_level: LogLevel = LogLevel.INFO,
|
|
38
39
|
kube_context: str = "",
|
|
40
|
+
bind_ip: Union[ipaddress.IPv4Address, ipaddress.IPv6Address, str, None] = None,
|
|
39
41
|
) -> Generator["PortForwarder", None, None]:
|
|
40
42
|
"""
|
|
41
43
|
Connects to a **pod or service** and tunnels traffic from a local port to
|
|
@@ -52,21 +54,16 @@ def forward(
|
|
|
52
54
|
>>> import portforward
|
|
53
55
|
>>> with portforward.forward("test", "web-svc", 9000, 80):
|
|
54
56
|
>>> # Do work
|
|
55
|
-
>>>
|
|
56
|
-
>>> # Or without context manager
|
|
57
|
-
>>>
|
|
58
|
-
>>> forwarder = portforward.forward("test", "some-pod", 9000, 80)
|
|
59
|
-
>>> # Do work
|
|
60
|
-
>>> forwarder.stop()
|
|
61
57
|
|
|
62
58
|
:param namespace: Target namespace
|
|
63
59
|
:param pod_or_service: Name of target Pod or service
|
|
64
|
-
:param from_port: Local port
|
|
60
|
+
:param from_port: Local port, or 0 to use any free port
|
|
65
61
|
:param to_port: Port inside the pod
|
|
66
62
|
:param config_path: Path for loading kube config
|
|
67
63
|
:param waiting: Delay in seconds
|
|
68
64
|
:param log_level: Level of logging
|
|
69
65
|
:param kube_context: Target kubernetes context (fallback is current context)
|
|
66
|
+
:param bind_ip: To which IP shall the portforward be bind
|
|
70
67
|
:return: forwarder to manual stop the forwarding
|
|
71
68
|
"""
|
|
72
69
|
|
|
@@ -79,6 +76,7 @@ def forward(
|
|
|
79
76
|
waiting,
|
|
80
77
|
log_level,
|
|
81
78
|
kube_context,
|
|
79
|
+
bind_ip,
|
|
82
80
|
)
|
|
83
81
|
|
|
84
82
|
try:
|
|
@@ -107,6 +105,7 @@ class PortForwarder:
|
|
|
107
105
|
waiting: float = 0.1,
|
|
108
106
|
log_level: LogLevel = LogLevel.INFO,
|
|
109
107
|
kube_context: str = "",
|
|
108
|
+
bind_ip: Union[ipaddress.IPv4Address, ipaddress.IPv6Address, str, None] = None,
|
|
110
109
|
) -> None:
|
|
111
110
|
self._async_forwarder = AsyncPortForwarder(
|
|
112
111
|
namespace,
|
|
@@ -117,6 +116,7 @@ class PortForwarder:
|
|
|
117
116
|
waiting,
|
|
118
117
|
log_level,
|
|
119
118
|
kube_context,
|
|
119
|
+
bind_ip,
|
|
120
120
|
)
|
|
121
121
|
|
|
122
122
|
def forward(self):
|
|
@@ -129,6 +129,11 @@ class PortForwarder:
|
|
|
129
129
|
def is_stopped(self):
|
|
130
130
|
return self._async_forwarder.is_stopped
|
|
131
131
|
|
|
132
|
+
@property
|
|
133
|
+
def from_port(self):
|
|
134
|
+
"""The local port that was actually used for the portforward."""
|
|
135
|
+
return self._async_forwarder.from_port
|
|
136
|
+
|
|
132
137
|
|
|
133
138
|
class AsyncPortForwarder:
|
|
134
139
|
"""Use the same args as the `portforward.forward` method."""
|
|
@@ -143,10 +148,10 @@ class AsyncPortForwarder:
|
|
|
143
148
|
waiting: float = 0.1,
|
|
144
149
|
log_level: LogLevel = LogLevel.INFO,
|
|
145
150
|
kube_context: str = "",
|
|
151
|
+
bind_ip: Union[ipaddress.IPv4Address, ipaddress.IPv6Address, str, None] = None,
|
|
146
152
|
) -> None:
|
|
147
153
|
self.namespace: str = _validate_str("namespace", namespace)
|
|
148
154
|
self.pod_or_service: str = _validate_str("pod_or_service", pod_or_service)
|
|
149
|
-
self.from_port: int = _validate_port("from_port", from_port)
|
|
150
155
|
self.to_port: int = _validate_port("to_port", to_port)
|
|
151
156
|
self.log_level: LogLevel = _validate_log(log_level)
|
|
152
157
|
self.waiting: float = waiting
|
|
@@ -154,14 +159,19 @@ class AsyncPortForwarder:
|
|
|
154
159
|
self.config_path: str = _config_path(config_path)
|
|
155
160
|
self.kube_context: str = _kube_context(kube_context)
|
|
156
161
|
|
|
162
|
+
_validate_port("from_port", from_port)
|
|
163
|
+
bind_ip = _validate_ip_address(bind_ip)
|
|
164
|
+
|
|
157
165
|
self.actual_pod_name: str = ""
|
|
166
|
+
self.from_port: int = 0
|
|
158
167
|
self._is_stopped: bool = False
|
|
168
|
+
self.bind_address: str = f"{bind_ip}:{from_port}"
|
|
159
169
|
|
|
160
170
|
async def forward(self):
|
|
161
|
-
self.actual_pod_name = await _portforward.forward(
|
|
171
|
+
(self.actual_pod_name, self.from_port) = await _portforward.forward(
|
|
162
172
|
self.namespace,
|
|
163
173
|
self.pod_or_service,
|
|
164
|
-
self.
|
|
174
|
+
self.bind_address,
|
|
165
175
|
self.to_port,
|
|
166
176
|
self.config_path,
|
|
167
177
|
self.log_level.value,
|
|
@@ -196,7 +206,7 @@ def _validate_str(arg_name, arg) -> str:
|
|
|
196
206
|
|
|
197
207
|
|
|
198
208
|
def _validate_port(arg_name, arg) -> int:
|
|
199
|
-
in_range = arg and 0
|
|
209
|
+
in_range = arg is not None and 0 <= arg < 65536
|
|
200
210
|
if arg is None or not isinstance(arg, int) or not in_range:
|
|
201
211
|
raise ValueError(f"{arg_name}={arg} is not a valid port")
|
|
202
212
|
|
|
@@ -210,6 +220,18 @@ def _validate_log(log_level):
|
|
|
210
220
|
return log_level
|
|
211
221
|
|
|
212
222
|
|
|
223
|
+
def _validate_ip_address(ip_address):
|
|
224
|
+
if not ip_address:
|
|
225
|
+
return "127.0.0.1"
|
|
226
|
+
|
|
227
|
+
if isinstance(ip_address, ipaddress.IPv4Address) or isinstance(
|
|
228
|
+
ip_address, ipaddress.IPv4Address
|
|
229
|
+
):
|
|
230
|
+
return str(ip_address)
|
|
231
|
+
|
|
232
|
+
return str(ipaddress.ip_address(ip_address))
|
|
233
|
+
|
|
234
|
+
|
|
213
235
|
def _config_path(config_path_arg) -> str:
|
|
214
236
|
if config_path_arg and not isinstance(config_path_arg, str):
|
|
215
237
|
raise ValueError(f"config_path={config_path_arg} is not a valid str")
|
|
Binary file
|
portforward/_portforward.pyi
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: portforward
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Classifier: Programming Language :: Rust
|
|
5
5
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
6
6
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
@@ -18,9 +18,9 @@ Author-email: Sebastian Ziemann <corka149@mailbox.org>
|
|
|
18
18
|
License: MIT License
|
|
19
19
|
Requires-Python: >=3.7
|
|
20
20
|
Description-Content-Type: text/x-rst; charset=UTF-8
|
|
21
|
-
Project-URL: Changelog, https://github.com/pytogo/portforward/blob/main/HISTORY.rst
|
|
22
21
|
Project-URL: Repository, https://github.com/pytogo/portforward.git
|
|
23
22
|
Project-URL: Documentation, https://portforward.readthedocs.io
|
|
23
|
+
Project-URL: Changelog, https://github.com/pytogo/portforward/blob/main/HISTORY.rst
|
|
24
24
|
|
|
25
25
|
===========
|
|
26
26
|
portforward
|
|
@@ -58,22 +58,17 @@ Installation
|
|
|
58
58
|
|
|
59
59
|
Wheels are available for:
|
|
60
60
|
|
|
61
|
-
* Windows
|
|
62
|
-
* MacOS X
|
|
63
|
-
* Linux
|
|
61
|
+
* Windows (architectures: x64, x86)
|
|
62
|
+
* MacOS X (architectures: x86_64, aarch64)
|
|
63
|
+
* Linux (architectures: x86_64, x86, aarch64)
|
|
64
64
|
|
|
65
65
|
with Python versions:
|
|
66
66
|
|
|
67
|
-
* 3.7
|
|
68
67
|
* 3.8
|
|
69
68
|
* 3.9
|
|
70
69
|
* 3.10
|
|
71
70
|
* 3.11
|
|
72
|
-
|
|
73
|
-
and architectures:
|
|
74
|
-
|
|
75
|
-
* x84_64
|
|
76
|
-
* arm64 (known as M1/Apple Chip - MacOS only)
|
|
71
|
+
* 3.12
|
|
77
72
|
|
|
78
73
|
**Requirements for installation from source**
|
|
79
74
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
portforward-0.7.0.dist-info/METADATA,sha256=bGcqg3CAEII8VH5YibAWWZ567FIN58ZTf3gHV7S70Yc,3733
|
|
2
|
+
portforward-0.7.0.dist-info/WHEEL,sha256=YB4nIpEaVbQYtEelAR0MsnJWBlMXhW33ztHgM37Axhc,106
|
|
3
|
+
portforward-0.7.0.dist-info/license_files/LICENSE,sha256=n2aq0UH0YZkyF_5hougjNi5gzXIUapEEqEUn6FwAcFE,1075
|
|
4
|
+
portforward-0.7.0.dist-info/license_files/AUTHORS.rst,sha256=YQwE3_FUEuGVHbxYUa4NQMlG28QBGwcCYEoa2MP9Xgk,163
|
|
5
|
+
portforward/__init__.py,sha256=aG57_IslXAlgIZU7SoB4zKMut29hwpELWeTgVphmGQ8,7059
|
|
6
|
+
portforward/_portforward.pyi,sha256=KZSR_2INAUDtpwbVFA9e6cLs3KBwgMw-hgtirmMRZgY,336
|
|
7
|
+
portforward/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
portforward/_portforward.cpython-310-darwin.so,sha256=PY6s_akHOo5YIdfpcsgdGAIeuEK8K0WOIYCBkbmn9Z8,9503128
|
|
9
|
+
portforward-0.7.0.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
portforward-0.6.1.dist-info/METADATA,sha256=HMGXszM12NbLQ7TeGRnj6egNjD5wbPxL1Ez6l1LkniQ,3711
|
|
2
|
-
portforward-0.6.1.dist-info/WHEEL,sha256=YB4nIpEaVbQYtEelAR0MsnJWBlMXhW33ztHgM37Axhc,106
|
|
3
|
-
portforward-0.6.1.dist-info/license_files/LICENSE,sha256=n2aq0UH0YZkyF_5hougjNi5gzXIUapEEqEUn6FwAcFE,1075
|
|
4
|
-
portforward-0.6.1.dist-info/license_files/AUTHORS.rst,sha256=YQwE3_FUEuGVHbxYUa4NQMlG28QBGwcCYEoa2MP9Xgk,163
|
|
5
|
-
portforward/__init__.py,sha256=G7f0GD9RIyUNzRzqieH760lEUsSNCr45H-d1ryEOsTc,6238
|
|
6
|
-
portforward/_portforward.pyi,sha256=cAkWB_L4LhZAfqkeflWBoC_kHfcoT7hTfZnoWzFQxp4,333
|
|
7
|
-
portforward/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
-
portforward/_portforward.cpython-310-darwin.so,sha256=XPc9zDvyOKxQHZUrYTF-ajkDv7PTJqEEdtn-qgQQud8,20974312
|
|
9
|
-
portforward-0.6.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|