UNPKG

mecano

Version:

Common functions for system deployment.

78 lines (70 loc) 2.26 kB
// Generated by CoffeeScript 1.7.1 var child, conditions, each, execute, krb5_ktadd, misc; each = require('each'); misc = require('./misc'); conditions = require('./misc/conditions'); child = require('./misc/child'); execute = require('./execute'); krb5_ktadd = require('./krb5_ktadd'); 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_end, do_kadmin, do_keytab, modified; if (!options.principal) { return next(new Error('Property principal is required')); } if (!options.password && !options.randkey) { return next(new Error('Password or randkey missing')); } modified = false; do_kadmin = function() { var cmd; if (/.*@.*/.test(options.kadmin_principal)) { if (options.realm == null) { options.realm = options.kadmin_principal.split('@')[1]; } } cmd = misc.kadmin(options, options.password ? "addprinc -pw " + options.password + " " + options.principal : "addprinc -randkey " + options.principal); return execute({ cmd: cmd, ssh: options.ssh, log: options.log, stdout: options.stdout, stderr: options.stderr }, function(err, _, stdout) { if (err) { return next(err); } if (-1 === stdout.indexOf('already exists')) { modified = true; } return do_keytab(); }); }; do_keytab = function() { return krb5_ktadd(options, function(err, ktadded) { if (ktadded) { modified = true; } return do_end(); }); }; do_end = function() { if (modified) { executed++; } return next(); }; return conditions.all(options, next, do_kadmin); }).on('both', function(err) { return callback(err, executed); }); }); };