Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,35 @@ exp_client = elabapi_python.ExperimentsApi(api_client)
items_client = elabapi_python.ItemsApi(api_client)
~~~

## Using a proxy

To route API traffic through a proxy, set the standard environment variables before running the script. These variables are used by both the Python HTTP stack and the eLabFTW client.

### Environment configuration

Set the following variables according to your proxy setup:

- `HTTP_PROXY` and `HTTPS_PROXY`: Define the proxy server address, including the protocol and port (for example, `http://127.0.0.1:8080`).
- `NO_PROXY`: Specify hostnames or IPs that should bypass the proxy (for example, localhost or internal domains).
- `REQUESTS_CA_BUNDLE`: Optional path to a custom CA certificate file, required if the proxy intercepts HTTPS traffic with a self-signed certificate.

Example:
~~~bash
export HTTP_PROXY="http://127.0.0.1:8080"
export HTTPS_PROXY="http://127.0.0.1:8080"
export NO_PROXY="localhost,127.0.0.1"
export REQUESTS_CA_BUNDLE="/path/to/proxy-ca.pem"
~~~

### Client configuration

The client automatically detects these environment variables. To set the proxy manually, use the configuration object:

~~~python
configuration.proxy = os.getenv("HTTPS_PROXY") or os.getenv("HTTP_PROXY")
configuration.ssl_ca_cert = os.getenv("CA_PATH") or os.getenv("REQUESTS_CA_BUNDLE")
~~~

# Unofficial documentation

From TU Graz, Shared RDM Project:
Expand All @@ -68,13 +97,13 @@ From TU Graz, Shared RDM Project:

The primary tool for generating the library is swagger-codegen. However, you can also use OpenAPI Generator as an alternative, if it better suits your requirements or you encounter issues with the default.

```bash
~~~bash
# Option 1: Generate using Swagger Codegen
./helper.sh generate

# Option 2: Generate using OpenAPI Generator
GENERATOR_TOOL=openapi ./helper.sh generate
```
~~~

### Or Generate from a local OpenAPI Specification
Ensure the `openapi.yaml` file is located in the current working directory, then run:
Expand All @@ -83,9 +112,9 @@ Ensure the `openapi.yaml` file is located in the current working directory, then
~~~

### Build packages
```bash
~~~bash
./helper.sh build
```
~~~

## Installing the library for dev

Expand Down
21 changes: 21 additions & 0 deletions examples/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@
# Set this flag to True to get more verbose output
configuration.debug = False

# PROXY CONFIG
# Typical usage:
# export HTTP_PROXY="http://127.0.0.1:8080"
# export HTTPS_PROXY="http://127.0.0.1:8080"
# export NO_PROXY=localhost,127.0.0.1
# export REQUESTS_CA_BUNDLE=/path/to/mitmproxy-ca.pem
# Many libraries (e.g. 'requests') read HTTP(S)_PROXY from the environment automatically.
# However the generated elabapi_python client uses a generated Configuration + urllib3
# which may not read those env vars. That is why we set the env vars along with 'configuration.proxy'
# and 'configuration.ssl_ca_cert' so the generated client itself uses the proxy and trust bundle.
proxy_url = os.getenv("HTTPS_PROXY") or os.getenv("HTTP_PROXY")
if proxy_url:
configuration.proxy = proxy_url

# set CA for both requests and the elabapi-client
ca_path = os.getenv("CA_PATH") or os.getenv("REQUESTS_CA_BUNDLE")
if ca_path:
configuration.ssl_ca_cert = ca_path
if not os.getenv("REQUESTS_CA_BUNDLE"):
os.environ["REQUESTS_CA_BUNDLE"] = ca_path

# Create an API client object with our configuration
api_client = elabapi_python.ApiClient(configuration)

Expand Down