royal-thing
Version:
A process that restarts the local registrant when needed
63 lines (55 loc) • 2.04 kB
JavaScript
// Generated by CoffeeScript 2.4.1
(function() {
// First let's define what we mean by "when needed". We mean that changes were brought to any of the `registrant_*` fields in the global-number document that references them.
var assert, debug, fields, needed, pkg;
fields = [
'registrant_expiry',
'registrant_host',
'registrant_password',
'registrant_realm',
'registrant_domain',
'registrant_remote_ipv4', // legacy
'registrant_socket',
'registrant_username',
'registrant_proxy'
];
// However since calls can't be placed if the `account` field is empty, we don't need to be alerted of changes in that case. Also, obviously the changes only apply to a host that is listed as the `registrant_host`.
needed = function(local_host, old_doc, new_doc) {
var changed, i, len, name, value;
assert(local_host != null, `${pkg.name}: needed: missing localhost`);
assert(old_doc != null, `${pkg.name}: needed: missing old_doc`);
assert(new_doc != null, `${pkg.name}: needed: missing new_doc`);
changed = false;
value = function(doc, name) {
var host, ref, ref1;
if (doc.account == null) {
return null;
}
if (doc._deleted || doc.disabled) {
return null;
}
host = (ref = doc.registrant_host) != null ? ref.split(':')[0] : void 0;
if (host !== local_host) {
return null;
}
return (ref1 = doc[name]) != null ? ref1 : null;
};
for (i = 0, len = fields.length; i < len; i++) {
name = fields[i];
(function(name) {
var new_value, old_value;
old_value = value(old_doc, name);
new_value = value(new_doc, name);
if (old_value !== new_value) {
debug('Field changed', name, old_value, new_value);
return changed = true;
}
})(name);
}
return changed;
};
module.exports = needed;
assert = require('assert');
pkg = require('./package.json');
debug = (require('debug'))(`${pkg.name}:needed:trace`);
}).call(this);