Skip to content

Commit a3aa824

Browse files
committed
chore(credentials): Check for overwriting of credentials
1 parent 653486b commit a3aa824

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

watson_developer_cloud/watson_service.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ def __init__(self, vcap_services_name, url, username=None, password=None,
256256
user_agent_string += ' ' + platform.python_version() # Python version
257257
self.user_agent_header = {'user-agent': user_agent_string}
258258

259+
# 1. Credentials are passed in constructor
259260
if api_key is not None:
260261
self.set_api_key(api_key)
261262
elif username is not None and password is not None:
@@ -266,11 +267,13 @@ def __init__(self, vcap_services_name, url, username=None, password=None,
266267
elif iam_access_token is not None or iam_apikey is not None:
267268
self.set_token_manager(iam_apikey, iam_access_token, iam_url)
268269

269-
if display_name is not None:
270+
# 2. Credentials from credential file
271+
if not display_name and not self.username and not self.token_manager:
270272
service_name = display_name.replace(' ', '_').lower()
271273
self.load_from_credential_file(service_name)
272274

273-
if use_vcap_services and not self.username and not self.api_key:
275+
# 3. Credentials from VCAP
276+
if use_vcap_services and not self.username and not self.token_manager:
274277
self.vcap_service_credentials = load_from_vcap_services(
275278
vcap_services_name)
276279
if self.vcap_service_credentials is not None and isinstance(

0 commit comments

Comments
 (0)