Skip to content

Commit

Permalink
promote dev
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpricethesecond committed Sep 17, 2024
2 parents 423ce64 + 2cc2da4 commit d8b0f59
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Intellij files
.idea/*
*config-local*
*pycache*
*config-local.json*
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
1.6.4
1.7.0

Live-docs: https://tapis-project.github.io/live-docs/?service=GlobusProxy

Breaking Changes:
- new config requirement to have a client_id and client_secret in the config-local.json file. This will be the id and secret of the service client. See https://docs.globus.org/guides/recipes/automate-with-service-account/ for instructions on how to create a service client and give it credentials.
- none

New features:
- none

Bug fixes:
- none
- fixed incorrect error code when globus errors happen while making a transfer
- fixed formatting of error logs
- fixed 400 error on GET when a content-type header is included
- added additional tenant
- better error messages for uncaught exceptions
- change schema to allow for larger file sizes
13 changes: 7 additions & 6 deletions service/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,18 @@ def __init__(self, url_map, *items):

@app.before_request
def log_before():
logger.info('\n========== Received new request ==========')
logger.info(f'{request}\n')
logger.info(f'\n{request.headers}')
if request.json:
logger.info(f'json:: {request.json}')
print()
logger.info(f'========== Received new request ==========')
logger.info({request})
# if request.json:
# logger.debug(f'json:: {request.json}')

@app.after_request
def log_after(response):
# logger.debug(f'request complete with status:: {response.data['status']}')

if response.status == '500 INTERNAL SERVER ERROR':
logger.error(f'\tEncountered error during request: {response.json}')
logger.info(f'\n========== Ended request with status:: {response.status} ==========\n')
logger.info(f'========== Ended request with status:: {response.status} ==========')
print()
return response
20 changes: 12 additions & 8 deletions service/controllers/transfers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
class TransferResource(Resource):
def post(self, client_id):
logger.info(f'Beginning creation of transfer task for client: {client_id} with args: {request.args} and json: {request.json}')
logger.debug(f'request headers:: {request.headers}')
logger.debug(f'request json:: {request.json}')
# logger.debug(f'request headers:: {request.headers}')
# logger.debug(f'request json:: {request.json}')

# setup
access_token = None
Expand Down Expand Up @@ -52,7 +52,7 @@ def post(self, client_id):
except Exception as e:
logger.error(f'Error parsing args for request:: {e}')

logger.debug(f'have setup args \naccess_token: {access_token}\nrefresh_token: {refresh_token}\nsrc: {src}\ndest: {dest}\nitems: {items}\n')
# logger.debug(f'have setup args \naccess_token: {access_token}\nrefresh_token: {refresh_token}\nsrc: {src}\ndest: {dest}\nitems: {items}\n')

if not access_token or not refresh_token:
logger.error('error parsing args')
Expand All @@ -65,12 +65,13 @@ def post(self, client_id):
logger.debug(f'have tc:: {transfer_client}')
except TransferAPIError as e:
logger.error(f'got TransferAPIError trying to submit transfer job:: {e}')
raise handle_transfer_error(e.http_reason)
raise handle_transfer_error(e)
except GlobusError as e:
raise handle_transfer_error(e)
except Exception as e:
logger.error(f'failed to authenticate transfer client :: {e}')
raise InternalServerError(msg='Failed to authenticate transfer client')
# raise InternalServerError(msg='Failed to authenticate transfer client')
raise handle_transfer_error(e)

## perform request
result = (transfer(transfer_client, src, dest, items))
Expand All @@ -97,12 +98,14 @@ def get(self, client_id, task_id):
transfer_client = precheck(client_id, None, access_token, refresh_token)
except Exception as e:
logger.error(f'error while getting transfer client for client id {client_id}: {e}')
raise InternalServerError(msg='Error while authenticating globus client')
# raise InternalServerError(msg='Error while authenticating globus client')
raise handle_transfer_error(e)
try:
result = transfer_client.get_task(task_id)
except Exception as e:
logger.error(f'error while getting transfer task with id {task_id}: {e}')
raise InternalServerError(msg='Error retrieving transfer task')
# raise InternalServerError(msg='Error retrieving transfer task')
raise handle_transfer_error(e)
logger.info(f'Successful modify with client {client_id} of task {task_id}')
return utils.ok(
result=result.data,
Expand All @@ -124,7 +127,8 @@ def delete(self, client_id, task_id):
result = transfer_client.cancel_task(task_id)
except Exception as e:
logger.error(f'error while canceling transfer task with id {task_id}: {e}')
raise AuthenticationError(msg='Error retrieving transfer task')
# raise AuthenticationError(msg='Error retrieving transfer task')
raise handle_transfer_error(e)
logger.info(f'Successful delete with client {client_id} of task {task_id}')
return utils.ok(
result=result.data,
Expand Down
4 changes: 2 additions & 2 deletions service/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ class GlobusPathExists(BaseTapisError):
def __init__(self, msg="A directory with given path already exists", code=409):
super().__init__(msg, code)

class CollectionNotFoundError(BaseTapisError):
def __init__(self, msg='Requested endpoint does not exist', code=404):
class EndpointNotFoundError(BaseTapisError):
def __init__(self, msg="Could not find requested endpoint", code=404):
super().__init__(msg, code)
12 changes: 6 additions & 6 deletions service/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ def check_consent_required(client, target):
Checks if an endpoint required consent before operations can be made against it
returns a list of scopes so we can send it through the auth flow again
'''
logger.debug('in check_consent_required')
consent_required_scopes = []
try:
ls_endpoint(client, target)
logger.debug(f'successful ls on ep: {target}')
except globus_sdk.TransferAPIError as e:
if e.info.consent_required:
consent_required_scopes.extend(e.info.consent_required.required_scopes)
Expand Down Expand Up @@ -126,7 +128,6 @@ def get_collection_id(client_id, client_secret, name):

def get_transfer_client(client_id, refresh_token, access_token):
logger.debug(f'Attempting auth for client {client_id} using token')
print(f'Attempting auth for client {client_id} using token')
client = globus_sdk.NativeAppAuthClient(client_id)
# check_token(client_id, refresh_token, access_token)
tomorrow = datetime.today() + timedelta(days=1)
Expand Down Expand Up @@ -199,9 +200,7 @@ def handle_transfer_error(exception, endpoint_id=None, msg=None):
except:
logger.debug(f'exception has no attribute msg.')

logger.critical(f'\nhandling transfer API error:: {exception.code}:: with message {message}\n')
if exception.__cause__:
logger.exception('cause:: ', exception.__cause__)
logger.critical(f'handling transfer API error:: {exception.code}:: with message {message}')
error = InternalServerError(msg='Interal server error', code=500)
if getattr(exception, "code", None) == None:
logger.debug(f'exception {exception} has no code, therefore returning InternalServerError')
Expand All @@ -227,8 +226,9 @@ def handle_transfer_error(exception, endpoint_id=None, msg=None):
error = InternalServerError(msg="Bad Gateway", code=502)
if exception.code == 400:
error = GlobusInvalidRequestError(msg=message)
if error:
logger.error(error)
if exception.code == 404:
error = EndpointNotFoundError(msg=exception.message)
logger.error(error)
return error

def is_endpoint_activated(tc, ep):
Expand Down

0 comments on commit d8b0f59

Please sign in to comment.