66import logging
77from ydb .iam import auth
88from .credentials import AbstractExpiringTokenCredentials
9+ from ydb import issues
910
1011logger = logging .getLogger (__name__ )
1112
@@ -75,23 +76,6 @@ def __init__(
7576 assert aiohttp is not None , "Install aiohttp library to use OAuth 2.0 token exchange credentials provider"
7677 self ._token_exchange_url = token_exchange_url
7778
78- def _process_response_status_code (self , response ):
79- if response .status_code == 403 :
80- raise issues .Unauthenticated (response .content )
81- if response .status_code >= 500 :
82- raise issues .Unavailable (response .content )
83- if response .status_code >= 400 :
84- raise issues .BadRequest (response .content )
85- if response .status_code != 200 :
86- raise issues .Error (response .content )
87-
88- def _process_response (self , response ):
89- self ._process_response_status_code (response )
90- response_json = json .loads (response .content )
91- access_token = response_json ["access_token" ]
92- expires_in = response_json ["expires_in" ]
93- return {"access_token" : access_token , "expires_in" : expires_in }
94-
9579 async def _make_token_request (self ):
9680 params = {
9781 "grant_type" : "urn:ietf:params:oauth:grant-type:token-exchange" ,
@@ -104,7 +88,19 @@ async def _make_token_request(self):
10488 timeout = aiohttp .ClientTimeout (total = 2 )
10589 async with aiohttp .ClientSession (timeout = timeout ) as session :
10690 async with session .post (self ._token_exchange_url , data = params , headers = headers ) as response :
107- return self ._process_response (response )
91+ if response .status == 403 :
92+ raise issues .Unauthenticated (await response .text ())
93+ if response .status >= 500 :
94+ raise issues .Unavailable (await response .text ())
95+ if response .status >= 400 :
96+ raise issues .BadRequest (await response .text ())
97+ if response .status != 200 :
98+ raise issues .Error (await response .text ())
99+
100+ response_json = await response .json ()
101+ access_token = response_json ["access_token" ]
102+ expires_in = response_json ["expires_in" ]
103+ return {"access_token" : access_token , "expires_in" : expires_in }
108104
109105
110106class JWTIamCredentials (TokenServiceCredentials , auth .BaseJWTCredentials ):
0 commit comments