48 lines
5.3 KiB
JavaScript
48 lines
5.3 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";
|
|
}
|
|
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, dirPathArg);
|
|
return done.promise;
|
|
};
|
|
SshConfig.prototype.read = function (dirPathArg) {
|
|
var done = plugins.q.defer();
|
|
var configArray;
|
|
return done.promise;
|
|
};
|
|
return SshConfig;
|
|
}());
|
|
exports.SshConfig = SshConfig;
|
|
;
|
|
;
|
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMuc3NoY29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDeEIsSUFBWSxPQUFPLFdBQU0sb0JBQW9CLENBQUMsQ0FBQTtBQUk5QztJQUVJLG1CQUFZLGNBQXVCO1FBQy9CLElBQUksQ0FBQyxXQUFXLEdBQUcsY0FBYyxDQUFDO0lBQ3RDLENBQUM7SUFFRDs7T0FFRztJQUN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pbnMucS5kZWZlcigpO1xuICAgICAgICBsZXQgY29uZmlnQXJyYXk6Y29uZmlnT2JqZWN0W107XG4gICAgICAgIGxldCBjb25maWdTdHJpbmc7XG4gICAgICAgIGZvcihsZXQga2V5IGluIHRoaXMuc3NoS2V5QXJyYXkpe1xuICAgICAgICAgICAgbGV0IHNzaEtleSA9IHRoaXMuc3NoS2V5QXJyYXlba2V5XTtcbiAgICAgICAgICAgIGlmKHNzaEtleS5ob3N0KXtcbiAgICAgICAgICAgICAgICBjb25maWdTdHJpbmcgPSBcIkhvc3QgXCIgKyBzc2hLZXkuaG9zdCArIFwiXFxuXCIgK1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcIiAgSG9zdE5hbWUgXCIgKyBzc2hLZXkuaG9zdCArIFwiXFxuXCIgK1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcIiAgSWRlbnRpdHlGaWxlIH4vLnNzaC9cIiArIHNzaEtleS5ob3N0ICsgXCJcXG5cIlxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY29uZmlnQXJyYXkucHVzaCh7XG4gICAgICAgICAgICAgICAgY29uZmlnU3RyaW5nOmNvbmZpZ1N0cmluZyxcbiAgICAgICAgICAgICAgICBhdXRob3JpemVkOiBzc2hLZXkuYXV0aG9yaXplZCxcbiAgICAgICAgICAgICAgICBzc2hLZXk6IHNzaEtleVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH1cbiAgICAgICAgbGV0IGNvbmZpZ0ZpbGU6c3RyaW5nID0gXCJcIjtcbiAgICAgICAgZm9yKGxldCBrZXkgaW4gY29uZmlnQXJyYXkpe1xuICAgICAgICAgICAgY29uZmlnRmlsZSA9IGNvbmZpZ0ZpbGUgKyBjb25maWdBcnJheVtrZXldLmNvbmZpZ1N0cmluZyArIFwiXFxuXCI7XG4gICAgICAgIH07XG4gICAgICAgIHBsdWdpbnMuc21hcnRmaWxlLm1lbW9yeS50b0ZzU3luYyhjb25maWdGaWxlLGRpclBhdGhBcmcpO1xuICAgICAgICByZXR1cm4gZG9uZS5wcm9taXNlO1xuICAgIH1cbiAgICByZWFkKGRpclBhdGhBcmcpe1xuICAgICAgICBsZXQgZG9uZSA9IHBsdWdpbnMucS5kZWZlcigpO1xuICAgICAgICBsZXQgY29uZmlnQXJyYXk6Y29uZmlnT2JqZWN0W107XG4gICAgICAgIFxuICAgICAgICByZXR1cm4gZG9uZS5wcm9taXNlO1xuICAgIH1cbn07XG5cbmV4cG9ydCBpbnRlcmZhY2UgY29uZmlnT2JqZWN0IHtcbiAgICBjb25maWdTdHJpbmc6c3RyaW5nO1xuICAgIGF1dGhvcml6ZWQ6Ym9vbGVhbjtcbiAgICBzc2hLZXk6U3NoS2V5O1xufTtcblxuIl19
|