Skip to content

Commit

Permalink
allow disabling of metrics endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Travis Glenn Hansen <[email protected]>
  • Loading branch information
travisghansen committed Jun 16, 2023
1 parent 10c5acc commit e7a49ed
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
23 changes: 13 additions & 10 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
29 changes: 29 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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-_.+/=]*$/
Expand Down Expand Up @@ -506,6 +534,7 @@ module.exports = {
base64_decode,
generate_session_id,
generate_csrf_id,
toBoolean,
is_json_like,
is_yaml_like,
is_jwt,
Expand Down

0 comments on commit e7a49ed

Please sign in to comment.