-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "fix(migrate): improve acl->authz migration, remove deprecated…
… endpoints (#336)" (#337) This reverts commit 98146f5. Co-authored-by: Alexander VT <[email protected]>
- Loading branch information
1 parent
98146f5
commit 6d7b337
Showing
8 changed files
with
500 additions
and
369 deletions.
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
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
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,55 @@ | ||
from cdislogging import get_logger | ||
|
||
import flask | ||
import requests | ||
|
||
|
||
from indexd.index.errors import NoRecordFound as IndexNoRecordFound | ||
from indexd.errors import IndexdUnexpectedError | ||
from indexd.auth.errors import AuthError, AuthzError | ||
|
||
|
||
logger = get_logger(__name__) | ||
|
||
|
||
class FenceClient(object): | ||
def __init__(self, url): | ||
self.url = url | ||
|
||
def get_signed_url_for_object(self, object_id, access_id): | ||
fence_server = self.url | ||
api_url = fence_server.rstrip("/") + "/data/download/" | ||
url = api_url + object_id | ||
headers = flask.request.headers | ||
if "AUTHORIZATION" not in headers: | ||
logger.error("Bearer Token not available.") | ||
raise AuthError("Not Authorized. Access Token Required.") | ||
if access_id: | ||
url += "?protocol=" + access_id | ||
if flask.request.query_string: | ||
url = f"{url}&{flask.request.query_string.decode()}" | ||
try: | ||
req = requests.get(url, headers=headers) | ||
except Exception as e: | ||
logger.error("failed to reach fence at {0}: {1}".format(url + object_id, e)) | ||
raise IndexdUnexpectedError("Failed to retrieve access url") | ||
if req.status_code == 404: | ||
logger.error( | ||
"Not found. Fence could not find {}: {} with access id: {}".format( | ||
url + object_id, req.text, access_id | ||
) | ||
) | ||
raise IndexNoRecordFound( | ||
"No document with id:{} with access_id:{}".format(object_id, access_id) | ||
) | ||
if req.status_code == 401: | ||
raise AuthzError("Unauthorized: Access denied due to invalid credentials.") | ||
elif req.status_code != 200: | ||
err_msg = "Unable to get presigned URL from Fence" | ||
logger.error( | ||
"{} - code: {} - details:\n{}".format( | ||
err_msg, req.status_code, req.text | ||
) | ||
) | ||
raise IndexdUnexpectedError(code=req.status_code, message=err_msg) | ||
return req.json() |
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
Oops, something went wrong.