-
Notifications
You must be signed in to change notification settings - Fork 551
Use pure-sasl in python 3.11 #454
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
Merged
bkyryliuk
merged 1 commit into
dropbox:master
from
mdeshmu:use-pure-sasl-in-python-3.11
Jun 20, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Original source of this file is https://github.com/cloudera/impyla/blob/master/impala/sasl_compat.py | ||
# which uses Apache-2.0 license as of 21 May 2023. | ||
# This code was added to Impyla in 2016 as a compatibility layer to allow use of either python-sasl or pure-sasl | ||
# via PR https://github.com/cloudera/impyla/pull/179 | ||
# Even though thrift_sasl lists pure-sasl as dependency here https://github.com/cloudera/thrift_sasl/blob/master/setup.py#L34 | ||
# but it still calls functions native to python-sasl in this file https://github.com/cloudera/thrift_sasl/blob/master/thrift_sasl/__init__.py#L82 | ||
# Hence this code is required for the fallback to work. | ||
|
||
|
||
from puresasl.client import SASLClient, SASLError | ||
from contextlib import contextmanager | ||
|
||
@contextmanager | ||
def error_catcher(self, Exc = Exception): | ||
try: | ||
self.error = None | ||
yield | ||
except Exc as e: | ||
self.error = str(e) | ||
|
||
|
||
class PureSASLClient(SASLClient): | ||
def __init__(self, *args, **kwargs): | ||
mdeshmu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.error = None | ||
super(PureSASLClient, self).__init__(*args, **kwargs) | ||
|
||
def start(self, mechanism): | ||
with error_catcher(self, SASLError): | ||
if isinstance(mechanism, list): | ||
self.choose_mechanism(mechanism) | ||
else: | ||
self.choose_mechanism([mechanism]) | ||
return True, self.mechanism, self.process() | ||
# else | ||
return False, mechanism, None | ||
|
||
def encode(self, incoming): | ||
with error_catcher(self): | ||
return True, self.unwrap(incoming) | ||
# else | ||
return False, None | ||
|
||
def decode(self, outgoing): | ||
with error_catcher(self): | ||
return True, self.wrap(outgoing) | ||
# else | ||
return False, None | ||
|
||
def step(self, challenge=None): | ||
with error_catcher(self): | ||
return True, self.process(challenge) | ||
# else | ||
return False, None | ||
|
||
def getError(self): | ||
return self.error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.