Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
padamstx marked this conversation as resolved.
Show resolved Hide resolved
# 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:
padamstx marked this conversation as resolved.
Show resolved Hide resolved
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