Add req back to audit log events and extend to Projects api

This commit is contained in:
Nick O'Leary
2019-08-09 16:56:11 +01:00
parent 6032d096ec
commit be2dd6dc32
13 changed files with 249 additions and 114 deletions

View File

@@ -67,7 +67,7 @@ var api = module.exports = {
* @param {String} opts.id - the id of the context
* @param {String} opts.store - the context store
* @param {String} opts.key - the context key
* @param {Object} opts.req - the request to log (optional)
* @return {Promise} - the node information
* @memberof @node-red/runtime_context
*/
@@ -81,7 +81,7 @@ var api = module.exports = {
var availableStores = runtime.nodes.listContextStores();
//{ default: 'default', stores: [ 'default', 'file' ] }
if (store && availableStores.stores.indexOf(store) === -1) {
runtime.log.audit({event: "context.get",scope:scope,id:id,store:store,key:key,error:"not_found"});
runtime.log.audit({event: "context.get",scope:scope,id:id,store:store,key:key,error:"not_found"}, opts.req);
var err = new Error();
err.code = "not_found";
err.status = 404;
@@ -106,7 +106,7 @@ var api = module.exports = {
if (store !== availableStores.default) {
encoded.store = store;
}
runtime.log.audit({event: "context.get",scope:scope,id:id,store:store,key:key});
runtime.log.audit({event: "context.get",scope:scope,id:id,store:store,key:key}, opts.req);
resolve(encoded);
});
return;
@@ -127,7 +127,7 @@ var api = module.exports = {
// TODO: proper error reporting
if (!errorReported) {
errorReported = true;
runtime.log.audit({event: "context.get",scope:scope,id:id,store:store,key:key,error:"unexpected_error"});
runtime.log.audit({event: "context.get",scope:scope,id:id,store:store,key:key,error:"unexpected_error"}, opts.req);
var err = new Error();
err.code = "unexpected_error";
err.status = 400;
@@ -139,7 +139,7 @@ var api = module.exports = {
c--;
if (c === 0) {
if (!errorReported) {
runtime.log.audit({event: "context.get",scope:scope,id:id,store:store,key:key});
runtime.log.audit({event: "context.get",scope:scope,id:id,store:store,key:key},opts.req);
resolve(result);
}
}
@@ -147,7 +147,7 @@ var api = module.exports = {
})
}
} else {
runtime.log.audit({event: "context.get",scope:scope,id:id,store:store,key:key});
runtime.log.audit({event: "context.get",scope:scope,id:id,store:store,key:key},opts.req);
resolve({});
}
})
@@ -161,7 +161,7 @@ var api = module.exports = {
* @param {String} opts.id - the id of the context
* @param {String} opts.store - the context store
* @param {String} opts.key - the context key
* @param {Object} opts.req - the request to log (optional)
* @return {Promise} - the node information
* @memberof @node-red/runtime_context
*/
@@ -175,7 +175,7 @@ var api = module.exports = {
var availableStores = runtime.nodes.listContextStores();
//{ default: 'default', stores: [ 'default', 'file' ] }
if (store && availableStores.stores.indexOf(store) === -1) {
runtime.log.audit({event: "context.get",scope:scope,id:id,store:store,key:key,error:"not_found"});
runtime.log.audit({event: "context.get",scope:scope,id:id,store:store,key:key,error:"not_found"},opts.req);
var err = new Error();
err.code = "not_found";
err.status = 404;
@@ -196,13 +196,13 @@ var api = module.exports = {
if (key) {
store = store || availableStores.default;
ctx.set(key,undefined,store,function(err) {
runtime.log.audit({event: "context.delete",scope:scope,id:id,store:store,key:key});
runtime.log.audit({event: "context.delete",scope:scope,id:id,store:store,key:key},opts.req);
resolve();
});
return;
} else {
// TODO: support deleting whole context
runtime.log.audit({event: "context.get",scope:scope,id:id,store:store,key:key,error:"not_found"});
runtime.log.audit({event: "context.get",scope:scope,id:id,store:store,key:key,error:"not_found"},opts.req);
var err = new Error();
err.code = "not_found";
err.status = 404;
@@ -243,7 +243,7 @@ var api = module.exports = {
// })
}
} else {
runtime.log.audit({event: "context.delete",scope:scope,id:id,store:store,key:key});
runtime.log.audit({event: "context.delete",scope:scope,id:id,store:store,key:key},opts.req);
resolve();
}