Repository navigation
fix: do not raise when both auth header and api_key is passed - #482
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the transport authorization migration changes.
No open issues 🎉
What changed in this PR
This PR eases migration from v6 by allowing transport-level Authorization headers alongside api_key. The SDK warns and uses api_key, while still rejecting an authorization header without an API key.
Changes:
- Move authorization validation from transport construction to client construction.
- Add tests for warnings, missing-key errors, and header precedence in synchronous and asynchronous transports.
- Update transport docstrings and README guidance.
| File | Description |
|---|---|
UnleashClient/transport/_requests.py |
Remove constructor rejection and update header documentation. |
UnleashClient/transport/_aiohttp.py |
Apply the same changes to the asynchronous transport. |
UnleashClient/transport/__init__.py |
Add shared validation that warns or raises based on api_key. |
UnleashClient/clients/unleash_client.py |
Validate transport authorization during client construction. |
UnleashClient/clients/async_unleash_client.py |
Add equivalent asynchronous-client validation. |
tests/unit_tests/test_transport.py |
Verify SDK authorization overrides custom authorization. |
tests/unit_tests/test_aiohttp_transport.py |
Verify asynchronous authorization header precedence. |
tests/unit_tests/clients/test_unleash_client_transport.py |
Test warnings and missing-key errors across header casing. |
tests/unit_tests/clients/test_async_unleash_client_transport.py |
Add equivalent asynchronous-client validation tests. |
README.md |
Explain API-key precedence and conditional validation. |
Review effort: Balanced
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.
An
Authorizationheader passed toRequestsTransportorAiohttpTransportno longer always raisesValueError.Follow-up to the review discussion on Unleash/unleash-documentation#160. Users migrating from v6 might move
custom_headers={"Authorization": ...}into the transport and also setapi_key. Failing to start in that case is harsher than needed, because the SDK's header replaces theirs. A warning gives them a period to remove it.Without
api_key, the header would be the only credential. Ignoring it silently would send unauthenticated requests and serve default flag values, so failing fast is still the safer choice there, so I kept raisingValueErrorbehaviour.