Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support new env variable for blocking public access #20

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/api/disabled.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const db = require("../db");
const { getDisabledServerReason } = require("../utils");

// returns a disabled flag status
module.exports = (req, res) => {
const disabled = db.get("disabled").value();
const manualDisabledReason = db.get("disabled").value();

res.send({ disabled });
res.send({ disabled: getDisabledServerReason(manualDisabledReason) });
};
5 changes: 4 additions & 1 deletion src/api/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { StatusCodes } = require("http-status-codes");
const { sum, sumBy } = require("lodash");
const db = require("../db");
const { getDisabledServerReason } = require("../utils");

/**
* Get status code that should be returned in the API response.
Expand Down Expand Up @@ -54,7 +55,9 @@ function getMostRecentCriticalEntry() {
* Get the disabled flag state (manual portal disable)
*/
function getDisabled() {
return db.get("disabled").value();
const manualDisabledReason = db.get("disabled").value();

return getDisabledServerReason(manualDisabledReason);
}

module.exports = (req, res) => {
Expand Down
18 changes: 18 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,31 @@ function isPortalModuleEnabled(module) {
return process.env.PORTAL_MODULES && process.env.PORTAL_MODULES.indexOf(module) !== -1;
}

/**
* Compute and generate a message indicating a disabled server. Server is disabled when either:
* - disable reason is set manually (non empty)
* - DENY_PUBLIC_ACCESS env variable is set to true (server on takedown)
*/
function getDisabledServerReason(manualDisabledReason) {
// check if a flag that indicates that server should disable public traffic is enabled
if (process.env.DENY_PUBLIC_ACCESS === "true") {
const accessDeniedReason = "Server public access denied"; // generic reason message

// include manual disable reason if server has been manually disabled
return manualDisabledReason ? `${manualDisabledReason} & ${accessDeniedReason}` : accessDeniedReason;
}

return manualDisabledReason;
}

module.exports = {
calculateElapsedTime,
getYesterdayISOString,
getResponseContent,
ensureValidJSON,
getAuthCookie,
isPortalModuleEnabled,
getDisabledServerReason,
ipCheckService,
ipRegex,
};