UNPKG

mecano

Version:

Common functions for system deployment.

53 lines (50 loc) 1.58 kB
// Generated by CoffeeScript 1.11.1 var fs; module.exports = function(options) { options.log({ message: "Entering assert", level: 'DEBUG', module: 'mecano/lib/assert' }); if (options.encoding == null) { options.encoding = 'utf8'; } if (options.target == null) { options.target = options.argument; } if (options.target == null) { options.target = options.source; } if (!options.target) { throw Error('Missing option: "target"'); } if (typeof options.content === 'string') { options.content = Buffer.from(options.content, options.encoding); } else if ((options.content != null) && !Buffer.isBuffer(options.content)) { throw Error("Invalid option 'content': expect string or buffer"); } this.call({ unless: options.content }, function(_, callback) { return fs.exists(options.ssh, options.target.toString(), function(err, exists) { if (!exists) { err = Error("File does not exists: " + (JSON.stringify(options.target))); } return callback(err); }); }); return this.call({ "if": options.content }, function(_, callback) { return fs.readFile(options.ssh, options.target, function(err, buffer) { if (!(err || buffer.equals(options.content))) { if (options.error == null) { options.error = "Invalid content match: expected " + (JSON.stringify(options.content.toString())) + ", got " + (JSON.stringify(buffer.toString())); } err = Error(options.error); } return callback(err); }); }); }; fs = require('ssh2-fs');