From fca841f4b82a0e2376296258e92b553e31a16bed Mon Sep 17 00:00:00 2001 From: Punam Verma Date: Fri, 8 Dec 2023 08:07:27 -0800 Subject: [PATCH] Adding missing code for Query --- monitoring/monitorlib/fetch/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/monitoring/monitorlib/fetch/__init__.py b/monitoring/monitorlib/fetch/__init__.py index 404fe1ed4b..340ad38347 100644 --- a/monitoring/monitorlib/fetch/__init__.py +++ b/monitoring/monitorlib/fetch/__init__.py @@ -3,6 +3,7 @@ import os import traceback import uuid +import jwt from typing import Dict, Optional, List, Union from enum import Enum @@ -290,6 +291,15 @@ def error_message(self) -> Optional[str]: else None ) + def get_client_sub(self): + headers = self.request.headers + if "Authorization" in headers: + token = headers.get("Authorization").split(" ")[1] + payload = jwt.decode( + token, algorithms="RS256", options={"verify_signature": False} + ) + return payload["sub"] + class QueryError(RuntimeError): """Error encountered when interacting with a server in the UTM ecosystem."""