Skip to content

Commit

Permalink
Merge pull request uc-cdis#1130 from uc-cdis/chore/logs
Browse files Browse the repository at this point in the history
chore(logs): improve signed URL data metrics log by adding client_id …
  • Loading branch information
Avantol13 authored Jan 19, 2024
2 parents b1bdd6a + b700937 commit a2c0639
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions fence/blueprints/data/indexd.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def get_signed_url_for_file(
r_pays_project = flask.request.args.get("userProject", None)
db_session = db_session or current_app.scoped_session()

# default to signing the url
# default to signing the URL
force_signed_url = True
no_force_sign_param = flask.request.args.get("no_force_sign")
if no_force_sign_param and no_force_sign_param.lower() == "true":
Expand Down Expand Up @@ -162,13 +162,14 @@ def get_signed_url_for_file(
_log_signed_url_data_info(
indexed_file=indexed_file,
user_sub=flask.g.audit_data.get("sub", ""),
client_id=_get_client_id(),
requested_protocol=requested_protocol,
)

return {"url": signed_url}


def _log_signed_url_data_info(indexed_file, user_sub, requested_protocol):
def _log_signed_url_data_info(indexed_file, user_sub, client_id, requested_protocol):
size_in_kibibytes = (indexed_file.index_document.get("size") or 0) / 1024
acl = indexed_file.index_document.get("acl")
authz = indexed_file.index_document.get("authz")
Expand All @@ -192,10 +193,21 @@ def _log_signed_url_data_info(indexed_file, user_sub, requested_protocol):
break

logger.info(
f"Signed URL Generated. size_in_kibibytes={size_in_kibibytes} acl={acl} authz={authz} bucket={bucket} user_sub={user_sub}"
f"Signed URL Generated. size_in_kibibytes={size_in_kibibytes} "
f"acl={acl} authz={authz} bucket={bucket} user_sub={user_sub} client_id={client_id}"
)


def _get_client_id():
client_id = "Unknown Client"

try:
client_id = current_token.get("azp") or "Unknown Client"
except Exception as exc:
pass

return client_id

def prepare_presigned_url_audit_log(protocol, indexed_file):
"""
Store in `flask.g.audit_data` the data needed to record an audit log.
Expand Down Expand Up @@ -423,7 +435,7 @@ class IndexedFile(object):
also be cleaner).
Args:
file_id (str): GUID for the file.
file_id (str): GUID for the file
"""

def __init__(self, file_id):
Expand Down

0 comments on commit a2c0639

Please sign in to comment.