Skip to content

Commit

Permalink
logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpricethesecond committed Apr 12, 2024
1 parent 348e615 commit 6742ad2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
12 changes: 12 additions & 0 deletions service/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,15 @@ def __init__(self, url_map, *items):
api.add_resource(ReadyResource, '/v3/globus-proxy/ready')
api.add_resource(HealthcheckResource, '/v3/globus-proxy/healthcheck')
api.add_resource(HelloResource, '/v3/globus-proxy/hello')

@app.before_request
def log_before():
logger.debug(f'Beginning new request:: {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']}')
logger.debug(f'request complete with status:: {response.status}\n')
return response
1 change: 1 addition & 0 deletions service/controllers/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def get(self, client_id, endpoint_id, path):

# mkdir
def do_mkdir(self, transfer_client, endpoint_id, path):
logger.debug(f'In do_mkdir with {endpoint_id}:{path}')
result = transfer_client.operation_mkdir(
endpoint_id=endpoint_id,
path=path
Expand Down
28 changes: 19 additions & 9 deletions service/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ def check_tokens(client_id, refresh_token, access_token):

return access_token, refresh_token

def format_path(path, default_dir=None):
'''
Force absoulte paths for now, due to Globus not ahndling /~/ the same way on all systems
if a user provides a relative path, it will instead be returned as an INCORRECT abs path.
'''
logger.info(f'building path with path {path} and default {default_dir} ')

return f"/{path.rstrip('/').lstrip('/')}"

def get_transfer_client(client_id, refresh_token, access_token):
client = globus_sdk.NativeAppAuthClient(client_id)
# check_token(client_id, refresh_token, access_token)
Expand All @@ -138,9 +147,19 @@ def get_transfer_client(client_id, refresh_token, access_token):
access_token=access_token,
expires_at=expires_at
)
get_token_introspect(client_id, refresh_token)
transfer_client = globus_sdk.TransferClient(authorizer=authorizer)
return transfer_client

def get_token_introspect(client_id, refresh_token):
logger.debug(f'authed {client_id} with ')
CLIENT_ID = '0ffd2a38-27e0-48c5-a870-bcb964237439'
CLIENT_SECRET = '+P3dXBG0BE26dLui8HiLQEj8VH+kcbQ/7GyVJzxsOco='
ac = globus_sdk.ConfidentialAppAuthClient(CLIENT_ID, CLIENT_SECRET)
data = ac.oauth2_token_introspect(refresh_token, include="identity_set")
for identity in data["identity_set"]:
logger.debug(f'token authenticates for "{identity}"')

def get_valid_token(client_id, refresh_token):
'''
Utility function that takes a client id and refresh token
Expand All @@ -155,15 +174,6 @@ def get_valid_token(client_id, refresh_token):
response = client.oauth2_refresh_token(refresh_token)
return response['transfer.api.globus.org']['access_token']

def format_path(path, default_dir=None):
'''
Force absoulte paths for now, due to Globus not ahndling /~/ the same way on all systems
if a user provides a relative path, it will instead be returned as an INCORRECT abs path.
'''
logger.info(f'building path with path {path} and default {default_dir} ')

return f"/{path.rstrip('/').lstrip('/')}"

def handle_transfer_error(exception, endpoint_id=None, msg=None):
'''Tanslates transfer api errors into the configured basetapiserrors in ./errors.py'''
logger.critical(f'\nhandling transfer API error:: {exception.code}:: with message {exception.message}\n')
Expand Down

0 comments on commit 6742ad2

Please sign in to comment.