-
Notifications
You must be signed in to change notification settings - Fork 447
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
Support Client Side Cert for Livy #576
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
|
||
class Endpoint(object): | ||
def __init__(self, url, auth, username="", password="", implicitly_added=False): | ||
def __init__(self, url, auth, username="", password="", implicitly_added=False, ssl_info=None): | ||
if not url: | ||
raise BadUserDataException(u"URL must not be empty") | ||
if auth not in AUTHS_SUPPORTED: | ||
|
@@ -13,6 +13,7 @@ def __init__(self, url, auth, username="", password="", implicitly_added=False): | |
self.username = username | ||
self.password = password | ||
self.auth = auth | ||
self.ssl_info = ssl_info | ||
# implicitly_added is set to True only if the endpoint wasn't configured manually by the user through | ||
# a widget, but was instead implicitly defined as an endpoint to a wrapper kernel in the configuration | ||
# JSON file. | ||
|
@@ -21,13 +22,37 @@ def __init__(self, url, auth, username="", password="", implicitly_added=False): | |
def __eq__(self, other): | ||
if type(other) is not Endpoint: | ||
return False | ||
return self.url == other.url and self.username == other.username and self.password == other.password and self.auth == other.auth | ||
return self.url == other.url and self.username == other.username and self.password == other.password and self.auth == other.auth and self.ssl_info == other.ssl_info | ||
|
||
def __hash__(self): | ||
return hash((self.url, self.username, self.password, self.auth)) | ||
return hash((self.url, self.username, self.password, self.auth, self.ssl_info)) | ||
|
||
def __ne__(self, other): | ||
return not self == other | ||
|
||
def __str__(self): | ||
return u"Endpoint({})".format(self.url) | ||
|
||
class SSLInfo(object): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a docstring explain what this class does, and what the parameters are. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, this seems like a good place to start using |
||
def __init__(self, client_cert, client_key, ssl_verify): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having two different places where youo set |
||
self.client_cert = client_cert | ||
self.client_key = client_key | ||
self.ssl_verify = ssl_verify | ||
|
||
@property | ||
def cert(self): | ||
return (self.client_cert, self.client_key, ) | ||
|
||
def __eq__(self, other): | ||
if type(other) is not SSLInfo: | ||
return False | ||
return self.client_cert == other.client_cert and self.client_key == other.client_key and self.ssl_verify == other.ssl_verify | ||
|
||
def __hash__(self): | ||
return hash((self.client_cert, self.client_key, self.ssl_verify)) | ||
|
||
def __ne__(self, other): | ||
return not self == other | ||
|
||
def __str__(self): | ||
return u"SSLInfo(client_cert={}, client_key={}, ssl_verify={})".format(self.client_cert, self.client_key, self.ssl_verify) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,15 +61,37 @@ def _send_request_helper(self, url, accepted_status_codes, function, data, retry | |
try: | ||
if self._endpoint.auth == constants.NO_AUTH: | ||
if data is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This now has a huge amount of duplicate paths and code, which makes me worry about errors. Can it be simplified? E.g.
at the top would simplify it quite a lot, and so on. |
||
r = function(url, headers=self._headers, verify=self.verify_ssl) | ||
if self._endpoint.ssl_info is None: | ||
r = function(url, headers=self._headers, verify=self.verify_ssl) | ||
else: | ||
r = function(url, headers=self._headers, | ||
verify=self._endpoint.ssl_info.ssl_verify, | ||
cert=self._endpoint.ssl_info.cert) | ||
else: | ||
r = function(url, headers=self._headers, data=json.dumps(data), verify=self.verify_ssl) | ||
if self._endpoint.ssl_info is None: | ||
r = function(url, headers=self._headers, data=json.dumps(data), verify=self.verify_ssl) | ||
else: | ||
r = function(url, headers=self._headers, data=json.dumps(data), | ||
verify=self._endpoint.ssl_info.ssl_verify, | ||
cert=self._endpoint.ssl_info.cert) | ||
else: | ||
if data is None: | ||
r = function(url, headers=self._headers, auth=self._auth, verify=self.verify_ssl) | ||
if self._endpoint.ssl_info is None: | ||
r = function(url, headers=self._headers, auth=self._auth, verify=self.verify_ssl) | ||
else: | ||
r = function(url, headers=self._headers, auth=self._auth, | ||
verify=self._endpoint.ssl_info.ssl_verify, | ||
cert=self._endpoint.ssl_info.cert) | ||
else: | ||
r = function(url, headers=self._headers, auth=self._auth, | ||
data=json.dumps(data), verify=self.verify_ssl) | ||
if self._endpoint.ssl_info is None: | ||
r = function(url, headers=self._headers, auth=self._auth, | ||
data=json.dumps(data), verify=self.verify_ssl) | ||
else: | ||
r = function(url, headers=self._headers, auth=self._auth, | ||
data=json.dumps(data), | ||
verify=self._endpoint.ssl_info.ssl_verify, | ||
cert=self._endpoint.ssl_info.cert) | ||
|
||
except requests.exceptions.RequestException as e: | ||
error = True | ||
r = None | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we say "TLS" instead of "SSL" everywhere? It's been TLS for 20 years now :)