Skip to content

Commit bb06ccd

Browse files
barshauldvora-h
andauthored
CredentialsProvider class added to support password rotation (#2261)
* A CredentialsProvider class has been added to allow the user to add his own provider for password rotation * Moved CredentialsProvider to a separate file, added type hints * Changed username and password to properties * Added: StaticCredentialProvider, examples, tests Changed: CredentialsProvider to CredentialProvider Fixed: calling AUTH only with password * Changed private members' prefix to __ * fixed linters * fixed auth test * fixed credential test * Raise an error if username or password are passed along with credential_provider * fixing linters * fixing test * Changed dundered to single per side underscore * Changed Connection class members username and password to properties to enable backward compatibility with changing the members value on existing connection. * Reverting last commit and adding backward compatibility to 'username' and 'password' inside on_connect function * Refactored CredentialProvider class * Fixing tuple type to Tuple * Fixing optional string members in UsernamePasswordCredentialProvider * Fixed credential test * Added credential provider support to AsyncRedis * linters * linters * linters * linters - black Co-authored-by: dvora-h <67596500+dvora-h@users.noreply.github.com> Co-authored-by: dvora-h <dvora.heller@redis.com>
1 parent fb64743 commit bb06ccd

13 files changed

+898
-74
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* ClusterPipeline Doesn't Handle ConnectionError for Dead Hosts (#2225)
2525
* Remove compatibility code for old versions of Hiredis, drop Packaging dependency
2626
* The `deprecated` library is no longer a dependency
27+
* Added CredentialsProvider class to support password rotation
2728
* Enable Lock for asyncio cluster mode
2829

2930
* 4.1.3 (Feb 8, 2022)

docs/examples/asyncio_examples.ipynb

Lines changed: 76 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@
2121
{
2222
"cell_type": "code",
2323
"execution_count": 1,
24-
"metadata": {
25-
"pycharm": {
26-
"name": "#%%\n"
27-
}
28-
},
2924
"outputs": [
3025
{
3126
"name": "stdout",
@@ -41,27 +36,29 @@
4136
"connection = redis.Redis()\n",
4237
"print(f\"Ping successful: {await connection.ping()}\")\n",
4338
"await connection.close()"
44-
]
39+
],
40+
"metadata": {
41+
"collapsed": false,
42+
"pycharm": {
43+
"name": "#%%\n"
44+
}
45+
}
4546
},
4647
{
4748
"cell_type": "markdown",
49+
"source": [
50+
"If you supply a custom `ConnectionPool` that is supplied to several `Redis` instances, you may want to disconnect the connection pool explicitly. Disconnecting the connection pool simply disconnects all connections hosted in the pool."
51+
],
4852
"metadata": {
53+
"collapsed": false,
4954
"pycharm": {
5055
"name": "#%% md\n"
5156
}
52-
},
53-
"source": [
54-
"If you supply a custom `ConnectionPool` that is supplied to several `Redis` instances, you may want to disconnect the connection pool explicitly. Disconnecting the connection pool simply disconnects all connections hosted in the pool."
55-
]
57+
}
5658
},
5759
{
5860
"cell_type": "code",
5961
"execution_count": 2,
60-
"metadata": {
61-
"pycharm": {
62-
"name": "#%%\n"
63-
}
64-
},
6562
"outputs": [],
6663
"source": [
6764
"import redis.asyncio as redis\n",
@@ -70,15 +67,16 @@
7067
"await connection.close()\n",
7168
"# Or: await connection.close(close_connection_pool=False)\n",
7269
"await connection.connection_pool.disconnect()"
73-
]
74-
},
75-
{
76-
"cell_type": "markdown",
70+
],
7771
"metadata": {
72+
"collapsed": false,
7873
"pycharm": {
79-
"name": "#%% md\n"
74+
"name": "#%%\n"
8075
}
81-
},
76+
}
77+
},
78+
{
79+
"cell_type": "markdown",
8280
"source": [
8381
"## Transactions (Multi/Exec)\n",
8482
"\n",
@@ -87,16 +85,17 @@
8785
"The commands will not be reflected in Redis until execute() is called & awaited.\n",
8886
"\n",
8987
"Usually, when performing a bulk operation, taking advantage of a “transaction” (e.g., Multi/Exec) is to be desired, as it will also add a layer of atomicity to your bulk operation."
90-
]
88+
],
89+
"metadata": {
90+
"collapsed": false,
91+
"pycharm": {
92+
"name": "#%% md\n"
93+
}
94+
}
9195
},
9296
{
9397
"cell_type": "code",
9498
"execution_count": 3,
95-
"metadata": {
96-
"pycharm": {
97-
"name": "#%%\n"
98-
}
99-
},
10099
"outputs": [],
101100
"source": [
102101
"import redis.asyncio as redis\n",
@@ -106,25 +105,31 @@
106105
" ok1, ok2 = await (pipe.set(\"key1\", \"value1\").set(\"key2\", \"value2\").execute())\n",
107106
"assert ok1\n",
108107
"assert ok2"
109-
]
108+
],
109+
"metadata": {
110+
"collapsed": false,
111+
"pycharm": {
112+
"name": "#%%\n"
113+
}
114+
}
110115
},
111116
{
112117
"cell_type": "markdown",
113-
"metadata": {},
114118
"source": [
115119
"## Pub/Sub Mode\n",
116120
"\n",
117121
"Subscribing to specific channels:"
118-
]
122+
],
123+
"metadata": {
124+
"collapsed": false,
125+
"pycharm": {
126+
"name": "#%% md\n"
127+
}
128+
}
119129
},
120130
{
121131
"cell_type": "code",
122132
"execution_count": 4,
123-
"metadata": {
124-
"pycharm": {
125-
"name": "#%%\n"
126-
}
127-
},
128133
"outputs": [
129134
{
130135
"name": "stdout",
@@ -165,23 +170,29 @@
165170
" await r.publish(\"channel:1\", STOPWORD)\n",
166171
"\n",
167172
" await future"
168-
]
173+
],
174+
"metadata": {
175+
"collapsed": false,
176+
"pycharm": {
177+
"name": "#%%\n"
178+
}
179+
}
169180
},
170181
{
171182
"cell_type": "markdown",
172-
"metadata": {},
173183
"source": [
174184
"Subscribing to channels matching a glob-style pattern:"
175-
]
185+
],
186+
"metadata": {
187+
"collapsed": false,
188+
"pycharm": {
189+
"name": "#%% md\n"
190+
}
191+
}
176192
},
177193
{
178194
"cell_type": "code",
179195
"execution_count": 5,
180-
"metadata": {
181-
"pycharm": {
182-
"name": "#%%\n"
183-
}
184-
},
185196
"outputs": [
186197
{
187198
"name": "stdout",
@@ -223,11 +234,16 @@
223234
" await r.publish(\"channel:1\", STOPWORD)\n",
224235
"\n",
225236
" await future"
226-
]
237+
],
238+
"metadata": {
239+
"collapsed": false,
240+
"pycharm": {
241+
"name": "#%%\n"
242+
}
243+
}
227244
},
228245
{
229246
"cell_type": "markdown",
230-
"metadata": {},
231247
"source": [
232248
"## Sentinel Client\n",
233249
"\n",
@@ -236,16 +252,17 @@
236252
"Calling aioredis.sentinel.Sentinel.master_for or aioredis.sentinel.Sentinel.slave_for methods will return Redis clients connected to specified services monitored by Sentinel.\n",
237253
"\n",
238254
"Sentinel client will detect failover and reconnect Redis clients automatically."
239-
]
255+
],
256+
"metadata": {
257+
"collapsed": false,
258+
"pycharm": {
259+
"name": "#%% md\n"
260+
}
261+
}
240262
},
241263
{
242264
"cell_type": "code",
243265
"execution_count": null,
244-
"metadata": {
245-
"pycharm": {
246-
"name": "#%%\n"
247-
}
248-
},
249266
"outputs": [],
250267
"source": [
251268
"import asyncio\n",
@@ -260,7 +277,13 @@
260277
"assert ok\n",
261278
"val = await r.get(\"key\")\n",
262279
"assert val == b\"value\""
263-
]
280+
],
281+
"metadata": {
282+
"collapsed": false,
283+
"pycharm": {
284+
"name": "#%%\n"
285+
}
286+
}
264287
}
265288
],
266289
"metadata": {
@@ -284,4 +307,4 @@
284307
},
285308
"nbformat": 4,
286309
"nbformat_minor": 1
287-
}
310+
}

0 commit comments

Comments
 (0)