Skip to content

Commit

Permalink
Merge pull request #10 from srikumarks/master
Browse files Browse the repository at this point in the history
Minor changes
  • Loading branch information
srikumarks committed Feb 22, 2021
2 parents 7e19983 + 1d8bc00 commit 7dbcda2
Show file tree
Hide file tree
Showing 3 changed files with 830 additions and 1,172 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
"mysql2": "^2.1.0",
"node-fetch": "^2.6.1",
"nodemailer": "^6.4.5",
"pg": "^7.17.0",
"pg": "8.5.1",
"pg-hstore": "^2.3.3",
"postcss": "^8.2.4",
"postcss-cli": "^8.3.1",
"redis": "^2.8.0",
"sass": "^1.26.5",
"sequelize": "5.21.5",
"sequelize": "6.3.5",
"showdown": "^1.9.1",
"sqlite3": "^4.1.1",
"swagger-ui": "^3.40.0",
Expand Down
54 changes: 18 additions & 36 deletions services/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,19 @@ I.boot = async function (name, resid, query, headers, config) {
I.user_cache_period_ms = 2 * 60 * 1000; // 2 minutes;
I.group_cache_period_ms = 15 * 60 * 1000; // 2 minutes;

await Promise.all(
[
"token_expiry_ms",
"earliest_renew_time_ms",
"user_cache_period_ms",
"group_cache_period_ms",
].map(loadConfig)
const kConfigurables = [
"token_expiry_ms",
"earlist_renew_time_ms",
"user_cache_period_ms",
"group_cache_period_ms",
];

const kConfigurableResID = new RegExp(
"^[/]?_config[/](" + kConfigurables.join("|") + ")$"
);

await Promise.all(kConfigurables.map(loadConfig));

async function loadConfig(name) {
let result = await I.network(
userdb,
Expand Down Expand Up @@ -242,35 +246,13 @@ I.boot = async function (name, resid, query, headers, config) {
};

I.put = async function (name, resid, query, headers, body) {
if (/^[/]?_config[/]token_expiry_ms$/.test(resid)) {
I.token_expiry_ms = +body;
console.log("auth[config] token_expiry_ms=" + I.token_expiry_ms);
await saveConfig("token_expiry_ms");
return { status: 200 };
}
if (/^[/]?_config[/]earliest_renew_time_ms$/.test(resid)) {
I.earliest_renew_time_ms = +body;
console.log(
"auth[config] earliest_renew_time_ms=" +
I.earliest_renew_time_ms
);
await saveConfig("earliest_renew_time_ms");
return { status: 200 };
}
if (/^[/]?_config[/]user_cache_period_ms$/.test(resid)) {
I.user_cache_period_ms = +body;
console.log(
"auth[config] user_cache_period_ms=" + I.user_cache_period_ms
);
await saveConfig("user_cache_period_ms");
return { status: 200 };
}
if (/^[/]?_config[/]group_cache_period_ms$/.test(resid)) {
I.group_cache_period_ms = +body;
console.log(
"auth[config] group_cache_period_ms=" + I.group_cache_period_ms
);
await saveConfig("group_cache_period_ms");
// Support configuration setting via the /_config/ resource root.
// If a field was specified that isn't configurable, reject it
// with an error.
if (kConfigurableRESID.test(resid)) {
I[key] = +body;
console.log("auth[config] " + key + " = " + I[key]);
await saveConfig(key);
return { status: 200 };
}
return { status: 404, body: "auth: No such config - " + resid };
Expand Down
Loading

0 comments on commit 7dbcda2

Please sign in to comment.