From 1d5a05347e87f2debd876bd8377d6194f28fe649 Mon Sep 17 00:00:00 2001 From: Guna Date: Fri, 4 Apr 2025 18:55:27 -0700 Subject: [PATCH 1/5] Adding proxy support to base handler generator Step 1 : adding lower support of proxy --- splunklib/binding.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/splunklib/binding.py b/splunklib/binding.py index c5f361b8..71b989f5 100644 --- a/splunklib/binding.py +++ b/splunklib/binding.py @@ -1434,7 +1434,7 @@ def readinto(self, byte_array): return bytes_read -def handler(key_file=None, cert_file=None, timeout=None, verify=False, context=None): +def handler(key_file=None, cert_file=None, timeout=None, verify=False, context=None, proxy=None): """This class returns an instance of the default HTTP request handler using the values you provide. @@ -1447,7 +1447,9 @@ def handler(key_file=None, cert_file=None, timeout=None, verify=False, context=N :param `verify`: Set to False to disable SSL verification on https connections. :type verify: ``Boolean`` :param `context`: The SSLContext that can is used with the HTTPSConnection when verify=True is enabled and context is specified - :type context: ``SSLContext` + :type context: ``SSLContext`` + :param `proxy`: A dictionary of possible proxies the handler can leverage + :type proxy: ``dict`` """ def connect(scheme, host, port): @@ -1481,8 +1483,13 @@ def request(url, message, **kwargs): for key, value in message["headers"]: head[key] = value method = message.get("method", "GET") - - connection = connect(scheme, host, port) + + # have a proxy entry for the current scheme + if proxy.get(scheme): + connection = connect(scheme, *proxy.get(scheme).split(":")) + connection.set_tunnel("www.python.org") + else: + connection = connect(scheme, host, port) is_keepalive = False try: connection.request(method, path, body, head) From dbcea2f215501ac43a9a8aaa1e9bcd0a49bc1c53 Mon Sep 17 00:00:00 2001 From: Guna Date: Fri, 4 Apr 2025 19:00:34 -0700 Subject: [PATCH 2/5] Adding proxies to mid level class --- splunklib/binding.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/splunklib/binding.py b/splunklib/binding.py index 71b989f5..93eccf59 100644 --- a/splunklib/binding.py +++ b/splunklib/binding.py @@ -1208,9 +1208,9 @@ class HttpLib: """ def __init__(self, custom_handler=None, verify=False, key_file=None, cert_file=None, context=None, retries=0, - retryDelay=10): + retryDelay=10, proxies=None): if custom_handler is None: - self.handler = handler(verify=verify, key_file=key_file, cert_file=cert_file, context=context) + self.handler = handler(verify=verify, key_file=key_file, cert_file=cert_file, context=context, proxies=proxies) else: self.handler = custom_handler self._cookies = {} From 387471050df55d45913d68652ba7f804343a71a9 Mon Sep 17 00:00:00 2001 From: Guna Date: Fri, 4 Apr 2025 19:05:34 -0700 Subject: [PATCH 3/5] Adding proxies at highest-level --- splunklib/client.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/splunklib/client.py b/splunklib/client.py index c78ea88d..78ffabbc 100644 --- a/splunklib/client.py +++ b/splunklib/client.py @@ -326,7 +326,11 @@ def connect(**kwargs): :type retryDelay: ``int`` (in seconds) :param `context`: The SSLContext that can be used when setting verify=True (optional) :type context: ``SSLContext`` + :param proxies: Optional proxies, formatted { "" : ":" } + :type proxies: ``dict`` + :return: An initialized :class:`Service` connection. + **Example**:: @@ -398,6 +402,8 @@ class Service(_BaseService): :param retryDelay: How long to wait between connection attempts if `retries` > 0 (optional, defaults to 10s). :type retryDelay: ``int`` (in seconds) :return: A :class:`Service` instance. + :param proxies: Optional proxies, formatted { "" : ":" } + :type proxies: ``dict`` **Example**:: From 8a769033232147669668d3239103c2322e0f7304 Mon Sep 17 00:00:00 2001 From: Guna Date: Fri, 4 Apr 2025 19:09:02 -0700 Subject: [PATCH 4/5] Typos --- splunklib/binding.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/splunklib/binding.py b/splunklib/binding.py index 93eccf59..614a7842 100644 --- a/splunklib/binding.py +++ b/splunklib/binding.py @@ -1434,7 +1434,7 @@ def readinto(self, byte_array): return bytes_read -def handler(key_file=None, cert_file=None, timeout=None, verify=False, context=None, proxy=None): +def handler(key_file=None, cert_file=None, timeout=None, verify=False, context=None, proxies=None): """This class returns an instance of the default HTTP request handler using the values you provide. @@ -1485,8 +1485,8 @@ def request(url, message, **kwargs): method = message.get("method", "GET") # have a proxy entry for the current scheme - if proxy.get(scheme): - connection = connect(scheme, *proxy.get(scheme).split(":")) + if proxies.get(scheme): + connection = connect(scheme, *(proxies.get(scheme).split(":"))) connection.set_tunnel("www.python.org") else: connection = connect(scheme, host, port) From f47d73787a01cd19da07e0a5d85fdfc2e12fa73b Mon Sep 17 00:00:00 2001 From: Guna Date: Fri, 4 Apr 2025 19:09:41 -0700 Subject: [PATCH 5/5] More typos --- splunklib/binding.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/splunklib/binding.py b/splunklib/binding.py index 614a7842..8ac1d0f3 100644 --- a/splunklib/binding.py +++ b/splunklib/binding.py @@ -1448,8 +1448,8 @@ def handler(key_file=None, cert_file=None, timeout=None, verify=False, context=N :type verify: ``Boolean`` :param `context`: The SSLContext that can is used with the HTTPSConnection when verify=True is enabled and context is specified :type context: ``SSLContext`` - :param `proxy`: A dictionary of possible proxies the handler can leverage - :type proxy: ``dict`` + :param `proxies`: A dictionary of possible proxies the handler can leverage + :type proxies: ``dict`` """ def connect(scheme, host, port):