Skip to content

Commit 257f5c4

Browse files
committed
remove UserPasswordCredentials
1 parent dff7303 commit 257f5c4

File tree

3 files changed

+7
-123
lines changed

3 files changed

+7
-123
lines changed

docs/examples/authentication.rst

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ Full executable example `here <https://github.com/ydb-platform/ydb-python-sdk/tr
3131
)
3232
3333
34-
Static Credentials (Legacy)
34+
Static Credentials
3535
---------------------------
36-
This method is legacy, use UserPasswordCredentials instead.
3736

3837
Full executable example `here <https://github.com/ydb-platform/ydb-python-sdk/tree/main/examples/static-credentials>`_.
3938

@@ -43,41 +42,13 @@ Full executable example `here <https://github.com/ydb-platform/ydb-python-sdk/tr
4342
driver_config = ydb.DriverConfig(
4443
endpoint=endpoint,
4544
database=database,
46-
)
47-
creds = ydb.StaticCredentials(
48-
driver_config=driver_config,
49-
user=user,
50-
password=password,
51-
)
52-
53-
driver = ydb.Driver(
54-
driver_config=driver_config,
55-
credentials=creds,
56-
)
57-
58-
59-
User Password Credentials
60-
-------------------------
61-
62-
Full executable example `here <https://github.com/ydb-platform/ydb-python-sdk/tree/main/examples/static-credentials>`_.
63-
64-
.. code-block:: python
65-
66-
driver_config = ydb.DriverConfig(
67-
endpoint=endpoint,
68-
database=database,
69-
credentials=ydb.UserPasswordCredentials(
70-
user=user,
71-
password=password,
72-
endpoint=endpoint,
73-
database=database,
74-
),
45+
credentials=ydb.StaticCredentials.from_user_password(user, password),
7546
)
7647
7748
driver = ydb.Driver(driver_config=driver_config)
7849
7950
80-
Service Accaount Credentials
51+
Service Account Credentials
8152
----------------------------
8253

8354
Full executable example `here <https://github.com/ydb-platform/ydb-python-sdk/tree/main/examples/service-account-credentials>`_.

examples/static-credentials/example.py

Lines changed: 4 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,11 @@
44
def test_driver_works(driver: ydb.Driver):
55
driver.wait(5)
66
pool = ydb.QuerySessionPool(driver)
7-
pool.execute_with_retries("SELECT 1")
8-
print("everything is fine")
7+
result = pool.execute_with_retries("SELECT 1 as cnt")
8+
assert result[0].rows[0].cnt == 1
99

1010

11-
def auth_with_static_credentials_old(endpoint: str, database: str, user: str, password: str):
12-
driver_config_temp = ydb.DriverConfig(
13-
endpoint=endpoint,
14-
database=database,
15-
)
16-
creds = ydb.StaticCredentials(
17-
driver_config=driver_config_temp,
18-
user=user,
19-
password=password,
20-
)
21-
22-
driver_config = ydb.DriverConfig(
23-
endpoint=endpoint,
24-
database=database,
25-
credentials=creds,
26-
)
27-
28-
with ydb.Driver(driver_config=driver_config) as driver:
29-
test_driver_works(driver)
30-
31-
32-
def auth_with_static_credentials_new(endpoint: str, database: str, user: str, password: str):
33-
driver_config = ydb.DriverConfig(
34-
endpoint=endpoint,
35-
database=database,
36-
)
37-
creds = ydb.StaticCredentials(
38-
driver_config=driver_config,
39-
user=user,
40-
password=password,
41-
)
42-
43-
with ydb.Driver(driver_config=driver_config, credentials=creds) as driver:
44-
test_driver_works(driver)
45-
46-
47-
def auth_with_static_credentials_new2(endpoint: str, database: str, user: str, password: str):
11+
def auth_with_static_credentials(endpoint: str, database: str, user: str, password: str):
4812
driver_config = ydb.DriverConfig(
4913
endpoint=endpoint,
5014
database=database,
@@ -55,24 +19,5 @@ def auth_with_static_credentials_new2(endpoint: str, database: str, user: str, p
5519
test_driver_works(driver)
5620

5721

58-
def auth_with_user_password_credentials(endpoint: str, database: str, user: str, password: str):
59-
driver_config = ydb.DriverConfig(
60-
endpoint=endpoint,
61-
database=database,
62-
credentials=ydb.UserPasswordCredentials(
63-
user=user,
64-
password=password,
65-
endpoint=endpoint,
66-
database=database,
67-
),
68-
)
69-
70-
with ydb.Driver(driver_config=driver_config) as driver:
71-
test_driver_works(driver)
72-
73-
7422
def run(endpoint: str, database: str, user: str, password: str):
75-
auth_with_static_credentials_old(endpoint, database, user, password)
76-
auth_with_static_credentials_new(endpoint, database, user, password)
77-
auth_with_static_credentials_new2(endpoint, database, user, password)
78-
auth_with_user_password_credentials(endpoint, database, user, password)
23+
auth_with_static_credentials(endpoint, database, user, password)

ydb/credentials.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -230,38 +230,6 @@ def _update_driver_config(self, driver_config):
230230
)
231231

232232

233-
class UserPasswordCredentials(AbstractExpiringTokenCredentials):
234-
def __init__(self, user, password, endpoint, database, root_certificates=None, tracer=None):
235-
super(UserPasswordCredentials, self).__init__(tracer)
236-
237-
from .driver import DriverConfig # to prevent circular dependencies
238-
239-
self.driver_config = DriverConfig(
240-
endpoint=endpoint,
241-
database=database,
242-
root_certificates=root_certificates,
243-
)
244-
245-
self.user = user
246-
self.password = password
247-
self.request_timeout = 10
248-
249-
def _make_token_request(self):
250-
conn = connection.Connection.ready_factory(self.driver_config.endpoint, self.driver_config)
251-
assert conn is not None, "Failed to establish connection in to %s" % self.driver_config.endpoint
252-
try:
253-
result = conn(
254-
ydb_auth_pb2.LoginRequest(user=self.user, password=self.password),
255-
ydb_auth_v1_pb2_grpc.AuthServiceStub,
256-
"Login",
257-
_wrap_static_credentials_response,
258-
settings_impl.BaseRequestSettings().with_timeout(self.request_timeout).with_need_rpc_auth(False),
259-
)
260-
finally:
261-
conn.close()
262-
return {"expires_in": 30 * 60, "access_token": result.token}
263-
264-
265233
class AnonymousCredentials(Credentials):
266234
@staticmethod
267235
def auth_metadata():

0 commit comments

Comments
 (0)