mirror of https://gitee.com/bigwinds/arangodb
Now allows to configure an App during runtime and get its configuration options. Configure will trigger reload routing.
This commit is contained in:
parent
802167cea7
commit
c9b92ecf23
|
@ -391,6 +391,17 @@ function updateApp (mount, update) {
|
||||||
return tmp_getStorage().updateByExample({mount: mount}, update);
|
return tmp_getStorage().updateByExample({mount: mount}, update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief define regex for parameter types
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
var typeToRegex = {
|
||||||
|
"int": /[0-9]+/,
|
||||||
|
"integer": /[0-9]+/,
|
||||||
|
"boolean": /(true)|(false)/,
|
||||||
|
"bool": /(true)|(false)/,
|
||||||
|
"string": /[\w\W]*/
|
||||||
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief Exports
|
/// @brief Exports
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -406,6 +417,7 @@ exports.repackZipFile = repackZipFile;
|
||||||
exports.processDirectory = processDirectory;
|
exports.processDirectory = processDirectory;
|
||||||
exports.processGithubRepository = processGithubRepository;
|
exports.processGithubRepository = processGithubRepository;
|
||||||
exports.validateAppName = validateAppName;
|
exports.validateAppName = validateAppName;
|
||||||
|
exports.typeToRegex = typeToRegex;
|
||||||
|
|
||||||
exports.tmp_getStorage = tmp_getStorage;
|
exports.tmp_getStorage = tmp_getStorage;
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,8 @@
|
||||||
var internal = require("internal");
|
var internal = require("internal");
|
||||||
var db = internal.db;
|
var db = internal.db;
|
||||||
var _= require("underscore");
|
var _= require("underscore");
|
||||||
|
var utils = require("org/arangodb/foxx/manager-utils");
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- constructors and destructors
|
// --SECTION-- constructors and destructors
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -187,6 +189,56 @@ var ArangoApp = function (config) {
|
||||||
return this._appContext;
|
return this._appContext;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief set app configuration
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ArangoApp.prototype.configure = function(config) {
|
||||||
|
var expected = this._manifest.configuration;
|
||||||
|
var attr;
|
||||||
|
var type;
|
||||||
|
var invalid = [];
|
||||||
|
this._options.configuration = this._options.configuration || {};
|
||||||
|
for (attr in config) {
|
||||||
|
if (config.hasOwnProperty(attr)) {
|
||||||
|
if (!expected.hasOwnProperty(attr)) {
|
||||||
|
invalid.push("Unexpected Attribute " + attr);
|
||||||
|
} else {
|
||||||
|
type = expected[attr].type;
|
||||||
|
if (!(utils.typeToRegex[type]).test(config[attr])) {
|
||||||
|
invalid.push("Attribute " + attr + " has wrong type, expected: " + type);
|
||||||
|
} else {
|
||||||
|
this._options.configuration[attr] = config[attr];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return invalid;
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief get app configuration
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ArangoApp.prototype.getConfiguration = function() {
|
||||||
|
if (!this._manifest.hasOwnProperty("configuration")) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
// Make sure originial is unmodified
|
||||||
|
var config = JSON.parse(JSON.stringify(this._manifest.configuration));
|
||||||
|
var setting = this._options.configuration || {};
|
||||||
|
var attr;
|
||||||
|
for (attr in config) {
|
||||||
|
if (config.hasOwnProperty(attr)) {
|
||||||
|
if (setting.hasOwnProperty(attr)) {
|
||||||
|
config[attr].current = setting[attr];
|
||||||
|
} else if (config[attr].hasOwnProperty("default")) {
|
||||||
|
config[attr].current = config[attr].default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief loadAppScript
|
/// @brief loadAppScript
|
||||||
|
|
|
@ -1274,6 +1274,7 @@ exports.initializeFoxx = function () {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
var lookupApp = function(mount) {
|
var lookupApp = function(mount) {
|
||||||
|
require("console").log(Object.keys(appCache));
|
||||||
if (!appCache.hasOwnProperty(mount)) {
|
if (!appCache.hasOwnProperty(mount)) {
|
||||||
throw "App not found";
|
throw "App not found";
|
||||||
}
|
}
|
||||||
|
@ -1784,8 +1785,6 @@ exports.initializeFoxx = function () {
|
||||||
executeGlobalContextFunction("reloadRouting");
|
executeGlobalContextFunction("reloadRouting");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief Internal install function. Check install.
|
/// @brief Internal install function. Check install.
|
||||||
/// Does not check parameters and throws errors.
|
/// Does not check parameters and throws errors.
|
||||||
|
@ -1949,6 +1948,29 @@ exports.initializeFoxx = function () {
|
||||||
_toggleDevelopment(mount, false);
|
_toggleDevelopment(mount, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var configure = function(mount, options) {
|
||||||
|
checkParameter(
|
||||||
|
"mount(<mount>)",
|
||||||
|
[ [ "Mount path", "string" ] ],
|
||||||
|
[ mount ] );
|
||||||
|
var app = lookupApp(mount);
|
||||||
|
var invalid = app.configure(options);
|
||||||
|
if (invalid.length > 0) {
|
||||||
|
require("console").log(invalid);
|
||||||
|
}
|
||||||
|
utils.updateApp(mount, app.toJSON());
|
||||||
|
executeGlobalContextFunction("reloadRouting");
|
||||||
|
};
|
||||||
|
|
||||||
|
var configuration = function(mount) {
|
||||||
|
checkParameter(
|
||||||
|
"mount(<mount>)",
|
||||||
|
[ [ "Mount path", "string" ] ],
|
||||||
|
[ mount ] );
|
||||||
|
var app = lookupApp(mount);
|
||||||
|
return app.getConfiguration();
|
||||||
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- exports
|
// --SECTION-- exports
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -1967,6 +1989,8 @@ exports.initializeFoxx = function () {
|
||||||
exports.appRoutes = appRoutes;
|
exports.appRoutes = appRoutes;
|
||||||
exports.development = setDevelopment;
|
exports.development = setDevelopment;
|
||||||
exports.production = setProduction;
|
exports.production = setProduction;
|
||||||
|
exports.configure = configure;
|
||||||
|
exports.configuration = configuration;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief Exports from foxx utils module.
|
/// @brief Exports from foxx utils module.
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||||
///
|
///
|
||||||
/// @author Lucas Dohmen
|
/// @author Lucas Dohmen
|
||||||
|
/// @author Michael Hackstein
|
||||||
/// @author Copyright 2013, triAGENS GmbH, Cologne, Germany
|
/// @author Copyright 2013, triAGENS GmbH, Cologne, Germany
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue