aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrekby <rekby@ydb.tech>2023-03-27 08:01:31 +0300
committerrekby <rekby@ydb.tech>2023-03-27 08:01:31 +0300
commit8f9b3c6be615e45788ac1917ad5dec0c66ae66b1 (patch)
treec8da1d59b3436daace38de72ecf5364ee740b610
parent27007511733688a9e501c044db191050c77a33e6 (diff)
downloadydb-8f9b3c6be615e45788ac1917ad5dec0c66ae66b1.tar.gz
tmp revert construct_credentials_from_environ
-rw-r--r--ydb/public/sdk/python3/ydb/__init__.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/ydb/public/sdk/python3/ydb/__init__.py b/ydb/public/sdk/python3/ydb/__init__.py
index 648077880e..bedfa4431d 100644
--- a/ydb/public/sdk/python3/ydb/__init__.py
+++ b/ydb/public/sdk/python3/ydb/__init__.py
@@ -20,6 +20,7 @@ try:
except Exception:
pass
+# THIS AND BELOW IS AUTOGENERATED for arcadia only
try:
import kikimr.public.sdk.python.ydb_v3_new_behavior # noqa
global_allow_split_transactions(False) # noqa
@@ -32,3 +33,47 @@ except ModuleNotFoundError:
global_allow_split_transactions(True) # noqa
global_allow_truncated_result(True) # noqa
+
+
+def construct_credentials_from_environ(tracer=None):
+ import os
+ import warnings
+
+ from . import credentials, tracing
+
+ tracer = tracer if tracer is not None else tracing.Tracer(None)
+ warnings.warn(
+ "using construct_credentials_from_environ method DEPRECATED, use ydb.credentials_from_env_variables "
+ )
+
+ # dynamically import required authentication libraries
+ if (
+ os.getenv("USE_METADATA_CREDENTIALS") is not None
+ and int(os.getenv("USE_METADATA_CREDENTIALS")) == 1
+ ):
+ import ydb.iam
+
+ tracing.trace(tracer, {"credentials.metadata": True})
+ return ydb.iam.MetadataUrlCredentials()
+
+ if os.getenv("YDB_TOKEN") is not None:
+ tracing.trace(tracer, {"credentials.access_token": True})
+ return credentials.AuthTokenCredentials(os.getenv("YDB_TOKEN"))
+
+ if os.getenv("SA_KEY_FILE") is not None:
+
+ import ydb.iam
+
+ tracing.trace(tracer, {"credentials.sa_key_file": True})
+ root_certificates_file = os.getenv("SSL_ROOT_CERTIFICATES_FILE", None)
+ iam_channel_credentials = {}
+ if root_certificates_file is not None:
+ iam_channel_credentials = {
+ "root_certificates": read_bytes(root_certificates_file)
+ }
+ return ydb.iam.ServiceAccountCredentials.from_file(
+ os.getenv("SA_KEY_FILE"),
+ iam_channel_credentials=iam_channel_credentials,
+ iam_endpoint=os.getenv("IAM_ENDPOINT", "iam.api.cloud.yandex.net:443"),
+ )
+