-
Notifications
You must be signed in to change notification settings - Fork 182
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
Issue ref #269: OAuth 2.0 Credential Format for Delta Sharing Python … #309
Merged
zhuansunxt
merged 6 commits into
delta-io:main
from
dialberg:dialberg_delta_sharing_client_v1
Jun 5, 2023
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
372f0a3
Issue ref #269: OAuth 2.0 Credential Format for Delta Sharing Python …
dialberg b1bafe4
Issue ref #269: OAuth 2.0 Credential Format for Delta Sharing Python …
dialberg 3140294
Issue ref #269: OAuth 2.0 Credential Format for Delta Sharing Python …
dialberg 467494a
Issue ref #269: OAuth 2.0 Credential Format for Delta Sharing Python …
dialberg 516c5b1
Issue ref #269: OAuth 2.0 Credential Format for Delta Sharing Python …
dialberg c315cab
Issue ref #269: OAuth 2.0 Credential Format for Delta Sharing Python …
dialberg 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 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,9 @@ | ||
############################################################################################### | ||
# | ||
# Copyright © 2023, 2023, Oracle and/or its affiliates. | ||
# Issue ref #269: OAuth 2.0 Credential Format for Delta Sharing Client | ||
# Code update: | ||
# - protocol.py | ||
# - rest_client.py | ||
# | ||
############################################################################################### |
This file contains 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 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 |
---|---|---|
|
@@ -143,16 +143,61 @@ def __init__(self, profile: DeltaSharingProfile, num_retries=10): | |
self._profile = profile | ||
self._num_retries = num_retries | ||
self._sleeper = lambda sleep_ms: time.sleep(sleep_ms / 1000) | ||
self.auth_session(profile) | ||
|
||
def auth_session(self, profile): | ||
self._session = requests.Session() | ||
self.auth_broker(profile) | ||
if urlparse(profile.endpoint).hostname == "localhost": | ||
self._session.verify = False | ||
|
||
def auth_broker(self, profile): | ||
if profile.share_credentials_version == 2: | ||
if profile.type == "persistent_oauth2.0": | ||
self.auth_persistent_oauth2(profile) | ||
elif profile.type == "bearer_token": | ||
self.auth_bearer_token(profile) | ||
elif profile.type == "basic": | ||
self.auth_basic(profile) | ||
else: | ||
self.auth_bearer_token(profile) | ||
else: | ||
self.auth_bearer_token(profile) | ||
|
||
def auth_bearer_token(self, profile): | ||
self._session.headers.update( | ||
{ | ||
"Authorization": f"Bearer {profile.bearer_token}", | ||
"User-Agent": DataSharingRestClient.USER_AGENT, | ||
} | ||
) | ||
if urlparse(profile.endpoint).hostname == "localhost": | ||
self._session.verify = False | ||
|
||
def auth_persistent_oauth2(self, profile): | ||
response = requests.post(profile.token_endpoint, | ||
data={"grant_type": "client_credentials"}, | ||
auth=(profile.client_id, | ||
profile.client_secret),) | ||
bearer_token = "{}".format(response.json()["access_token"]) | ||
|
||
self._session.headers.update( | ||
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. The content-type and accept headers are not meant to be sent to the API headers but the token exchange endpoints. 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. Fixed. |
||
{ | ||
"Authorization": f"Bearer {bearer_token}", | ||
"User-Agent": DataSharingRestClient.USER_AGENT, | ||
} | ||
) | ||
|
||
def auth_basic(self, profile): | ||
response = requests.post(profile.token_endpoint, | ||
data={"grant_type": "client_credentials"}, | ||
auth=(profile.username, profile.password),) | ||
bearer_token = "{}".format(response.json()["access_token"]) | ||
|
||
self._session.headers.update( | ||
{ | ||
"Authorization": f"Bearer {bearer_token}", | ||
"User-Agent": DataSharingRestClient.USER_AGENT, | ||
} | ||
) | ||
|
||
@retry_with_exponential_backoff | ||
def list_shares( | ||
|
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.
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.
Can you make all internal methods private by prepend the
_
? e.g._auth_broker
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.
Fixed.