From 78490c669b390fcc1a185dcd0f6dd2cc0f116d34 Mon Sep 17 00:00:00 2001 From: Sal Tijerina Date: Mon, 18 Nov 2024 14:57:52 -0600 Subject: [PATCH] include tracking id in audit logs --- designsafe/apps/workspace/api/views.py | 27 ++++++++++++++++++++++---- designsafe/settings/common_settings.py | 4 ++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/designsafe/apps/workspace/api/views.py b/designsafe/apps/workspace/api/views.py index f8e38339c3..94693f4aad 100644 --- a/designsafe/apps/workspace/api/views.py +++ b/designsafe/apps/workspace/api/views.py @@ -561,7 +561,10 @@ def select(self, client, request): """Returns detailed information for a given job uuid""" job_uuid = request.GET.get("uuid") - data = client.jobs.getJob(jobUuid=job_uuid) + data = client.jobs.getJob( + jobUuid=job_uuid, + headers={"X-Tapis-Tracking-ID": f"portals.{request.session.session_key}"}, + ) return data @@ -584,6 +587,7 @@ def listing(self, client, request): skip=skip, orderBy="lastUpdated(desc),name(asc)", select="allAttributes", + headers={"X-Tapis-Tracking-ID": f"portals.{request.session.session_key}"}, **kwargs, ) if isinstance(data, list): @@ -626,6 +630,7 @@ def search(self, client, request): orderBy="lastUpdated(desc),name(asc)", request_body={"search": sql_queries}, select="allAttributes", + headers={"X-Tapis-Tracking-ID": f"portals.{request.session.session_key}"}, ) return {"listing": data, "reachedEnd": len(data) < int(limit)} @@ -645,7 +650,10 @@ def delete(self, request, *args, **kwargs): ) tapis = request.user.tapis_oauth.client job_uuid = request.GET.get("uuid") - data = tapis.jobs.hideJob(jobUuid=job_uuid) + data = tapis.jobs.hideJob( + jobUuid=job_uuid, + headers={"X-Tapis-Tracking-ID": f"portals.{request.session.session_key}"}, + ) return JsonResponse( { "status": 200, @@ -755,6 +763,9 @@ def _submit_job(self, request, body, tapis, username): tapis.files.mkdir( systemId=exec_system_id, path=f"{system['home_dir'].format(tasdir)}/.tap", + headers={ + "X-Tapis-Tracking-ID": f"portals.{request.session.session_key}" + }, ) # Add webhook subscription for job status updates @@ -771,7 +782,10 @@ def _submit_job(self, request, body, tapis, username): ] logger.info(f"user: {username} is submitting job: {job_post}") - response = tapis.jobs.submitJob(**job_post) + response = tapis.jobs.submitJob( + **job_post, + headers={"X-Tapis-Tracking-ID": f"portals.{request.session.session_key}"}, + ) return response def post(self, request, *args, **kwargs): @@ -797,7 +811,12 @@ def post(self, request, *args, **kwargs): status=400, ) tapis_operation = getattr(tapis.jobs, operation) - response = tapis_operation(jobUuid=job_uuid) + response = tapis_operation( + jobUuid=job_uuid, + headers={ + "X-Tapis-Tracking-ID": f"portals.{request.session.session_key}" + }, + ) else: # submit job diff --git a/designsafe/settings/common_settings.py b/designsafe/settings/common_settings.py index 94c5eae3b4..dae86ed1e9 100644 --- a/designsafe/settings/common_settings.py +++ b/designsafe/settings/common_settings.py @@ -427,7 +427,7 @@ 'metrics': { 'format': '[METRICS] %(levelname)s %(module)s %(name)s.%(funcName)s:%(lineno)s:' ' %(message)s user=%(user)s ip=%(ip)s agent=%(agent)s sessionId=%(sessionId)s op=%(operation)s' - ' info=%(info)s timestamp=%(asctime)s portal=designsafe tenant=designsafe' + ' info=%(info)s timestamp=%(asctime)s trackingId=portal.%(sessionId)s portal=designsafe tenant=designsafe' }, }, 'handlers': { @@ -508,7 +508,7 @@ ALLOCATIONS_TO_EXCLUDE = ( os.environ.get("ALLOCATIONS_TO_EXCLUDE", "").split(",") if os.environ.get("ALLOCATIONS_TO_EXCLUDE") - else ["DesignSafe-DCV"] + else ["DesignSafe-DCV,DesignSafe-Corral"] )