fix(ICP): Minor changes in ICM logic
@@ -32,7 +32,7 @@ BEARER = 'Bearer'
X_WATSON_AUTHORIZATION_TOKEN = 'X-Watson-Authorization-Token'
AUTH_HEADER_DEPRECATION_MESSAGE = 'Authenticating with the X-Watson-Authorization-Token header is deprecated. The token continues to work with Cloud Foundry services, but is not supported for services that use Identity and Access Management (IAM) authentication.'
ICP_PREFIX = 'icp-'
-USERNAME_FOR_ICP = 'apikey'
+APIKEY = 'apikey'
# Uncomment this to enable http debugging
# try:
@@ -242,11 +242,11 @@ class WatsonService(object):
if api_key is not None:
if api_key.startswith(ICP_PREFIX):
- self.set_username_and_password(USERNAME_FOR_ICP, api_key)
+ self.set_username_and_password(APIKEY, api_key)
else:
self.set_api_key(api_key)
elif username is not None and password is not None:
- if username in ('apikey', 'apiKey'):
+ if username is APIKEY:
self.set_token_manager(password, iam_access_token, iam_url)
else:
self.set_username_and_password(username, password)
@@ -264,10 +264,6 @@ class WatsonService(object):
if 'password' in self.vcap_service_credentials:
self.password = self.vcap_service_credentials['password']
if 'apikey' in self.vcap_service_credentials:
- if self.vcap_service_credentials['apikey'].startswith(ICP_PREFIX):
- self.username = USERNAME_FOR_ICP
- self.password = self.vcap_service_credentials['apikey']
- else:
self.api_key = self.vcap_service_credentials['apikey']
if 'api_key' in self.vcap_service_credentials:
self.api_key = self.vcap_service_credentials['api_key']
@@ -298,7 +294,7 @@ class WatsonService(object):
if api_key == 'YOUR API KEY':
api_key = None
if api_key.startswith(ICP_PREFIX):
- self.set_username_and_password(USERNAME_FOR_ICP, api_key)
+ self.set_username_and_password(APIKEY, api_key)
self.api_key = api_key
