lightkube icon indicating copy to clipboard operation
lightkube copied to clipboard

How to configure custom SSL contex for requests?

Open 4andy opened this issue 2 years ago • 1 comments

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!

4andy avatar Dec 27 '23 15:12 4andy

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

gtsystem avatar Dec 31 '23 10:12 gtsystem