diff --git a/.gitignore b/.gitignore index 4fc5eed..e4cc36a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ # Intellij files .idea/* +*config-local* *pycache* -*config-local.json* \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index ea643eb..28279a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/service/api.py b/service/api.py index f8f6239..d86dbd7 100644 --- a/service/api.py +++ b/service/api.py @@ -48,11 +48,11 @@ 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): @@ -60,5 +60,6 @@ def log_after(response): 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 diff --git a/service/controllers/transfers.py b/service/controllers/transfers.py index 52a9172..520198d 100644 --- a/service/controllers/transfers.py +++ b/service/controllers/transfers.py @@ -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 @@ -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') @@ -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)) @@ -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, @@ -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, diff --git a/service/errors.py b/service/errors.py index 66a33b5..ad2416f 100644 --- a/service/errors.py +++ b/service/errors.py @@ -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) diff --git a/service/utils.py b/service/utils.py index 2322dfb..8848fa3 100644 --- a/service/utils.py +++ b/service/utils.py @@ -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) @@ -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) @@ -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') @@ -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):