Skip to content

Commit

Permalink
feat(CP4D Authentication): add ssl verification for self-signed certi…
Browse files Browse the repository at this point in the history
…ficates (#147)

* feat(CP4D Authentication): add ssl verification for self-signed certificates

Signed-off-by: Luc Exposito <luc.braunexposito@gmail.com>
  • Loading branch information
LBExposito authored Aug 1, 2022
1 parent cb6d75d commit a16685d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 4 additions & 2 deletions ibm_cloud_sdk_core/authenticators/cp4d_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class CloudPakForDataAuthenticator(Authenticator):
proxies: Dictionary for mapping request protocol to proxy URL.
proxies.http (optional): The proxy endpoint to use for HTTP requests.
proxies.https (optional): The proxy endpoint to use for HTTPS requests.
verify (optional): The path to the certificate to use for HTTPS requests.
Attributes:
token_manager (CP4DTokenManager): Retrieves and manages CP4D tokens from the endpoint specified by the url.
Expand All @@ -59,14 +60,15 @@ def __init__(self,
apikey: str = None,
disable_ssl_verification: bool = False,
headers: Optional[Dict[str, str]] = None,
proxies: Optional[Dict[str, str]] = None) -> None:
proxies: Optional[Dict[str, str]] = None,
verify: Optional[str] = None) -> None:
# Check the type of `disable_ssl_verification`. Must be a bool.
if not isinstance(disable_ssl_verification, bool):
raise TypeError('disable_ssl_verification must be a bool')

self.token_manager = CP4DTokenManager(
username=username, password=password, apikey=apikey, url=url,
disable_ssl_verification=disable_ssl_verification, headers=headers, proxies=proxies)
disable_ssl_verification=disable_ssl_verification, headers=headers, proxies=proxies, verify=verify)

self.validate()

Expand Down
9 changes: 7 additions & 2 deletions ibm_cloud_sdk_core/token_managers/cp4d_token_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class CP4DTokenManager(JWTTokenManager):
proxies: Proxies to use for making request. Defaults to None.
proxies.http (optional): The proxy endpoint to use for HTTP requests.
proxies.https (optional): The proxy endpoint to use for HTTPS requests.
verify (optional): The path to the certificate to use for HTTPS requests.
Attributes:
username (str): The username for authentication.
Expand All @@ -45,6 +46,7 @@ class CP4DTokenManager(JWTTokenManager):
proxies (dict): Proxies to use for making token requests.
proxies.http (str): The proxy endpoint to use for HTTP requests.
proxies.https (str): The proxy endpoint to use for HTTPS requests.
verify (str): The path to the certificate to use for HTTPS requests.
"""
TOKEN_NAME = 'token'
VALIDATE_AUTH_PATH = '/v1/authorize'
Expand All @@ -57,9 +59,11 @@ def __init__(self,
apikey: str = None,
disable_ssl_verification: bool = False,
headers: Optional[Dict[str, str]] = None,
proxies: Optional[Dict[str, str]] = None) -> None:
proxies: Optional[Dict[str, str]] = None,
verify: Optional[str] = None) -> None:
self.username = username
self.password = password
self.verify = verify
if url and not self.VALIDATE_AUTH_PATH in url:
url = url + '/v1/authorize'
self.apikey = apikey
Expand All @@ -83,7 +87,8 @@ def request_token(self) -> dict:
"password": self.password,
"api_key": self.apikey
}),
proxies=self.proxies)
proxies=self.proxies,
verify=self.verify)
return response

def set_headers(self, headers: Dict[str, str]) -> None:
Expand Down

0 comments on commit a16685d

Please sign in to comment.