redis-py
redis-py copied to clipboard
CredentialsProvider class added to support password rotation
Pull Request check-list
Please make sure to review and check all of these items:
- [x] Does
$ tox
pass with this change (including linting)? - [x] Do the CI tests pass with this change (enable it first in your forked repo and wait for the github action build to finish)?
- [x] Is the new or changed code fully tested?
- [x] Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
- [x] Is there an example added to the examples folder (if applicable)?
- [x] Was the change added to CHANGES file?
NOTE: these things are not required to open a PR and can be done afterwards / while the PR is open.
Description of change
Instead of providing a simple pair of username+password, the users can create a CredentialsProvider object with their own credentials supplier function, and have redis-py call it whenever a new connection is created. By doing so, users will be able to fetch the current password and rotate credentials without having to create a new client.
See related feature request in Lettuce: https://github.com/lettuce-io/lettuce-core/issues/1774
Codecov Report
Base: 92.04% // Head: 92.12% // Increases project coverage by +0.07%
:tada:
Coverage data is based on head (
4c82551
) compared to base (fb64743
). Patch coverage: 97.28% of modified lines in pull request are covered.
Additional details and impacted files
@@ Coverage Diff @@
## master #2261 +/- ##
==========================================
+ Coverage 92.04% 92.12% +0.07%
==========================================
Files 110 113 +3
Lines 28746 29063 +317
==========================================
+ Hits 26460 26773 +313
- Misses 2286 2290 +4
Impacted Files | Coverage Δ | |
---|---|---|
redis/cluster.py | 89.85% <ø> (ø) |
|
redis/asyncio/connection.py | 86.61% <84.61%> (+0.22%) |
:arrow_up: |
redis/connection.py | 86.42% <85.71%> (+0.11%) |
:arrow_up: |
redis/credentials.py | 91.66% <91.66%> (ø) |
|
tests/test_credentials.py | 98.44% <98.44%> (ø) |
|
tests/test_asyncio/test_credentials.py | 98.73% <98.73%> (ø) |
|
redis/__init__.py | 90.90% <100.00%> (+0.43%) |
:arrow_up: |
redis/asyncio/client.py | 92.28% <100.00%> (+0.01%) |
:arrow_up: |
redis/asyncio/cluster.py | 90.77% <100.00%> (+0.01%) |
:arrow_up: |
redis/client.py | 89.12% <100.00%> (+0.02%) |
:arrow_up: |
... and 5 more |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.
:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
Added type hints + moved CredentialsProvider to a separate file
@chayim @dvora-h - Finished round, ready for review :). Tests failed here from some internal error, in my fork it seems that tests are passing: https://github.com/barshaul/redis-py/pull/16#partial-pull-merging
@barshaul Thanks as always. I left a tonne of comments - and will give it another once over. As part of this, I suggest a MockCredentialProvider or similar. It would be nice to provide an example of a standard provider, perhaps implemented by a single (useless) function. This is how @dvora-h initially looked at this PR in fact.
@chayim Finished round. I left some of the reviews open with questions
@barshaul See tests failure
@barshaul See tests failure
@dvora-h fixed
@dvora-h once @barshaul addresses @akx suggestions, I think an end-to-end (re)review of this is worthwhile. It can't make rc3 but could make rc4, potentially.
@chayim @dvora-h @akx - finished round
@barshaul I think that after adding async support we are good to go.
LGTM now!