Skip to content

Commit 9d99046

Browse files
committed
temp
1 parent 598776e commit 9d99046

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

ydb/credentials.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,43 @@ def _wrap_static_credentials_response(rpc_state, response):
185185
class StaticCredentials(AbstractExpiringTokenCredentials):
186186
def __init__(self, driver_config, user, password="", tracer=None):
187187
super(StaticCredentials, self).__init__(tracer)
188-
self.driver_config = driver_config
188+
189+
from .driver import DriverConfig
190+
191+
self.driver_config = DriverConfig(
192+
endpoint=driver_config.endpoint,
193+
194+
)
195+
self.user = user
196+
self.password = password
197+
self.request_timeout = 10
198+
199+
def _make_token_request(self):
200+
conn = connection.Connection.ready_factory(self.driver_config.endpoint, self.driver_config)
201+
assert conn is not None, "Failed to establish connection in to %s" % self.driver_config.endpoint
202+
try:
203+
result = conn(
204+
ydb_auth_pb2.LoginRequest(user=self.user, password=self.password),
205+
ydb_auth_v1_pb2_grpc.AuthServiceStub,
206+
"Login",
207+
_wrap_static_credentials_response,
208+
settings_impl.BaseRequestSettings().with_timeout(self.request_timeout).with_need_rpc_auth(False),
209+
)
210+
finally:
211+
conn.close()
212+
return {"expires_in": 30 * 60, "access_token": result.token}
213+
214+
215+
class UserPasswordCredentials(AbstractExpiringTokenCredentials):
216+
def __init__(self, user, password, endpoint, database, root_certificates=None, tracer=None):
217+
super(UserPasswordCredentials).__init__(tracer)
218+
219+
from .driver import DriverConfig # to prevent circular dependencies
220+
self.driver_config = DriverConfig(
221+
endpoint=endpoint,
222+
database=database,
223+
root_certificates=root_certificates,
224+
)
189225
self.user = user
190226
self.password = password
191227
self.request_timeout = 10

0 commit comments

Comments
 (0)