diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index baa74e3..2047f10 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -9,7 +9,7 @@ on: jobs: build: name: Build and Test Driver - runs-on: ubuntu-latest # keep your own runner + runs-on: ubuntu-latest strategy: matrix: python-version: [3.12] diff --git a/docs/examples/client.rst b/docs/examples/client.rst index 9a79149..09b46c8 100644 --- a/docs/examples/client.rst +++ b/docs/examples/client.rst @@ -312,6 +312,37 @@ disabled by setting `verify_server_version=False`. 'password', verify_server_version=False ) + +Headers +^^^^^^^^ +To add custom headers to all requests made by the client, provide a dictionary of headers during client instantiation. +.. code-block:: python + + from swimlane import Swimlane + + swimlane = Swimlane( + '192.168.1.1', # IP address or hostname + 'username', + 'password', + headers={ 'X-Custom-Header': 'custom-value' } + ) +This will add the specified headers to all requests made by the client, including those made by the preconfigured adapters. + +Proxies +^^^^^^^^ +To use a proxy for all requests made by the client, provide a dictionary of proxies during client instantiation. +.. code-block:: python + + from swimlane import Swimlane + + swimlane = Swimlane( + '192.168.1.1', # IP address or hostname + 'username', + 'password', + proxies={ 'http': 'http://10.10.1.10:3128', 'https': 'http://10.10.1.10:1080' } + ) +This will use the specified proxies for all requests made by the client, including those made by the preconfigured adapters. + Available Adapters ------------------ diff --git a/swimlane/core/client.py b/swimlane/core/client.py index f8bab8b..bd1fab4 100644 --- a/swimlane/core/client.py +++ b/swimlane/core/client.py @@ -70,14 +70,18 @@ class Swimlane(object): 'https://192.168.1.1', 'username', 'password', - verify_ssl=False + verify_ssl=False, + headers={'Custom-Header': 'value'}, + proxies={'http': 'http://proxy.example.com:8080', 'https': 'https://proxy.example.com:8080'} ) # Or establish connection using personal access token swimlane = Swimlane( 'https://192.168.1.1', access_token='abcdefg', - verify_ssl=False + verify_ssl=False, + headers={'Custom-Header': 'value'}, + proxies={'http': 'http://proxy.example.com:8080', 'https': 'https://proxy.example.com:8080'} ) # Retrieve an app @@ -100,7 +104,9 @@ def __init__( write_to_read_only: bool=False, retry: bool=True, max_retries: int=5, - retry_interval: int=5 + retry_interval: int=5, + headers=None, + proxies=None ): self.__verify_auth_params(username, password, access_token) @@ -119,7 +125,15 @@ def __init__( self._session = WrappedSession() self._session.verify = verify_ssl - + self._session.headers.update(headers or {}) + self._session.proxies.update(proxies or {}) + if self.host.scheme == 'http': + # Disable SSL verification for HTTP connections + self._session.verify = False + else: + # Ensure SSL verification is enabled for HTTPS connections + self._session.verify = verify_ssl + self.retry = retry self.max_retries = max_retries self.retry_interval = retry_interval