50 lines
6.0 KiB
JavaScript
50 lines
6.0 KiB
JavaScript
"use strict";
|
|
require("typings-global");
|
|
var plugins = require("./smartssh.plugins");
|
|
var SshConfig = (function () {
|
|
function SshConfig(sshKeyArrayArg) {
|
|
this._sshKeyArray = sshKeyArrayArg;
|
|
}
|
|
/**
|
|
* stores a config file
|
|
*/
|
|
SshConfig.prototype.store = function (dirPathArg) {
|
|
var done = plugins.q.defer();
|
|
var configArray = [];
|
|
var configString;
|
|
for (var key in this._sshKeyArray) {
|
|
var sshKey = this._sshKeyArray[key];
|
|
if (sshKey.host) {
|
|
configString = "Host " + sshKey.host + "\n" +
|
|
" HostName " + sshKey.host + "\n" +
|
|
" IdentityFile ~/.ssh/" + sshKey.host + "\n" +
|
|
" StrictHostKeyChecking no" + "\n";
|
|
}
|
|
configArray.push({
|
|
configString: configString,
|
|
authorized: sshKey.authorized,
|
|
sshKey: sshKey
|
|
});
|
|
}
|
|
var configFile = "";
|
|
for (var key in configArray) {
|
|
configFile = configFile + configArray[key].configString + "\n";
|
|
}
|
|
;
|
|
plugins.smartfile.memory.toFsSync(configFile, plugins.path.join(dirPathArg, "config"));
|
|
return done.promise;
|
|
};
|
|
SshConfig.prototype.read = function (dirPathArg) {
|
|
var done = plugins.q.defer();
|
|
var configArray;
|
|
plugins.smartfile.fs.toStringSync(plugins.path.join(dirPathArg, "config"));
|
|
return done.promise;
|
|
};
|
|
return SshConfig;
|
|
}());
|
|
exports.SshConfig = SshConfig;
|
|
;
|
|
;
|
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMuc3NoY29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDeEIsSUFBWSxPQUFPLFdBQU0sb0JBQW9CLENBQUMsQ0FBQTtBQUk5QztJQUVJLG1CQUFZLGNBQXVC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3NoLmNsYXNzZXMuc3Noa2V5XCJcblxuZXhwb3J0IGNsYXNzIFNzaENvbmZpZyB7XG4gICAgcHJpdmF0ZSBfc3NoS2V5QXJyYXk6U3NoS2V5W107XG4gICAgY29uc3RydWN0b3Ioc3NoS2V5QXJyYXlBcmc6U3NoS2V5W10pe1xuICAgICAgICB0aGlzLl9zc2hLZXlBcnJheSA9IHNzaEtleUFycmF5QXJnO1xuICAgIH1cblxuICAgIC8qKlxuICAgICAqIHN0b3JlcyBhIGNvbmZpZyBmaWxlXG4gICAgICovXG4gICAgc3RvcmUoZGlyUGF0aEFyZzpzdHJpbmcpe1xuICAgICAgICBsZXQgZG9uZSA9IHBsdWdpbnMucS5kZWZlcigpO1xuICAgICAgICBsZXQgY29uZmlnQXJyYXk6Y29uZmlnT2JqZWN0W10gPSBbXTtcbiAgICAgICAgbGV0IGNvbmZpZ1N0cmluZztcbiAgICAgICAgZm9yKGxldCBrZXkgaW4gdGhpcy5fc3NoS2V5QXJyYXkpe1xuICAgICAgICAgICAgbGV0IHNzaEtleSA9IHRoaXMuX3NzaEtleUFycmF5W2tleV07XG4gICAgICAgICAgICBpZihzc2hLZXkuaG9zdCl7XG4gICAgICAgICAgICAgICAgY29uZmlnU3RyaW5nID0gXCJIb3N0IFwiICsgc3NoS2V5Lmhvc3QgKyBcIlxcblwiICtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXCIgIEhvc3ROYW1lIFwiICsgc3NoS2V5Lmhvc3QgKyBcIlxcblwiICtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXCIgIElkZW50aXR5RmlsZSB+Ly5zc2gvXCIgKyBzc2hLZXkuaG9zdCArIFwiXFxuXCIgK1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcIiAgU3RyaWN0SG9zdEtleUNoZWNraW5nIG5vXCIgKyBcIlxcblwiXG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBjb25maWdBcnJheS5wdXNoKHtcbiAgICAgICAgICAgICAgICBjb25maWdTdHJpbmc6Y29uZmlnU3RyaW5nLFxuICAgICAgICAgICAgICAgIGF1dGhvcml6ZWQ6IHNzaEtleS5hdXRob3JpemVkLFxuICAgICAgICAgICAgICAgIHNzaEtleTogc3NoS2V5XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgICAgICBsZXQgY29uZmlnRmlsZTpzdHJpbmcgPSBcIlwiO1xuICAgICAgICBmb3IobGV0IGtleSBpbiBjb25maWdBcnJheSl7XG4gICAgICAgICAgICBjb25maWdGaWxlID0gY29uZmlnRmlsZSArIGNvbmZpZ0FycmF5W2tleV0uY29uZmlnU3RyaW5nICsgXCJcXG5cIjtcbiAgICAgICAgfTtcbiAgICAgICAgcGx1Z2lucy5zbWFydGZpbGUubWVtb3J5LnRvRnNTeW5jKGNvbmZpZ0ZpbGUscGx1Z2lucy5wYXRoLmpvaW4oZGlyUGF0aEFyZyxcImNvbmZpZ1wiKSk7XG4gICAgICAgIHJldHVybiBkb25lLnByb21pc2U7XG4gICAgfVxuICAgIHJlYWQoZGlyUGF0aEFyZyl7XG4gICAgICAgIGxldCBkb25lID0gcGx1Z2lucy5xLmRlZmVyKCk7XG4gICAgICAgIGxldCBjb25maWdBcnJheTpjb25maWdPYmplY3RbXTtcbiAgICAgICAgcGx1Z2lucy5zbWFydGZpbGUuZnMudG9TdHJpbmdTeW5jKHBsdWdpbnMucGF0aC5qb2luKGRpclBhdGhBcmcsXCJjb25maWdcIikpO1xuXG4gICAgICAgIHJldHVybiBkb25lLnByb21pc2U7XG4gICAgfVxufTtcblxuZXhwb3J0IGludGVyZmFjZSBjb25maWdPYmplY3Qge1xuICAgIGNvbmZpZ1N0cmluZzpzdHJpbmc7XG4gICAgYXV0aG9yaXplZDpib29sZWFuO1xuICAgIHNzaEtleTpTc2hLZXk7XG59O1xuXG4iXX0=
|