From 99b70f96e438e37c629e95cb1b37f3ce2d06b665 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue, 11 Oct 2022 08:40:15 -0700 Subject: [PATCH] Allow username + password for glances --- src/pages/api/widgets/glances.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/pages/api/widgets/glances.js b/src/pages/api/widgets/glances.js index d8cc04b7a..bf00862b2 100644 --- a/src/pages/api/widgets/glances.js +++ b/src/pages/api/widgets/glances.js @@ -18,14 +18,22 @@ export default async function handler(req, res) { } const apiUrl = `${url}/api/3/quicklook`; - const params = { method: "GET", headers: { + const headers = { "Accept-Encoding": "application/json" - } }; + }; + if (settings.username && settings.password) { + headers.Authorization = `Basic ${Buffer.from(`${settings.username}:${settings.password}`).toString("base64")}` + } + const params = { method: "GET", headers }; const [status, contentType, data] = await httpProxy(apiUrl, params); + if (status === 401) { + logger.error("Authorization failure getting data from glances API. Data: %s", data); + } + if (status !== 200) { - logger.error("HTTP %d getting data from glances API %s. Data: %s", status, apiUrl, data); + logger.error("HTTP %d getting data from glances API. Data: %s", status, data); } if (contentType) res.setHeader("Content-Type", contentType);