Skip to content

Commit

Permalink
fix(ICP): Authenticate using basic auth when iam_apikey is prefixed w…
Browse files Browse the repository at this point in the history
…ith icp
  • Loading branch information
ehdsouza committed Feb 6, 2019
1 parent 56cbfb4 commit 4ccfcbd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 11 additions & 0 deletions test/unit/test_watson_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ def test_for_icp():
assert service2.password is not None
assert service2.url is 'service_url'

service3 = AnyServiceV1('2017-07-07', iam_apikey='icp-xxx')
assert service3.token_manager is None
assert service2.iam_apikey is None
assert service2.username is not None
assert service2.password is not None

service4 = AnyServiceV1('2017-07-07', iam_access_token='lala')
assert service4.token_manager is not None
assert service4.username is None
assert service4.password is None

@responses.activate
def test_disable_SSL_verification():
service1 = AnyServiceV1('2017-07-07', username='apikey', password='icp-xxxx', url='service_url')
Expand Down
5 changes: 4 additions & 1 deletion watson_developer_cloud/watson_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,10 @@ def __init__(self, vcap_services_name, url, username=None, password=None,
else:
self.set_username_and_password(username, password)
elif iam_access_token is not None or iam_apikey is not None:
self.set_token_manager(iam_apikey, iam_access_token, iam_url)
if iam_apikey and iam_apikey.startswith(ICP_PREFIX):
self.set_username_and_password(APIKEY, iam_apikey)
else:
self.set_token_manager(iam_apikey, iam_access_token, iam_url)

# 2. Credentials from credential file
if display_name and not self.username and not self.token_manager:
Expand Down

0 comments on commit 4ccfcbd

Please sign in to comment.