Skip to content

Commit 7c764a5

Browse files
committed
Fix doing IAM requests on original endpoint
1 parent 85714ca commit 7c764a5

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
include=['yandexcloud*', 'yandex*'])
55

66
setup(name='yandexcloud',
7-
version='0.3',
7+
version='0.4',
88
description='The Yandex.Cloud official SDK',
99
url='https://github.com/yandex-cloud/python-sdk',
1010
author='Yandex LLC',
@@ -13,6 +13,7 @@
1313
install_requires=[
1414
'grpcio',
1515
'googleapis-common-protos',
16+
'six',
1617
],
1718
packages=packages,
1819
zip_safe=False)

yandexcloud/_auth_plugin.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from datetime import datetime
55

66
import grpc
7+
from six.moves.urllib.parse import urlparse
78

89
from yandex.cloud.iam.v1.iam_token_service_pb2 import CreateIamTokenRequest
910
from yandex.cloud.iam.v1.iam_token_service_pb2_grpc import IamTokenServiceStub
@@ -12,9 +13,10 @@
1213

1314

1415
class Credentials(grpc.AuthMetadataPlugin):
15-
def __init__(self, oauth_token, channel):
16+
def __init__(self, oauth_token, lazy_channel):
1617
self._oauth_token = oauth_token
17-
self._client = IamTokenServiceStub(channel)
18+
self._lazy_channel = lazy_channel
19+
self._channel = None
1820
self._cached_iam_token = None
1921
self._iam_token_timestamp = None
2022

@@ -25,13 +27,17 @@ def __call__(self, context, callback):
2527
callback(None, exception)
2628

2729
def _call(self, context, callback):
28-
if context.service_url == '/yandex.cloud.iam.v1.IamTokenService' or \
29-
context.service_url == '/yandex.cloud.endpoint.ApiEndpointService':
30+
u = urlparse(context.service_url)
31+
if u.path == '/yandex.cloud.iam.v1.IamTokenService' or \
32+
u.path == '/yandex.cloud.endpoint.ApiEndpointService':
3033
callback(None, None)
3134
return
3235

36+
if not self._channel:
37+
self._channel = self._lazy_channel()
38+
3339
if self._cached_iam_token is None or not self._fresh():
34-
token_future = self._client.Create.future(CreateIamTokenRequest(
40+
token_future = IamTokenServiceStub(self._channel).Create.future(CreateIamTokenRequest(
3541
yandex_passport_oauth_token=self._oauth_token))
3642
token_future.add_done_callback(self.create_done_callback(callback))
3743
return

yandexcloud/_channels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def channel(self, endpoint):
4040
endpoints = resp.endpoints
4141

4242
plugin = _auth_plugin.Credentials(
43-
self._token, self._unauthenticated_channel)
43+
self._token, lambda: self._channels["iam"])
4444
call_creds = grpc.metadata_call_credentials(plugin)
4545
creds = grpc.composite_channel_credentials(
4646
self._channel_creds, call_creds)

0 commit comments

Comments
 (0)