mecano
Version:
Common functions for system deployment.
77 lines (69 loc) • 2.02 kB
JavaScript
// Generated by CoffeeScript 1.7.1
var child, conditions, each, execute, misc, remove;
each = require('each');
misc = require('./misc');
conditions = require('./misc/conditions');
child = require('./misc/child');
execute = require('./execute');
remove = require('./remove');
module.exports = function(goptions, options, callback) {
var _ref;
_ref = misc.args(arguments), goptions = _ref[0], options = _ref[1], callback = _ref[2];
return misc.options(options, function(err, options) {
var executed;
if (err) {
return callback(err);
}
executed = 0;
return each(options).parallel(goptions.parallel).on('item', function(options, next) {
var do_delprinc, do_end, do_keytab, modified;
if (!options.principal) {
return next(new Error('Property principal is required'));
}
modified = true;
do_delprinc = function() {
return execute({
cmd: misc.kadmin(options, "delprinc -force " + options.principal),
ssh: options.ssh,
log: options.log,
stdout: options.stdout,
stderr: options.stderr
}, function(err, _, stdout) {
if (err) {
return next(err);
}
if (-1 === stdout.indexOf('does not exist')) {
modified = true;
}
return do_keytab();
});
};
do_keytab = function() {
if (!options.keytab) {
return do_end();
}
return remove({
ssh: options.ssh,
destination: options.keytab
}, function(err, removed) {
if (err) {
return next(err);
}
if (removed) {
modified++;
}
return do_end();
});
};
do_end = function() {
if (modified) {
executed++;
}
return next();
};
return conditions.all(options, next, do_delprinc);
}).on('both', function(err) {
return callback(err, executed);
});
});
};