Load config from DB
This commit is contained in:
1 parent
4530967b6b
commit
819e8a52a3
4 files changed
+203
-65
No files matched your search
+50
-1
@@ -21,11 +21,13 @@
|
||||
const vm = require("vm");
|
||||
const crypto = require("crypto");
|
||||
|
||||
const config = require("./config");
|
||||
const db = require("./db");
|
||||
const cache = require("./cache");
|
||||
const query = require("./query");
|
||||
const logger = require("./logger");
|
||||
const scheduling = require("./scheduling");
|
||||
const expression = require("./common/expression");
|
||||
|
||||
const REFRESH = 3000;
|
||||
const EVICT_TIMEOUT = 60000;
|
||||
@@ -56,6 +58,10 @@ function computeHash(snapshot) {
|
||||
h.update(JSON.stringify(keys));
|
||||
for (const k of keys) h.update(snapshot.virtualParameters[k].md5);
|
||||
|
||||
keys = Object.keys(snapshot.config).sort();
|
||||
h.update(JSON.stringify(keys));
|
||||
for (const k of keys) h.update(JSON.stringify(snapshot.config[k]));
|
||||
|
||||
return h.digest("hex");
|
||||
}
|
||||
|
||||
@@ -296,13 +302,27 @@ function refresh(callback) {
|
||||
})
|
||||
);
|
||||
|
||||
promises.push(
|
||||
new Promise((resolve, reject) => {
|
||||
db.getConfig((err, conf) => {
|
||||
if (err) return void reject(err);
|
||||
|
||||
const _config = {};
|
||||
for (const c of conf) _config[c.id] = c.value;
|
||||
|
||||
resolve(_config);
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
Promise.all(promises)
|
||||
.then(res => {
|
||||
const snapshot = {
|
||||
presets: res[0],
|
||||
provisions: res[1],
|
||||
virtualParameters: res[2],
|
||||
files: res[3]
|
||||
files: res[3],
|
||||
config: res[4]
|
||||
};
|
||||
|
||||
if (currentSnapshot) {
|
||||
@@ -362,9 +382,38 @@ function getFiles(snapshotKey) {
|
||||
return snapshot.files;
|
||||
}
|
||||
|
||||
function getConfig(snapshotKey, key, context, now) {
|
||||
const snapshot = snapshots.get(snapshotKey);
|
||||
if (!snapshot) throw new Error("Cache snapshot does not exist");
|
||||
|
||||
const oldOpts = {
|
||||
"cwmp.downloadTimeout": "DOWNLOAD_TIMEOUT",
|
||||
"cwmp.debug": "DEBUG",
|
||||
"cwmp.retryDelay": "RETRY_DELAY",
|
||||
"cwmp.sessionTimeout": "SESSION_TIMEOUT",
|
||||
"cwmp.connectionRequestTimeout": "CONNECTION_REQUEST_TIMEOUT",
|
||||
"cwmp.gpnNextLevel": "GPN_NEXT_LEVEL",
|
||||
"cwmp.gpvBatchSize": "GPV_BATCH_SIZE",
|
||||
"cwmp.cookiesPath": "COOKIES_PATH",
|
||||
"cwmp.datetimeMilliseconds": "DATETIME_MILLISECONDS",
|
||||
"cwmp.booleanLiteral": "BOOLEAN_LITERAL",
|
||||
"cwmp.connectionRequestAllowBasicAuth":
|
||||
"CONNECTION_REQUEST_ALLOW_BASIC_AUTH",
|
||||
"cwmp.maxCommitIterations": "MAX_COMMIT_ITERATIONS"
|
||||
};
|
||||
|
||||
if (!(key in snapshot.config)) {
|
||||
if (key in oldOpts)
|
||||
return config.get(oldOpts[key], context ? context.id : null);
|
||||
else return null;
|
||||
}
|
||||
return expression.evaluate(snapshot.config[key], context, now || Date.now());
|
||||
}
|
||||
|
||||
exports.getCurrentSnapshot = getCurrentSnapshot;
|
||||
exports.hasSnapshot = hasSnapshot;
|
||||
exports.getPresets = getPresets;
|
||||
exports.getProvisions = getProvisions;
|
||||
exports.getVirtualParameters = getVirtualParameters;
|
||||
exports.getFiles = getFiles;
|
||||
exports.getConfig = getConfig;
|
||||
Reference in new issue
Block a user