@@ -185,7 +185,44 @@ def _wrap_static_credentials_response(rpc_state, response):
185185class 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+ database = driver_config .database ,
194+ root_certificates = driver_config .root_certificates ,
195+ )
196+ self .user = user
197+ self .password = password
198+ self .request_timeout = 10
199+
200+ def _make_token_request (self ):
201+ conn = connection .Connection .ready_factory (self .driver_config .endpoint , self .driver_config )
202+ assert conn is not None , "Failed to establish connection in to %s" % self .driver_config .endpoint
203+ try :
204+ result = conn (
205+ ydb_auth_pb2 .LoginRequest (user = self .user , password = self .password ),
206+ ydb_auth_v1_pb2_grpc .AuthServiceStub ,
207+ "Login" ,
208+ _wrap_static_credentials_response ,
209+ settings_impl .BaseRequestSettings ().with_timeout (self .request_timeout ).with_need_rpc_auth (False ),
210+ )
211+ finally :
212+ conn .close ()
213+ return {"expires_in" : 30 * 60 , "access_token" : result .token }
214+
215+
216+ class UserPasswordCredentials (AbstractExpiringTokenCredentials ):
217+ def __init__ (self , user , password , endpoint , database , root_certificates = None , tracer = None ):
218+ super (UserPasswordCredentials ).__init__ (tracer )
219+
220+ from .driver import DriverConfig # to prevent circular dependencies
221+ self .driver_config = DriverConfig (
222+ endpoint = endpoint ,
223+ database = database ,
224+ root_certificates = root_certificates ,
225+ )
189226 self .user = user
190227 self .password = password
191228 self .request_timeout = 10
0 commit comments