Skip to content

Commit

Permalink
fix(client config): merge from master client config to JWT token manager
Browse files Browse the repository at this point in the history
  • Loading branch information
ehdsouza committed Oct 2, 2019
1 parent 1243a70 commit 0fe9482
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
[![Build Status](https://travis-ci.com/IBM/python-sdk-core.svg?branch=master)](https://travis-ci.com/IBM/python-sdk-core)
[![codecov](https://codecov.io/gh/IBM/python-sdk-core/branch/master/graph/badge.svg)](https://codecov.io/gh/IBM/python-sdk-core)
[![Latest Stable Version](https://img.shields.io/pypi/v/ibm-cloud-sdk-core.svg)](https://pypi.python.org/pypi/ibm-cloud-sdk-core)
[![CLA assistant](https://cla-assistant.io/readme/badge/ibm/python-sdk-core)](https://cla-assistant.io/ibm/python-sdk-core)

# python-sdk-core
This project contains the core functionality used by Python SDK's generated by the IBM OpenAPI 3 SDK Generator (openapi-sdkgen).
Python code generated by openapi-sdkgen will depend on the function contained in this project.

# Notice
Support for Python versions 2.x and versions <= 3.4 is deprecated and will be officially dropped in the next major release, which is expected to be end of September, 2019.

## Installation

To install, use `pip` or `easy_install`:
Expand Down
5 changes: 4 additions & 1 deletion ibm_cloud_sdk_core/base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
import requests
from requests.structures import CaseInsensitiveDict
from .version import __version__
from .utils import has_bad_first_or_last_char, remove_null_values, cleanup_values, read_external_sources
from .utils import has_bad_first_or_last_char, remove_null_values, cleanup_values
from .detailed_response import DetailedResponse
from .api_exception import ApiException
from .authenticators import Authenticator
from .jwt_token_manager import JWTTokenManager
from http.cookiejar import CookieJar
import logging

Expand Down Expand Up @@ -84,6 +85,8 @@ def set_http_config(self, http_config):
"""
if isinstance(http_config, dict):
self.http_config = http_config
if self.authenticator and hasattr(self.authenticator, 'token_manager') and isinstance(self.authenticator.token_manager, JWTTokenManager):
self.authenticator.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 @@ -33,6 +33,7 @@ def __init__(self, url, disable_ssl_verification=False, token_name=None):
self.token_name = token_name
self.token_info = {}
self.time_for_new_token = None
self.http_config = {}

def get_token(self):
"""
Expand Down Expand Up @@ -118,6 +119,9 @@ def _request(self,
data=None,
auth_tuple=None,
**kwargs):
kwargs = dict({"timeout": 60}, **kwargs)
kwargs = dict(kwargs, **self.http_config)

if self.disable_ssl_verification:
kwargs['verify'] = False

Expand Down
18 changes: 18 additions & 0 deletions test/test_base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,21 @@ def test_service_url_not_set():
with pytest.raises(ValueError) as err:
service.prepare_request('POST', url='')
assert str(err.value) == 'The service_url is required'


def test_setting_proxy():
service = BaseService('test', authenticator=IAMAuthenticator('wonder woman'))
assert service.authenticator is not None
assert service.authenticator.token_manager.http_config == {}

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

service2 = BaseService('test', authenticator=BasicAuthenticator('marvellous', 'mrs maisel'))
service2.set_http_config(http_config)
assert service2.authenticator is not None

0 comments on commit 0fe9482

Please sign in to comment.