From e7a49ed76af9df37139fb429930d264f65c8a49a Mon Sep 17 00:00:00 2001 From: Travis Glenn Hansen Date: Fri, 16 Jun 2023 07:10:32 -0600 Subject: [PATCH] allow disabling of metrics endpoint Signed-off-by: Travis Glenn Hansen --- CHANGELOG.md | 6 ++++++ src/server.js | 23 +++++++++++++---------- src/utils.js | 29 +++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37b9bf8..7c31177 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.13.1 + +Released 2023-06-16 + +- allow disabling of the metrices endpoint with env var `EAS_DISABLE_METRICS` + # 0.13.0 Released 2023-01-22 diff --git a/src/server.js b/src/server.js index e44b4ef..ee5b43f 100644 --- a/src/server.js +++ b/src/server.js @@ -44,17 +44,20 @@ const configTokenStoreManager = new ConfigTokenStoreManager(externalAuthServer); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser(externalAuthServer.secrets.cookie_sign_secret)); -app.use( - promBundle({ - includeMethod: true, - includePath: true, - promClient: { - collectDefaultMetrics: { - timeout: 2000, + +if (!externalAuthServer.utils.toBoolean(process.env.EAS_DISABLE_METRICS)) { + app.use( + promBundle({ + includeMethod: true, + includePath: true, + promClient: { + collectDefaultMetrics: { + timeout: 2000, + }, }, - }, - }) -); + }) + ); +} let revokedJtis = process.env["EAS_REVOKED_JTIS"]; if (revokedJtis) { diff --git a/src/utils.js b/src/utils.js index c047c5c..efae428 100644 --- a/src/utils.js +++ b/src/utils.js @@ -123,6 +123,34 @@ function generate_csrf_id() { return uuidv4(); } +function toBoolean(input) { + //return !!(dataStr?.toLowerCase?.() === 'true' || dataStr === true || Number.parseInt(dataStr, 10) === 0); + //return !!(dataStr?.toLowerCase?.() === 'true' || dataStr === true); + if (typeof input == "boolean") { + return input; + } + + if (!isNaN(input)) { + if (typeof input == "string") { + input = parseFloat(input); + } + return Boolean(input); + } + + if (typeof input == "string") { + switch (input.toLocaleLowerCase()) { + case "true": + return true; + case "false": + return false; + default: + return Boolean(input); + } + } + + throw new Error("unable to determine boolean value"); +} + function is_jwt(jwtString) { const re = new RegExp( /^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/ @@ -506,6 +534,7 @@ module.exports = { base64_decode, generate_session_id, generate_csrf_id, + toBoolean, is_json_like, is_yaml_like, is_jwt,