Repository navigation
feat: send attributable User-Agent on REST and OAuth requests (backport #477 to stable/10) - #478
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The User-Agent hook rejects valid mapping inputs, is bypassed by manually supplied clients, can invalidate signed requests, and discards some caller-provided identifiers.
4 open issues
What changed in this PR
Backports SDK-first User-Agent handling to stable/10, helping gateway usage reports identify Python SDK traffic across REST and OAuth requests.
Changes:
- Add version-derived SDK identification with appended application and caller user agents.
- Integrate sync/async REST hooks and OAuth headers, with acceptance coverage.
- Regenerate SDK output and stubs, document configuration, and remove the unused generator setting.
| File | Description |
|---|---|
tests/acceptance/test_user_agent.py |
Tests attribution, suffix preservation, and hook handling. |
tests/acceptance/test_pluggable_auth.py |
Tests OAuth user-agent defaults and composition. |
stubs/camunda_orchestration_sdk/runtime/user_agent.pyi |
Adds user-agent helper signatures. |
stubs/camunda_orchestration_sdk/runtime/configuration_resolver.pyi |
Exposes the application user-agent setting. |
stubs/camunda_orchestration_sdk/runtime/cluster_admin_url.pyi |
Exposes shared hook types and helper. |
stubs/camunda_orchestration_sdk/runtime/auth.pyi |
Adds OAuth user-agent parameters. |
stubs/camunda_orchestration_sdk/client.pyi |
Reflects low-level client initialization hooks. |
scripts/escape-hatch-baseline.json |
Updates stable-branch typing baseline counts. |
runtime/user_agent.py |
Implements SDK identification and request hooks. |
runtime/configuration_resolver.py |
Adds CAMUNDA_USER_AGENT configuration. |
runtime/cluster_admin_url.py |
Extracts reusable request-hook composition. |
runtime/auth.py |
Sets user-agent headers on OAuth clients. |
README.md |
Documents application user-agent configuration. |
hooks/post_gen/0900_flatten_client.py |
Generates client hooks and configuration wiring. |
generator-config.yaml |
Removes the ignored httpUserAgent setting. |
generated/camunda_orchestration_sdk/runtime/user_agent.py |
Includes generated user-agent runtime helpers. |
generated/camunda_orchestration_sdk/runtime/configuration_resolver.py |
Includes generated configuration support. |
generated/camunda_orchestration_sdk/runtime/cluster_admin_url.py |
Includes the shared hook helper. |
generated/camunda_orchestration_sdk/runtime/auth.py |
Includes OAuth user-agent handling. |
generated/camunda_orchestration_sdk/client.py |
Includes generated REST hooks and OAuth wiring. |
Review effort: Balanced
| ua_post_init = ''' | ||
| def __attrs_post_init__(self) -> None: | ||
| """Attach the SDK ``User-Agent`` request hook to the httpx factories.""" | ||
| self._httpx_args = ensure_user_agent_hook(self._httpx_args) |
| def _is_httpx_default(value: str) -> bool: | ||
| """True only for httpx's bare default (``python-httpx/<version>``), nothing appended.""" | ||
|
|
||
| return value.startswith(_HTTPX_DEFAULT_PREFIX) and " " not in value |
Comment on lines
+75
to
+77
| return append_request_hook( | ||
| httpx_args, _make_hook(build_user_agent(application_user_agent), async_client) | ||
| ) |
Comment on lines
+88
to
+95
| hooks = (dict(httpx_args or {}).get("event_hooks") or {}) | ||
| request_hooks = hooks.get("request") if isinstance(hooks, dict) else None | ||
| if isinstance(request_hooks, (list, tuple)) and any( | ||
| isinstance(getattr(h, "__camunda_user_agent__", None), str) | ||
| for h in request_hooks | ||
| ): | ||
| return dict(httpx_args or {}) | ||
| return inject_user_agent_hook(httpx_args) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Backport of #477 to
stable/10, done by hand: this repo has no backport workflow yet (#460 is still open).How it was built:
runtime/,hooks/post_gen/0900_flatten_client.py,generator-config.yaml, the tests and the README.generated/andstubs/were regenerated on stable/10 withmake generate-only, in a separatechore(gen)commit. They touch the same files as on main, with no unrelated drift.scripts/escape-hatch-baseline.jsonwas recounted for stable/10 withcheck_escape_hatches.py --update(any: 363 → 366), instead of taking main's counts.Tested locally:
make check(ruff, ty, escape-hatch guard) andmake test(1009 passed).relates to #476