-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
… Python Client Pull Request Signed-off-by: dialberg <[email protected]>
- Loading branch information
There are no files selected for viewing
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 | ||
# | ||
############################################################################################### |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,16 +143,60 @@ 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) -> requests.Session: | ||
self._session = requests.Session() | ||
self.auth_broker(profile) | ||
if urlparse(profile.endpoint).hostname == "localhost": | ||
self._session.verify = False | ||
|
||
def auth_broker(self, profile): | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
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, | ||
This comment has been minimized.
Sorry, something went wrong.
zhuansunxt
|
||
data = {"grant_type": "client_credentials"}, | ||
auth = (profile.client_id, profile.client_secret),) | ||
bearer_token = "{}".format(response.json()["access_token"]) | ||
|
||
self._session.headers.update( | ||
{ | ||
"Authorization": f"Bearer {bearer_token}", | ||
"User-Agent": DataSharingRestClient.USER_AGENT, | ||
} | ||
) | ||
|
||
def auth_basic(self, profile): | ||
This comment has been minimized.
Sorry, something went wrong.
zhuansunxt
|
||
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( | ||
|
3 comments
on commit 33bd3ba
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.
This looks good to me and is accordance with the proposal as outlined here: delta-io#269
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.
Hi @dialberg , I left some comments about the code change here.
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.
I have fixed the comments and added unit tests.
This should be
clientId