Skip to content

Conversation

MoustaphaCamara
Copy link
Collaborator

@MoustaphaCamara MoustaphaCamara commented Oct 6, 2025

Documentation on how to configure the elabapi_client using a proxy, with the example of mitmproxy

Summary by CodeRabbit

  • New Features

    • Enhanced client example to demonstrate proxy and CA-bundle configuration and setting a default Authorization header.
  • Documentation

    • Added a "Using a proxy" section with environment-variable examples for proxy and CA bundle.
    • Standardized code block formatting across the docs and slightly restructured section placement.
  • Notes

    • No runtime behavior changes; documentation and examples only.

@coderabbitai
Copy link

coderabbitai bot commented Oct 6, 2025

Walkthrough

The README adds a "Using a proxy" section and converts several bash code fences to tildes. The example client now reads proxy and CA bundle environment variables, configures configuration.proxy and configuration.ssl_ca_cert, exports REQUESTS_CA_BUNDLE if needed, and sets a default Authorization header on the ApiClient.

Changes

Cohort / File(s) Summary
Docs: proxy usage & code-fence style
README.md
Added "Using a proxy" section with env var examples (HTTP_PROXY, HTTPS_PROXY, NO_PROXY, REQUESTS_CA_BUNDLE, CA_PATH). Replaced several ```bash code fences with ~~~bash. Documentation-only edits.
Client example: env proxy, CA bundle, auth header
examples/client.py
Reads HTTPS_PROXY/HTTP_PROXY and sets configuration.proxy when present. Reads CA_PATH/REQUESTS_CA_BUNDLE, sets configuration.ssl_ca_cert, and exports REQUESTS_CA_BUNDLE if unset. After creating ApiClient(configuration), calls set_default_header("Authorization", API_KEY). No changes to public API signatures.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Env as Environment
  participant Example as examples/client.py
  participant Config as Configuration
  participant Api as ApiClient
  participant Service as Remote Service

  User->>Example: run example
  Example->>Env: read HTTPS_PROXY / HTTP_PROXY
  Env-->>Example: proxy URL (optional)
  Example->>Config: set proxy if present

  Example->>Env: read CA_PATH / REQUESTS_CA_BUNDLE
  Env-->>Example: CA path (optional)
  Example->>Config: set ssl_ca_cert if present
  Example->>Env: export REQUESTS_CA_BUNDLE if unset

  Example->>Api: instantiate with Config
  Example->>Api: set_default_header("Authorization", API_KEY)
  Api->>Service: request (uses proxy / CA / header)
  Service-->>Api: response
  Api-->>Example: result
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

Engage: docs and client now align,
Proxies chart the network line,
CA anchors keep the TLS true,
Authorization sails with you.
Steady helm — deploy and pursue.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title aptly conveys the core purpose of this pull request, which is to update both documentation and the example client to include proxy configuration guidance. It directly references the primary enhancement without extraneous detail and aligns with the modifications made in README.md and client.py. This clarity ensures any crew member reviewing the history will immediately understand the intent of the change.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch mouss-251006-add-proxy-config

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 213eec0 and 399d46c.

📒 Files selected for processing (1)
  • README.md (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • README.md

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
examples/client.py (1)

48-57: Consider logging for better observability, Number One.

The CA bundle configuration logic is sound. However, silently catching all exceptions may mask unexpected errors during development or troubleshooting. As a starship's first officer would advise, visibility into anomalies strengthens our defensive posture.

Consider adding a debug log when the attribute doesn't exist:

 # set CA for both requests and the elabapi-client
 ca_path = os.getenv("CA_PATH") or os.getenv("REQUESTS_CA_BUNDLE")
 if ca_path:
     # let requests (and other libs) use this CA bundle unless already set
     os.environ.setdefault("REQUESTS_CA_BUNDLE", ca_path)
     try:
         configuration.ssl_ca_cert = ca_path
-    except Exception:
+    except AttributeError:
         # attribute may not exist on all generated configurations
         pass
+    except Exception as e:
+        # unexpected error, log for debugging
+        if configuration.debug:
+            print(f"Warning: Could not set ssl_ca_cert: {e}")
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6846a48 and 2adffd2.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • examples/client.py (1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.18.1)
README.md

64-64: Code fence style
Expected: tilde; Actual: backtick

(MD048, code-fence-style)


72-72: Code fence style
Expected: tilde; Actual: backtick

(MD048, code-fence-style)


83-83: Code fence style
Expected: tilde; Actual: backtick

(MD048, code-fence-style)

🪛 Ruff (0.13.3)
examples/client.py

43-45: try-except-pass detected, consider logging the exception

(S110)


43-43: Do not catch blind exception: Exception

(BLE001)


55-57: try-except-pass detected, consider logging the exception

(S110)


55-55: Do not catch blind exception: Exception

(BLE001)

Copy link
Contributor

@NicolasCARPi NicolasCARPi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please adress comments from 🐰

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
examples/client.py (2)

47-56: Engage similar refinements for CA bundle handling.

The CA certificate configuration follows the same pattern as the proxy configuration. The same optional refinements apply here: consider catching AttributeError specifically and adding debug logging if desired.

Apply this diff for more specific exception handling:

     try:
         configuration.ssl_ca_cert = ca_path
-    except Exception:
+    except AttributeError:
         # attribute may not exist on all generated configurations
-        pass
+        if configuration.debug:
+            print("Note: This client version does not support the 'ssl_ca_cert' attribute")

29-45: Make it so: align documentation with implementation

  • Remove NO_PROXY from the proxy usage comments (examples/client.py:33) or implement its handling.
  • Optional: catch AttributeError instead of broad Exception and add debug logging if configuration.debug is enabled.
 #   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
     try:
         configuration.proxy = proxy_url
-    except Exception:
+    except AttributeError:
         # some generated clients don't expose 'proxy', so ignore safely
+        if getattr(configuration, "debug", False):
+            print("Note: This client version does not support the 'proxy' attribute")
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2adffd2 and f730270.

📒 Files selected for processing (2)
  • README.md (3 hunks)
  • examples/client.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • README.md
🧰 Additional context used
🪛 Ruff (0.13.3)
examples/client.py

43-45: try-except-pass detected, consider logging the exception

(S110)


43-43: Do not catch blind exception: Exception

(BLE001)


54-56: try-except-pass detected, consider logging the exception

(S110)


54-54: Do not catch blind exception: Exception

(BLE001)

🔇 Additional comments (1)
examples/client.py (1)

58-62: Excellent work, ensign!

The Authorization header configuration is properly placed after the ApiClient instantiation, and the approach using set_default_header is sound. This ensures the API key is consistently included in all requests made through this client.


## Using a proxy

The simplest way to route API traffic through a proxy is to set standard environment variables before running your script.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now the readme is missing the part about the configuration.proxy

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 302cc75 and 213eec0.

📒 Files selected for processing (1)
  • README.md (3 hunks)

Copy link
Contributor

@NicolasCARPi NicolasCARPi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plus verbose sur le texte et moins verbose sur le code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants