Commit f2ba49cd authored by project's avatar project

--no commit message

--no commit message
parent a9ab72aa
...@@ -56,12 +56,6 @@ CronList.prototype.clean = function() ...@@ -56,12 +56,6 @@ CronList.prototype.clean = function()
CronList.prototype.update = function(cb) CronList.prototype.update = function(cb)
{ {
var self=this; var self=this;
// this.mem.get(PREFIX, function (err, result) {
// if(!err && result){
// self.list = JSON.parse(result);
// }
// cb(err);
// });
self.list = []; self.list = [];
self.mem.hgetall(KEYS,function (err,res){ self.mem.hgetall(KEYS,function (err,res){
if(!err && res){ if(!err && res){
...@@ -81,6 +75,13 @@ CronList.prototype.update = function(cb) ...@@ -81,6 +75,13 @@ CronList.prototype.update = function(cb)
cb(err); cb(err);
}); });
// this.mem.get(PREFIX, function (err, result) {
// if(!err && result){
// self.list = JSON.parse(result);
// }
// cb(err);
// });
} }
CronList.prototype.commit = function(cb) CronList.prototype.commit = function(cb)
......
var Redis = require('redis'); var Redis = require('redis');
const PREFIX = 'bs:http:acl'; const PREFIX = 'bs:http:acl';
const KEYS = 'bs:regis:triggers';
module.exports.create = function(cfg) module.exports.create = function(cfg)
{ {
return new HttpACL(cfg); return new HttpACL(cfg);
} }
module.exports.mkACL = function(appkey,method,jobid,opt) module.exports.mkACL = mkACL;
function mkACL(appkey,method,jobid,opt)
{ {
var a = { var a = {
'appkey' : appkey, 'appkey' : appkey,
...@@ -54,25 +56,46 @@ HttpACL.prototype.clean = function() ...@@ -54,25 +56,46 @@ HttpACL.prototype.clean = function()
HttpACL.prototype.update = function(cb) HttpACL.prototype.update = function(cb)
{ {
var self=this; var self=this;
this.mem.get(PREFIX, function (err, result) { self.clean()
if(!err && result){ self.mem.hgetall(KEYS,function (err,res){
if(!err && res){
self.acl = JSON.parse(result); var ks = Object.keys(res);
for(var i=0;i<ks.length;i++)
{
var k = ks[i];
var trigger = JSON.parse(res[k]);
if(trigger.type == 'http')
{
var acl = mkACL(trigger.appkey,trigger.method,trigger.job_id);
self.add(acl);
}
}
} }
cb(err); cb(err);
}); });
}
HttpACL.prototype.commit = function(cb)
{
var stracl = JSON.stringify(this.acl);
this.mem.set(PREFIX,stracl);
if(typeof cb == 'function'){ // this.mem.get(PREFIX, function (err, result) {
cb(); // if(!err && result){
} //
// self.acl = JSON.parse(result);
// }
// cb(err);
// });
} }
// HttpACL.prototype.commit = function(cb)
// {
// var stracl = JSON.stringify(this.acl);
// this.mem.set(PREFIX,stracl);
//
// if(typeof cb == 'function'){
// cb();
// }
// }
HttpACL.prototype.findJob= function(appkey,method) HttpACL.prototype.findJob= function(appkey,method)
{ {
var jobs = []; var jobs = [];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment