|
8 | 8 | from itertools import chain |
9 | 9 | from queue import Empty, Full, LifoQueue |
10 | 10 | from time import time |
11 | | -from typing import Optional |
12 | 11 | from urllib.parse import parse_qs, unquote, urlparse |
13 | 12 |
|
14 | 13 | from redis.backoff import NoBackoff |
@@ -527,10 +526,8 @@ def __init__( |
527 | 526 | ) |
528 | 527 |
|
529 | 528 | self.credential_provider = credential_provider |
530 | | - if username or password: |
531 | | - # Keep backward compatibility by creating a static credential provider |
532 | | - # for the passed username and password |
533 | | - self.credential_provider = StaticCredentialProvider(username, password) |
| 529 | + self.password = password |
| 530 | + self.username = username |
534 | 531 | self.socket_timeout = socket_timeout |
535 | 532 | self.socket_connect_timeout = socket_connect_timeout or socket_timeout |
536 | 533 | self.socket_keepalive = socket_keepalive |
@@ -563,38 +560,6 @@ def __init__( |
563 | 560 | self._connect_callbacks = [] |
564 | 561 | self._buffer_cutoff = 6000 |
565 | 562 |
|
566 | | - @property |
567 | | - def password(self) -> Optional[str]: |
568 | | - if self.credential_provider is not None: |
569 | | - return self.credential_provider.password |
570 | | - else: |
571 | | - return None |
572 | | - |
573 | | - @password.setter |
574 | | - def password(self, value: Optional[str]): |
575 | | - if value is None: |
576 | | - # Delete the credential provider |
577 | | - self.credential_provider = None |
578 | | - return |
579 | | - if self.credential_provider is not None: |
580 | | - self.credential_provider.password = value |
581 | | - else: |
582 | | - self.credential_provider = StaticCredentialProvider(password=value) |
583 | | - |
584 | | - @property |
585 | | - def username(self) -> Optional[str]: |
586 | | - if self.credential_provider is not None: |
587 | | - return self.credential_provider.username |
588 | | - else: |
589 | | - return None |
590 | | - |
591 | | - @username.setter |
592 | | - def username(self, value: Optional[str]): |
593 | | - if self.credential_provider is not None: |
594 | | - self.credential_provider.username = value |
595 | | - else: |
596 | | - self.credential_provider = StaticCredentialProvider(username=value) |
597 | | - |
598 | 563 | def __repr__(self): |
599 | 564 | repr_args = ",".join([f"{k}={v}" for k, v in self.repr_pieces()]) |
600 | 565 | return f"{self.__class__.__name__}<{repr_args}>" |
@@ -721,9 +686,14 @@ def on_connect(self): |
721 | 686 | "Initialize the connection, authenticate and select a database" |
722 | 687 | self._parser.on_connect(self) |
723 | 688 |
|
724 | | - # if credentials provider is set, authenticate |
725 | | - if self.credential_provider is not None: |
726 | | - auth_args = self.credential_provider.get_credentials() |
| 689 | + # if credential provider or username and/or password are set, authenticate |
| 690 | + if self.credential_provider or (self.username or self.password): |
| 691 | + cred_provider = ( |
| 692 | + self.credential_provider |
| 693 | + if self.credential_provider |
| 694 | + else StaticCredentialProvider(self.username, self.password) |
| 695 | + ) |
| 696 | + auth_args = cred_provider.get_credentials() |
727 | 697 | # avoid checking health here -- PING will fail if we try |
728 | 698 | # to check the health prior to the AUTH |
729 | 699 | self.send_command("AUTH", *auth_args, check_health=False) |
@@ -1118,10 +1088,8 @@ def __init__( |
1118 | 1088 | "2. 'credential_provider'" |
1119 | 1089 | ) |
1120 | 1090 | self.credential_provider = credential_provider |
1121 | | - if username or password: |
1122 | | - # Keep backward compatibility by creating a static credential provider |
1123 | | - # for the passed username and password |
1124 | | - self.credential_provider = StaticCredentialProvider(username, password) |
| 1091 | + self.password = password |
| 1092 | + self.username = username |
1125 | 1093 | self.socket_timeout = socket_timeout |
1126 | 1094 | self.retry_on_timeout = retry_on_timeout |
1127 | 1095 | if retry_on_error is SENTINEL: |
@@ -1150,38 +1118,6 @@ def __init__( |
1150 | 1118 | self._connect_callbacks = [] |
1151 | 1119 | self._buffer_cutoff = 6000 |
1152 | 1120 |
|
1153 | | - @property |
1154 | | - def password(self) -> Optional[str]: |
1155 | | - if self.credential_provider is not None: |
1156 | | - return self.credential_provider.password |
1157 | | - else: |
1158 | | - return None |
1159 | | - |
1160 | | - @password.setter |
1161 | | - def password(self, value: Optional[str]): |
1162 | | - if value is None: |
1163 | | - # Delete the credential provider |
1164 | | - self.credential_provider = None |
1165 | | - return |
1166 | | - if self.credential_provider is not None: |
1167 | | - self.credential_provider.password = value |
1168 | | - else: |
1169 | | - self.credential_provider = StaticCredentialProvider(password=value) |
1170 | | - |
1171 | | - @property |
1172 | | - def username(self) -> Optional[str]: |
1173 | | - if self.credential_provider is not None: |
1174 | | - return self.credential_provider.username |
1175 | | - else: |
1176 | | - return None |
1177 | | - |
1178 | | - @username.setter |
1179 | | - def username(self, value: Optional[str]): |
1180 | | - if self.credential_provider is not None: |
1181 | | - self.credential_provider.username = value |
1182 | | - else: |
1183 | | - self.credential_provider = StaticCredentialProvider(username=value) |
1184 | | - |
1185 | 1121 | def repr_pieces(self): |
1186 | 1122 | pieces = [("path", self.path), ("db", self.db)] |
1187 | 1123 | if self.client_name: |
|
0 commit comments