Skip to content

Commit 7eaac7d

Browse files
authored
Merge pull request #430 support sa_key from string from uzhastik/load_sa_key_from_string
2 parents c43a80f + 4520342 commit 7eaac7d

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

ydb/iam/auth.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,22 @@ def set_token_expiration_timeout(self, value):
9999
@classmethod
100100
def from_file(cls, key_file, iam_endpoint=None, iam_channel_credentials=None):
101101
with open(os.path.expanduser(key_file), "r") as r:
102-
output = json.loads(r.read())
103-
account_id = output.get("service_account_id", None)
102+
key = r.read()
103+
104+
return BaseJWTCredentials.from_content(
105+
cls, key, iam_endpoint=iam_endpoint, iam_channel_credentials=iam_channel_credentials
106+
)
107+
108+
@classmethod
109+
def from_content(cls, key, iam_endpoint=None, iam_channel_credentials=None):
110+
key_json = json.loads(key)
111+
account_id = key_json.get("service_account_id", None)
104112
if account_id is None:
105-
account_id = output.get("user_account_id", None)
113+
account_id = key_json.get("user_account_id", None)
106114
return cls(
107115
account_id,
108-
output["id"],
109-
output["private_key"],
116+
key_json["id"],
117+
key_json["private_key"],
110118
iam_endpoint=iam_endpoint,
111119
iam_channel_credentials=iam_channel_credentials,
112120
)

0 commit comments

Comments
 (0)