From a4532f011ac80bbbe4d0b78b97785a05050d1fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 7 Sep 2017 15:34:17 -0400 Subject: [PATCH] Blacklist fix (#5918) * closes #5917 * fix callback for upgrade script * delete key even if falsy, could be empty string * DRYer ternary --- src/meta/blacklist.js | 11 +++++++++-- src/upgrades/1.6.0/ipblacklist-fix.js | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 src/upgrades/1.6.0/ipblacklist-fix.js diff --git a/src/meta/blacklist.js b/src/meta/blacklist.js index 4a1eeeb71f..20f0e441ff 100644 --- a/src/meta/blacklist.js +++ b/src/meta/blacklist.js @@ -41,7 +41,7 @@ pubsub.on('blacklist:reload', Blacklist.load); Blacklist.save = function (rules, callback) { async.waterfall([ function (next) { - db.set('ip-blacklist-rules', rules, next); + db.setObject('ip-blacklist-rules', { rules: rules }, next); }, function (next) { Blacklist.load(next); @@ -51,7 +51,14 @@ Blacklist.save = function (rules, callback) { }; Blacklist.get = function (callback) { - db.get('ip-blacklist-rules', callback); + async.waterfall([ + function (next) { + db.getObject('ip-blacklist-rules', next); + }, + function (data, next) { + next(null, data && data.rules); + }, + ], callback); }; Blacklist.test = function (clientIp, callback) { diff --git a/src/upgrades/1.6.0/ipblacklist-fix.js b/src/upgrades/1.6.0/ipblacklist-fix.js new file mode 100644 index 0000000000..27afd49d97 --- /dev/null +++ b/src/upgrades/1.6.0/ipblacklist-fix.js @@ -0,0 +1,25 @@ +'use strict'; + +var async = require('async'); + +var db = require('../../database'); + +module.exports = { + name: 'Changing ip blacklist storage to object', + timestamp: Date.UTC(2017, 8, 7), + method: function (callback) { + var rules; + async.waterfall([ + function (next) { + db.get('ip-blacklist-rules', next); + }, + function (_rules, next) { + rules = _rules; + db.delete('ip-blacklist-rules', rules ? next : callback); + }, + function (next) { + db.setObject('ip-blacklist-rules', { rules: rules }, next); + }, + ], callback); + }, +};