external-systems 0.2.0__tar.gz → 0.3.0__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.
Potentially problematic release.
This version of external-systems might be problematic. Click here for more details.
- {external_systems-0.2.0 → external_systems-0.3.0}/PKG-INFO +1 -1
- {external_systems-0.2.0 → external_systems-0.3.0}/external_systems/_version.py +1 -1
- {external_systems-0.2.0 → external_systems-0.3.0}/external_systems/sources/_sockets.py +17 -9
- {external_systems-0.2.0 → external_systems-0.3.0}/external_systems/sources/_sources.py +1 -1
- {external_systems-0.2.0 → external_systems-0.3.0}/pyproject.toml +1 -1
- {external_systems-0.2.0 → external_systems-0.3.0}/LICENSE.txt +0 -0
- {external_systems-0.2.0 → external_systems-0.3.0}/README.md +0 -0
- {external_systems-0.2.0 → external_systems-0.3.0}/external_systems/__init__.py +0 -0
- {external_systems-0.2.0 → external_systems-0.3.0}/external_systems/py.typed +0 -0
- {external_systems-0.2.0 → external_systems-0.3.0}/external_systems/sources/__init__.py +0 -0
- {external_systems-0.2.0 → external_systems-0.3.0}/external_systems/sources/_api.py +0 -0
- {external_systems-0.2.0 → external_systems-0.3.0}/external_systems/sources/_connections.py +0 -0
- {external_systems-0.2.0 → external_systems-0.3.0}/external_systems/sources/_proxies.py +0 -0
- {external_systems-0.2.0 → external_systems-0.3.0}/external_systems/sources/_refreshable.py +0 -0
- {external_systems-0.2.0 → external_systems-0.3.0}/external_systems/sources/_utils.py +0 -0
|
@@ -19,6 +19,7 @@ import re
|
|
|
19
19
|
import socket
|
|
20
20
|
import ssl
|
|
21
21
|
import time
|
|
22
|
+
from typing import Optional
|
|
22
23
|
|
|
23
24
|
import urllib3
|
|
24
25
|
|
|
@@ -30,15 +31,20 @@ NUM_RETRIES = 10
|
|
|
30
31
|
RETRYABLE_RESPONSE_CODES = {503, 429}
|
|
31
32
|
|
|
32
33
|
|
|
33
|
-
def create_socket(
|
|
34
|
+
def create_socket(
|
|
35
|
+
https_proxy_uri: str, target_host: str, target_port: int, custom_ca_bundle_path: Optional[str] = None
|
|
36
|
+
) -> socket.socket:
|
|
34
37
|
"""
|
|
35
38
|
Establishes a socket connection through an HTTPS proxy to a target host and port.
|
|
36
|
-
|
|
39
|
+
|
|
40
|
+
Args:
|
|
37
41
|
https_proxy_uri (str): The URI of the HTTPS proxy, must include auth if required.
|
|
38
42
|
target_host (str): The hostname of the target server to connect to.
|
|
39
43
|
target_port (int): The port number of the target server to connect to.
|
|
44
|
+
|
|
40
45
|
Returns:
|
|
41
46
|
socket.socket: A connected SSL socket to the target host and port through the proxy.
|
|
47
|
+
|
|
42
48
|
Raises:
|
|
43
49
|
ValueError: If the proxy URI does not specify a hostname or port, or if the connection fails after retrying, with an invalid response code.
|
|
44
50
|
RuntimeError: If there is an exception during the socket creation process.
|
|
@@ -55,7 +61,7 @@ def create_socket(https_proxy_uri: str, target_host: str, target_port: int) -> s
|
|
|
55
61
|
last_response_code = -1
|
|
56
62
|
for _ in range(NUM_RETRIES):
|
|
57
63
|
try:
|
|
58
|
-
proxy_socket = _create_ssl_socket(parsed_proxy_uri.hostname, parsed_proxy_uri.port)
|
|
64
|
+
proxy_socket = _create_ssl_socket(parsed_proxy_uri.hostname, parsed_proxy_uri.port, custom_ca_bundle_path)
|
|
59
65
|
proxy_socket.sendall(f"CONNECT {target_host}:{target_port} HTTP/1.1\r\n".encode())
|
|
60
66
|
proxy_socket.sendall(f"Host: {target_host}:{target_port}\r\n".encode())
|
|
61
67
|
|
|
@@ -88,14 +94,16 @@ def create_socket(https_proxy_uri: str, target_host: str, target_port: int) -> s
|
|
|
88
94
|
raise ValueError(f"Failed to establish tunnel, invalid response code: {last_response_code}")
|
|
89
95
|
|
|
90
96
|
|
|
91
|
-
def _create_ssl_socket(proxy_host: str, proxy_port: int) -> socket.socket:
|
|
92
|
-
ca_bundle_path =
|
|
97
|
+
def _create_ssl_socket(proxy_host: str, proxy_port: int, custom_ca_bundle_path: Optional[str] = None) -> socket.socket:
|
|
98
|
+
ca_bundle_path = (
|
|
99
|
+
custom_ca_bundle_path if custom_ca_bundle_path is not None else os.environ.get("REQUESTS_CA_BUNDLE")
|
|
100
|
+
)
|
|
93
101
|
if not ca_bundle_path or not os.path.isfile(ca_bundle_path):
|
|
94
|
-
log.warning("The
|
|
95
|
-
raise ValueError("
|
|
102
|
+
log.warning("The CA_BUNDLE environment variable does not exist or is not a file.")
|
|
103
|
+
raise ValueError("CA_BUNDLE does not exist")
|
|
96
104
|
if not os.access(ca_bundle_path, os.R_OK):
|
|
97
|
-
log.warning("The
|
|
98
|
-
raise ValueError("
|
|
105
|
+
log.warning("The CA_BUNDLE file is not readable.")
|
|
106
|
+
raise ValueError("CA_BUNDLE is not readable")
|
|
99
107
|
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
100
108
|
context.load_verify_locations(ca_bundle_path)
|
|
101
109
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
@@ -241,4 +241,4 @@ class Source:
|
|
|
241
241
|
if not self._https_proxy_url:
|
|
242
242
|
raise ValueError("Only usable with Agent Proxy Sources")
|
|
243
243
|
|
|
244
|
-
return create_socket(self._https_proxy_url, target_host, target_port)
|
|
244
|
+
return create_socket(self._https_proxy_url, target_host, target_port, self._custom_ca_bundle_path)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|