mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add req back to audit log events and extend to Projects api
This commit is contained in:
@@ -32,13 +32,14 @@ var api = module.exports = {
|
||||
* @param {String} opts.library - the library
|
||||
* @param {String} opts.type - the type of entry
|
||||
* @param {String} opts.path - the path of the entry
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<String|Object>} - resolves when complete
|
||||
* @memberof @node-red/runtime_library
|
||||
*/
|
||||
getEntry: function(opts) {
|
||||
return new Promise(function(resolve,reject) {
|
||||
runtime.library.getEntry(opts.library,opts.type,opts.path).then(function(result) {
|
||||
runtime.log.audit({event: "library.get",library:opts.library,type:opts.type,path:opts.path});
|
||||
runtime.log.audit({event: "library.get",library:opts.library,type:opts.type,path:opts.path}, opts.req);
|
||||
return resolve(result);
|
||||
}).catch(function(err) {
|
||||
if (err) {
|
||||
@@ -51,10 +52,10 @@ var api = module.exports = {
|
||||
} else {
|
||||
err.status = 400;
|
||||
}
|
||||
runtime.log.audit({event: "library.get",library:opts.library,type:opts.type,path:opts.path,error:err.code});
|
||||
runtime.log.audit({event: "library.get",library:opts.library,type:opts.type,path:opts.path,error:err.code}, opts.req);
|
||||
return reject(err);
|
||||
}
|
||||
runtime.log.audit({event: "library.get",library:opts.library,type:opts.type,error:"not_found"});
|
||||
runtime.log.audit({event: "library.get",library:opts.library,type:opts.type,error:"not_found"}, opts.req);
|
||||
var error = new Error();
|
||||
error.code = "not_found";
|
||||
error.status = 404;
|
||||
@@ -72,22 +73,23 @@ var api = module.exports = {
|
||||
* @param {String} opts.path - the path of the entry
|
||||
* @param {Object} opts.meta - any meta data associated with the entry
|
||||
* @param {String} opts.body - the body of the entry
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise} - resolves when complete
|
||||
* @memberof @node-red/runtime_library
|
||||
*/
|
||||
saveEntry: function(opts) {
|
||||
return new Promise(function(resolve,reject) {
|
||||
runtime.library.saveEntry(opts.library,opts.type,opts.path,opts.meta,opts.body).then(function() {
|
||||
runtime.log.audit({event: "library.set",type:opts.type,path:opts.path});
|
||||
runtime.log.audit({event: "library.set",type:opts.type,path:opts.path}, opts.req);
|
||||
return resolve();
|
||||
}).catch(function(err) {
|
||||
runtime.log.warn(runtime.log._("api.library.error-save-entry",{path:opts.path,message:err.toString()}));
|
||||
if (err.code === 'forbidden') {
|
||||
runtime.log.audit({event: "library.set",type:opts.type,path:opts.path,error:"forbidden"});
|
||||
runtime.log.audit({event: "library.set",type:opts.type,path:opts.path,error:"forbidden"}, opts.req);
|
||||
err.status = 403;
|
||||
return reject(err);
|
||||
}
|
||||
runtime.log.audit({event: "library.set",type:opts.type,path:opts.path,error:"unexpected_error",message:err.toString()});
|
||||
runtime.log.audit({event: "library.set",type:opts.type,path:opts.path,error:"unexpected_error",message:err.toString()}, opts.req);
|
||||
var error = new Error();
|
||||
error.status = 400;
|
||||
return reject(error);
|
||||
|
Reference in New Issue
Block a user