From 34a7b25c9ccc20579e12460197517423d7d85531 Mon Sep 17 00:00:00 2001 From: John Hollowell Date: Sat, 7 Jan 2023 02:00:44 +0000 Subject: [PATCH 1/2] Add truenas key to credentialed proxy handler Revert "Change TrueNAS to use API key" This reverts commit 1926c26b77d8e048d92da6e20ff24a3056237daf. Co-Authored-By: John Hollowell --- src/utils/proxy/handlers/credentialed.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/proxy/handlers/credentialed.js b/src/utils/proxy/handlers/credentialed.js index 5d34264df..10ca2b9c3 100644 --- a/src/utils/proxy/handlers/credentialed.js +++ b/src/utils/proxy/handlers/credentialed.js @@ -30,6 +30,8 @@ export default async function credentialedProxyHandler(req, res, map) { headers["X-gotify-Key"] = `${widget.key}`; } else if (widget.type === "authentik") { headers.Authorization = `Bearer ${widget.key}`; + } else if (widget.type === "truenas") { + headers.Authorization = `Bearer ${widget.key}`; } else if (widget.type === "proxmox") { headers.Authorization = `PVEAPIToken=${widget.username}=${widget.password}`; } else if (widget.type === "autobrr") { From 730f1c5ec10bacb28b47fa6b137ff1557e76b46e Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 7 Jan 2023 10:00:25 -0800 Subject: [PATCH 2/2] Support api key + username / pass for truenas widget --- src/widgets/truenas/widget.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/widgets/truenas/widget.js b/src/widgets/truenas/widget.js index 4c479e9f3..3139019bc 100644 --- a/src/widgets/truenas/widget.js +++ b/src/widgets/truenas/widget.js @@ -1,9 +1,31 @@ import { jsonArrayFilter } from "utils/proxy/api-helpers"; +import credentialedProxyHandler from "utils/proxy/handlers/credentialed"; import genericProxyHandler from "utils/proxy/handlers/generic"; +import getServiceWidget from "utils/config/service-helpers"; const widget = { api: "{url}/api/v2.0/{endpoint}", - proxyHandler: genericProxyHandler, + proxyHandler: async (req, res, map) => { // choose proxy handler based on widget settings + const { group, service } = req.query; + + if (group && service) { + const widgetOpts = await getServiceWidget(group, service); + let handler; + if (widgetOpts.username && widgetOpts.password) { + handler = genericProxyHandler; + } else if (widgetOpts.key) { + handler = credentialedProxyHandler; + } + + if (handler) { + return handler(req, res, map); + } + + return res.status(500).json({ error: "Username / password or API key required" }); + } + + return res.status(500).json({ error: "Error parsing widget request" }); + }, mappings: { alerts: {