mirror of https://github.com/node-red/node-red.git
Merge pull request #5276 from GogoVega/fix-plugins-getConfig
Handle plugin name in `plugins.getConfig`pull/5366/head
commit
8cf1e73a02
|
|
@ -91,6 +91,7 @@ module.exports = {
|
|||
// Plugins
|
||||
adminApp.get("/plugins", needsPermission("plugins.read"), plugins.getAll, apiUtil.errorHandler);
|
||||
adminApp.get("/plugins/messages", needsPermission("plugins.read"), plugins.getCatalogs, apiUtil.errorHandler);
|
||||
adminApp.get(/^\/plugins\/((@[^\/]+\/)?[^\/]+)$/,needsPermission("plugins.read"),plugins.getModule,apiUtil.errorHandler);
|
||||
adminApp.get(/^\/plugins\/((@[^\/]+\/)?[^\/]+)\/([^\/]+)$/,needsPermission("plugins.read"),plugins.getConfig,apiUtil.errorHandler);
|
||||
|
||||
adminApp.get("/diagnostics", needsPermission("diagnostics.read"), diagnostics.getReport, apiUtil.errorHandler);
|
||||
|
|
|
|||
|
|
@ -41,16 +41,28 @@ module.exports = {
|
|||
apiUtils.rejectHandler(req,res,err);
|
||||
})
|
||||
},
|
||||
getConfig: function(req, res) {
|
||||
|
||||
getModule: function(req, res) {
|
||||
let opts = {
|
||||
user: req.user,
|
||||
module: req.params[0],
|
||||
req: apiUtils.getRequestLogObject(req)
|
||||
}
|
||||
runtimeAPI.nodes.getModuleInfo(opts).then(function(result) {
|
||||
res.send(result);
|
||||
}).catch(function(err) {
|
||||
apiUtils.rejectHandler(req,res,err);
|
||||
})
|
||||
},
|
||||
getConfig: function(req, res) {
|
||||
|
||||
let opts = {
|
||||
user: req.user,
|
||||
id: req.params[0] + "/" + req.params[2],
|
||||
req: apiUtils.getRequestLogObject(req)
|
||||
}
|
||||
|
||||
if (req.get("accept") === "application/json") {
|
||||
runtimeAPI.nodes.getNodeInfo(opts.module).then(function(result) {
|
||||
runtimeAPI.plugins.getPluginInfo(opts).then(function(result) {
|
||||
res.send(result);
|
||||
}).catch(function(err) {
|
||||
apiUtils.rejectHandler(req,res,err);
|
||||
|
|
|
|||
|
|
@ -316,6 +316,7 @@ module.exports = {
|
|||
|
||||
registerPlugin: plugins.registerPlugin,
|
||||
getPlugin: plugins.getPlugin,
|
||||
getPluginInfo: plugins.getPluginInfo,
|
||||
getPluginsByType: plugins.getPluginsByType,
|
||||
getPluginList: plugins.getPluginList,
|
||||
getPluginConfigs: plugins.getPluginConfigs,
|
||||
|
|
|
|||
|
|
@ -77,8 +77,14 @@ function getPluginConfigs(lang) {
|
|||
function getPluginConfig(id, lang) {
|
||||
let result = '';
|
||||
let moduleConfigs = registry.getModuleList();
|
||||
if (moduleConfigs.hasOwnProperty(id)) {
|
||||
result = generateModulePluginConfig(moduleConfigs[id]);
|
||||
const module = registry.getModuleFromSetId(id);
|
||||
if (moduleConfigs.hasOwnProperty(module)) {
|
||||
const name = registry.getNodeFromSetId(id);
|
||||
const config = moduleConfigs[module].plugins[name];
|
||||
if (config && config.enabled && !config.err && config.config) {
|
||||
result += "\n<!-- --- [red-plugin:" + config.id + "] --- -->\n";
|
||||
result += config.config;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -98,6 +104,34 @@ function generateModulePluginConfig(module) {
|
|||
return result;
|
||||
}
|
||||
|
||||
function getPluginInfo(typeOrId) {
|
||||
let id = typeOrId;
|
||||
if (pluginToId.hasOwnProperty(typeOrId)) {
|
||||
id = pluginToId[typeOrId];
|
||||
}
|
||||
|
||||
if (id) {
|
||||
const moduleConfigs = registry.getModuleList();
|
||||
const module = moduleConfigs[registry.getModuleFromSetId(id)];
|
||||
if (module) {
|
||||
const config = module.plugins[registry.getNodeFromSetId(id)];
|
||||
if (config) {
|
||||
const info = registry.filterNodeInfo(config);
|
||||
if (config.hasOwnProperty("loaded")) {
|
||||
info.loaded = config.loaded;
|
||||
}
|
||||
if (module.pending_version) {
|
||||
info.pending_version = module.pending_version;
|
||||
}
|
||||
|
||||
info.version = module.version;
|
||||
return info;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function getPluginList() {
|
||||
var list = [];
|
||||
var moduleConfigs = registry.getModuleList();
|
||||
|
|
@ -203,6 +237,7 @@ module.exports = {
|
|||
init,
|
||||
registerPlugin,
|
||||
getPlugin,
|
||||
getPluginInfo,
|
||||
getPluginsByType,
|
||||
getPluginConfigs,
|
||||
getPluginConfig,
|
||||
|
|
|
|||
|
|
@ -22,6 +22,31 @@ var api = module.exports = {
|
|||
return runtime.plugins.getPlugin(opts.id);
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the info of an individual plugin set
|
||||
* @param {Object} opts
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.id - the id of the plugin set to return
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<PluginInfo>} - the plugin information
|
||||
* @memberof @node-red/runtime_plugins
|
||||
*/
|
||||
getPluginInfo: async function(opts) {
|
||||
const id = opts.id;
|
||||
const result = runtime.plugins.getPluginInfo(id);
|
||||
if (result) {
|
||||
runtime.log.audit({ event: "plugins.info.get", id: id }, opts.req);
|
||||
delete result.loaded;
|
||||
return result;
|
||||
} else {
|
||||
runtime.log.audit({ event: "plugins.info.get", id: id, error: "not_found" }, opts.req);
|
||||
var err = new Error("Plugin not found");
|
||||
err.code = "not_found";
|
||||
err.status = 404;
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets all plugin definitions of a given type
|
||||
* @param {Object} opts
|
||||
|
|
@ -67,12 +92,12 @@ var api = module.exports = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Gets the editor content for one registered plugin
|
||||
* Gets an individual plugin's html content
|
||||
* @param {Object} opts
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<NodeInfo>} - the plugin information
|
||||
* @return {Promise<string>} - the plugin html content
|
||||
* @memberof @node-red/runtime_plugins
|
||||
*/
|
||||
getPluginConfig: async function(opts) {
|
||||
|
|
@ -81,7 +106,7 @@ var api = module.exports = {
|
|||
return;
|
||||
}
|
||||
runtime.log.audit({event: "plugins.configs.get"}, opts.req);
|
||||
return runtime.plugins.getPluginConfig(opts.module, opts.lang);
|
||||
return runtime.plugins.getPluginConfig(opts.id, opts.lang);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ module.exports = {
|
|||
init: function() {},
|
||||
registerPlugin: registry.registerPlugin,
|
||||
getPlugin: registry.getPlugin,
|
||||
getPluginInfo: registry.getPluginInfo,
|
||||
getPluginsByType: registry.getPluginsByType,
|
||||
getPluginList: registry.getPluginList,
|
||||
getPluginConfigs: registry.getPluginConfigs,
|
||||
|
|
|
|||
Loading…
Reference in New Issue