Allow username + password for glances

pull/369/head
Michael Shamoon 2 years ago
parent 802fe0f721
commit 99b70f96e4

@ -18,14 +18,22 @@ export default async function handler(req, res) {
} }
const apiUrl = `${url}/api/3/quicklook`; const apiUrl = `${url}/api/3/quicklook`;
const params = { method: "GET", headers: { const headers = {
"Accept-Encoding": "application/json" "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); 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) { 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); if (contentType) res.setHeader("Content-Type", contentType);

Loading…
Cancel
Save