Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
feat(config): Merge with existing config when writing to memcache. (#151
Browse files Browse the repository at this point in the history
) r=vladikoff

This makes it easier to change a single setting while leaving all
the others alone.
  • Loading branch information
rfk authored and vladikoff committed Jan 19, 2017
1 parent 4f5d781 commit a8f4d68
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 57 deletions.
116 changes: 63 additions & 53 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"deep-equal": "1.0.1",
"ip": "1.1.3",
"ip-reputation-js-client": "1.0.1",
"lodash.merge": "4.6.0",
"memcached": "2.2.1",
"newrelic": "1.30.1",
"restify": "4.1.1"
Expand Down
20 changes: 16 additions & 4 deletions scripts/config-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
var Memcached = require('memcached')
var P = require('bluebird')
var BL = require('bl')
var merge = require('lodash.merge')

P.promisifyAll(Memcached.prototype)

Expand All @@ -35,6 +36,17 @@ if (!/.+:\d+/.test(process.argv[2])) {
return console.error(x)
}

function writeMergedSettings(mc, key, newSettings) {
return mc.getAsync(key)
.then(
function (settings) {
settings = settings || {}
merge(settings, newSettings)
return mc.setAsync(key, settings, 0)
}
)
}

var b = process.stdin.pipe(new BL())

process.stdin.on('end', function () {
Expand All @@ -49,19 +61,19 @@ process.stdin.on('end', function () {

var actions = []
if (input.limits) {
actions.push(mc.setAsync('limits', input.limits, 0))
actions.push(writeMergedSettings(mc, 'limits', input.limits))
}

if (input.allowedIPs) {
actions.push(mc.setAsync('allowedIPs', input.allowedIPs, 0))
actions.push(writeMergedSettings(mc, 'allowedIPs', input.allowedIPs))
}

if (input.allowedEmailDomains) {
actions.push(mc.setAsync('allowedEmailDomains', input.allowedEmailDomains, 0))
actions.push(writeMergedSettings(mc, 'allowedEmailDomains', input.allowedEmailDomains))
}

if (input.requestChecks) {
actions.push(mc.setAsync('requestChecks', input.requestChecks, 0))
actions.push(writeMergedSettings(mc, 'requestChecks', input.requestChecks))
}

P.all(actions)
Expand Down

0 comments on commit a8f4d68

Please sign in to comment.