Skip to content

Commit

Permalink
feat(SSL): Support to disable SSL certificate verification
Browse files Browse the repository at this point in the history
  • Loading branch information
ehdsouza committed Sep 19, 2018
1 parent a715334 commit e0f1d11
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Python client library to quickly get started with the various [Watson APIs][wdc]
* [Changes for v2.0](#changes-for-v20)
* [Migration](#migration)
* [Configuring the http client](#configuring-the-http-client-supported-from-v110)
* [Disable SSL certificate verification](#disable-ssl-certificate-verification)
* [Sending request headers](#sending-request-headers)
* [Parsing HTTP response info](#parsing-http-response-info)
* [Dependencies](#dependencies)
Expand Down Expand Up @@ -203,6 +204,13 @@ response = assistant.message(workspace_id=workspace_id, input={
print(json.dumps(response, indent=2))
```

## Disable SSL certificate verification
For ICP(IBM Cloud Private), you can disable the SSL certificate verification by:

```python
service.disable_SSL_verification()
```

## Sending request headers
Custom headers can be passed in any request in the form of a `dict` as:
```python
Expand Down
8 changes: 8 additions & 0 deletions test/unit/test_watson_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,11 @@ def test_for_icp():
assert service2.username is not None
assert service2.password is not None
assert service2.url is 'service_url'

@responses.activate
def test_disable_SSL_verification():
service1 = AnyServiceV1('2017-07-07', api_key='icp-xxxx', url='service_url')
assert service1.verify is None

service1.disable_SSL_verification()
assert service1.verify is False
8 changes: 8 additions & 0 deletions watson_developer_cloud/watson_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ def __init__(self, vcap_services_name, url, username=None, password=None,
self.iam_access_token = None
self.iam_url = None
self.token_manager = None
self.verify = None # Indicates whether to ignore verifying the SSL certification

user_agent_string = 'watson-apis-python-sdk-' + __version__ # SDK version
user_agent_string += ' ' + platform.system() # OS
Expand Down Expand Up @@ -349,6 +350,9 @@ def set_http_config(self, http_config):
else:
raise TypeError("http_config parameter must be a dictionary")

def disable_SSL_verification(self):
self.verify = False

def set_detailed_response(self, detailed_response):
self.detailed_response = detailed_response

Expand Down Expand Up @@ -445,6 +449,10 @@ def request(self, method, url, accept_json=False, headers=None,
params['api_key'] = self.api_key

kwargs = dict(kwargs, **self.http_config)

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

response = requests.request(method=method, url=full_url,
cookies=self.jar, auth=auth,
headers=headers,
Expand Down

1 comment on commit e0f1d11

@georg90
Copy link

@georg90 georg90 commented on e0f1d11 Jan 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.