From cf289d9c007033fb7d333d0ffbd90e897de1f58e Mon Sep 17 00:00:00 2001 From: Sergey Uzhakov Date: Sat, 8 Jun 2024 11:23:21 +0300 Subject: [PATCH 1/2] support sa_key from string --- ydb/iam/auth.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/ydb/iam/auth.py b/ydb/iam/auth.py index 7b4fa4e8..d4aa3424 100644 --- a/ydb/iam/auth.py +++ b/ydb/iam/auth.py @@ -99,14 +99,25 @@ def set_token_expiration_timeout(self, value): @classmethod def from_file(cls, key_file, iam_endpoint=None, iam_channel_credentials=None): with open(os.path.expanduser(key_file), "r") as r: - output = json.loads(r.read()) - account_id = output.get("service_account_id", None) + key = r.read() + + return BaseJWTCredentials.from_content( + cls, + key, + iam_endpoint=iam_endpoint, + iam_channel_credentials=iam_channel_credentials + ) + + @classmethod + def from_content(cls, key, iam_endpoint=None, iam_channel_credentials=None): + key_json = json.loads(key) + account_id = key_json.get("service_account_id", None) if account_id is None: - account_id = output.get("user_account_id", None) + account_id = key_json.get("user_account_id", None) return cls( account_id, - output["id"], - output["private_key"], + key_json["id"], + key_json["private_key"], iam_endpoint=iam_endpoint, iam_channel_credentials=iam_channel_credentials, ) From 4520342d2c01862c49df30b08cedd2ea34777135 Mon Sep 17 00:00:00 2001 From: Sergey Uzhakov Date: Sat, 8 Jun 2024 11:29:47 +0300 Subject: [PATCH 2/2] fix style --- ydb/iam/auth.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ydb/iam/auth.py b/ydb/iam/auth.py index d4aa3424..613b92ad 100644 --- a/ydb/iam/auth.py +++ b/ydb/iam/auth.py @@ -102,10 +102,7 @@ def from_file(cls, key_file, iam_endpoint=None, iam_channel_credentials=None): key = r.read() return BaseJWTCredentials.from_content( - cls, - key, - iam_endpoint=iam_endpoint, - iam_channel_credentials=iam_channel_credentials + cls, key, iam_endpoint=iam_endpoint, iam_channel_credentials=iam_channel_credentials ) @classmethod