How to configure custom SSL contex for requests?
Hi - I have a use case for using a custom SSL context and was wondering if the httpx client used by lightkube is exposed in some way that I could configure it?
Thanks for your help!
Hi, have you tried using the httpx environment variables https://www.python-httpx.org/environment_variables/ ?
If this doesn't work, it would be possible to override the httpx client constructor function: https://github.com/gtsystem/lightkube/blob/master/lightkube/config/client_adapter.py#L14 https://github.com/gtsystem/lightkube/blob/master/lightkube/core/generic_client.py#L73
However, be aware that the function signature may change in the future and you will have to readapt your code.
Untested example:
import httpx
from lightkube import SingleConfig, Client
from lightkube.config import client_adapter
from lightkube.core.generic_client import GenericClient
def MyHttpxClient(config: SingleConfig, timeout: httpx.Timeout, trust_env: bool = True) -> httpx.Client:
params = client_adapter.httpx_parameters(config, timeout, trust_env)
params.update(...). # add here any custom configuration
return httpx.Client(**params)
GenericClient.AdapterClient = MyHttpxClient
client = Client() # this will use the adapter defined above