From 174b5c6201c756b6ac8571792352d66104f712d0 Mon Sep 17 00:00:00 2001 From: zachmandeville Date: Tue, 19 Sep 2023 09:19:22 +1200 Subject: [PATCH] use swagger_url if token is unreadable Signed-off-by: zachmandeville --- apps/snoopdb/postgres/snoopUtils.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/snoopdb/postgres/snoopUtils.py b/apps/snoopdb/postgres/snoopUtils.py index fcb4839a..886e83da 100644 --- a/apps/snoopdb/postgres/snoopUtils.py +++ b/apps/snoopdb/postgres/snoopUtils.py @@ -116,9 +116,14 @@ def cluster_swagger(): elif os.path.isfile(tokenfile) and os.access(tokenfile, os.R_OK): token = Path(tokenfile).read_text() else: - raise "/token.txt or serviceaccount/token required" - auth = {"Authorization": "Bearer " + token} - return requests.get(url, headers=auth, verify=False).json() + token = None + + if token is None: + swagger_url = "https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json" + return requests.get(swagger_url).json() + else: + auth = {"Authorization": "Bearer " + token} + return requests.get(url, headers=auth, verify=False).json() def load_openapi_spec(url): """