Skip to content

Commit cf289d9

Browse files
committed
support sa_key from string
1 parent c43a80f commit cf289d9

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

ydb/iam/auth.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,25 @@ 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,
106+
key,
107+
iam_endpoint=iam_endpoint,
108+
iam_channel_credentials=iam_channel_credentials
109+
)
110+
111+
@classmethod
112+
def from_content(cls, key, iam_endpoint=None, iam_channel_credentials=None):
113+
key_json = json.loads(key)
114+
account_id = key_json.get("service_account_id", None)
104115
if account_id is None:
105-
account_id = output.get("user_account_id", None)
116+
account_id = key_json.get("user_account_id", None)
106117
return cls(
107118
account_id,
108-
output["id"],
109-
output["private_key"],
119+
key_json["id"],
120+
key_json["private_key"],
110121
iam_endpoint=iam_endpoint,
111122
iam_channel_credentials=iam_channel_credentials,
112123
)

0 commit comments

Comments
 (0)