mecano
Version:
Common functions for system deployment.
58 lines (55 loc) • 1.59 kB
JavaScript
// Generated by CoffeeScript 1.11.1
var db;
module.exports = {
shy: true,
handler: function(options) {
var cmd, k, ref, ref1, v;
if (options.db == null) {
options.db = {};
}
ref = options.db;
for (k in ref) {
v = ref[k];
if (options[k] == null) {
options[k] = v;
}
}
if (options.host == null) {
throw Error('Missing option: "hostname"');
}
if (options.admin_username == null) {
throw Error('Missing option: "admin_username"');
}
if (options.admin_password == null) {
throw Error('Missing option: "admin_password"');
}
if (options.username == null) {
throw Error('Missing option: "username"');
}
if (!options.engine) {
throw Error('Missing option: "engine"');
}
options.engine = options.engine.toLowerCase();
if ((ref1 = options.engine) !== 'mysql' && ref1 !== 'postgres') {
throw Error("Unsupport engine: " + (JSON.stringify(options.engine)));
}
if (options.port == null) {
options.port = 5432;
}
cmd = (function() {
switch (options.engine) {
case 'mysql':
return db.cmd(options, {
database: 'mysql'
}, "select User from user where User = '" + options.username + "'") + (" | grep '" + options.username + "'");
case 'postgres':
return db.cmd(options, "SELECT 1 FROM pg_roles WHERE rolname='" + options.username + "'") + " | grep 1";
}
})();
return this.execute({
cmd: cmd,
code_skipped: 1
});
}
};
db = require('../../misc/db');