From 5f71486b74f7ca9e7df43ceb2e6f4d73f067ff41 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 28 Oct 2022 00:58:59 -0700 Subject: [PATCH] remove unnecessary watchtower header cache, code style --- src/widgets/watchtower/proxy.js | 28 +++++++++------------------- src/widgets/watchtower/widget.js | 2 +- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/widgets/watchtower/proxy.js b/src/widgets/watchtower/proxy.js index 4bb985043..2d54928c6 100644 --- a/src/widgets/watchtower/proxy.js +++ b/src/widgets/watchtower/proxy.js @@ -1,5 +1,3 @@ -import cache from "memory-cache"; - import { httpProxy } from "utils/proxy/http"; import { formatApiCall } from "utils/proxy/api-helpers"; import getServiceWidget from "utils/config/service-helpers"; @@ -7,7 +5,6 @@ import createLogger from "utils/logger"; import widgets from "widgets/widgets"; const proxyName = "watchtowerProxyHandler"; -const headerCacheKey = `${proxyName}__headers`; const logger = createLogger(proxyName); export default async function watchtowerProxyHandler(req, res) { @@ -25,34 +22,27 @@ export default async function watchtowerProxyHandler(req, res) { return res.status(400).json({ error: "Invalid proxy service type" }); } - let headers = cache.get(headerCacheKey); - if (!headers) { - headers = { - "Authorization": `Bearer ${widget.key}`, - } - cache.put(headerCacheKey, headers); - } - const url = new URL(formatApiCall(widgets[widget.type].api, { endpoint, ...widget })); - const method = "GET" const [status, contentType, data] = await httpProxy(url, { - method, - headers, + method: "GET", + headers: { + "Authorization": `Bearer ${widget.key}`, + } }); + if (status !== 200 || !data) { + logger.error("Error getting data from WatchTower: %d. Data: %s", status, data); + } + const cleanData = data.toString().split("\n").filter(s => s.startsWith("watchtower")) - const jsonRes={} + const jsonRes = {} cleanData.map(e => e.split(" ")).forEach(strArray => { const [key, value] = strArray jsonRes[key] = value }) - if (status !== 200) { - logger.error("Error getting data from WatchTower: %d. Data: %s", status, data); - } - if (contentType) res.setHeader("Content-Type", contentType); return res.status(status).send(jsonRes); } diff --git a/src/widgets/watchtower/widget.js b/src/widgets/watchtower/widget.js index 734c90ebe..6e8fdf661 100644 --- a/src/widgets/watchtower/widget.js +++ b/src/widgets/watchtower/widget.js @@ -11,4 +11,4 @@ const widget = { }, }; -export default widget; \ No newline at end of file +export default widget;