Skip to content

fix(configs): Pass cllient configs to token managers #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ibm_cloud_sdk_core/base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ def set_http_config(self, http_config):
"""
if isinstance(http_config, dict):
self.http_config = http_config
if self.token_manager:
self.token_manager.http_config = http_config
else:
raise TypeError("http_config parameter must be a dictionary")

Expand Down
4 changes: 4 additions & 0 deletions ibm_cloud_sdk_core/jwt_token_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self, url, access_token=None, token_name=None):
self.expire_time = None
self.verify = None # to enable/ disable SSL verification
self.token_name = token_name
self.http_config = {}

def get_token(self):
"""
Expand Down Expand Up @@ -130,6 +131,9 @@ def _save_token_info(self, token_response):
self.token_info = token_response

def _request(self, method, url, headers=None, params=None, data=None, auth_tuple=None, **kwargs):
kwargs = dict({"timeout": 60}, **kwargs)
kwargs = dict(kwargs, **self.http_config)

if self.verify is not None:
kwargs['verify'] = not self.verify

Expand Down
13 changes: 13 additions & 0 deletions test/test_base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,3 +482,16 @@ def test_files():
form_data['file1'] = (None, file, 'application/octet-stream')
form_data['string1'] = (None, 'hello', 'text.plain')
service.request('GET', url='', headers={'X-opt-out': True}, files=form_data)

def test_setting_proxy():
service = BaseService('test', 'http://bogus', iam_apikey='testkey')
assert service.token_manager is not None
assert service.token_manager.http_config == {}

http_config = {
"proxies": {
"http": "user:password@host:port"
}
}
service.set_http_config(http_config)
assert service.token_manager.http_config == http_config