11import ydb
22
3- def load_ydb_ca_cert (path :str ) -> str :
4- """Load CA certification.
5-
6- Args:
7- path (str): path to CA certification.
8-
9- The function load_ydb_ca_cert accepts a path to a CA certificate
10- and returns its content as a byte string for further passing to ydb.DriverConfig.
11- If the specified path is incorrect or the certificate does not exist,
12- it raises an exception with the message "CA not found".
13-
14- """
15- if path is not None and os .path .exists (path ):
16- with open (path , "rb" ) as file :
17- return file .read ()
18- else :
19- raise FileNotFoundError ("CA not found" )
20-
213def test_driver_works (driver : ydb .Driver ):
224 """Tests the functionality of the YDB driver.
235
@@ -34,7 +16,7 @@ def test_driver_works(driver: ydb.Driver):
3416 result = pool .execute_with_retries ("SELECT 1 as cnt" )
3517 assert result [0 ].rows [0 ].cnt == 1
3618
37- def auth_with_static_credentials (endpoint : str , database : str , user : str , password : str ):
19+ def auth_with_static_credentials (endpoint : str , database : str , user : str , password : str , ca_path : str ):
3820 """Authenticate using static credentials.
3921
4022 Args:
@@ -52,7 +34,7 @@ def auth_with_static_credentials(endpoint: str, database: str, user: str, passwo
5234 endpoint = endpoint ,
5335 database = database ,
5436 credentials = ydb .StaticCredentials .from_user_password (user , password ),
55- root_certificates = load_ydb_ca_cert ( path = < path_to_ca - cert . crt > )
37+ root_certificates = ydb . auth_helpers . load_ydb_root_certificate ( ca_path )
5638 )
5739
5840 with ydb .Driver (driver_config = driver_config ) as driver :
0 commit comments