Skip to content

Commit 08957eb

Browse files
committed
Fix some mistakes
1 parent a585fe5 commit 08957eb

File tree

2 files changed

+3
-22
lines changed

2 files changed

+3
-22
lines changed

examples/static-credentials/example.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,5 @@
11
import 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-
213
def 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:

ydb/auth_helpers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ def read_bytes(f):
77
return fr.read()
88

99

10-
def load_ydb_root_certificate():
11-
path = os.getenv("YDB_SSL_ROOT_CERTIFICATES_FILE", None)
10+
def load_ydb_root_certificate(path:str = None):
1211
if path is not None and os.path.exists(path):
1312
return read_bytes(path)
1413
return None

0 commit comments

Comments
 (0)