smartssh/dist/smartssh.classes.ssh.js

53 lines
6.1 KiB
JavaScript

"use strict";
require("typings-global");
var helpers = require("./smartssh.classes.helpers");
var smartssh_classes_sshdir_1 = require("./smartssh.classes.sshdir");
var Ssh = (function () {
function Ssh(optionsArg) {
if (optionsArg === void 0) { optionsArg = {}; }
this.sshDir = new smartssh_classes_sshdir_1.SshDir(optionsArg.sshDir);
this.sshKeys = this.sshDir.getKeys();
this.sshSync = optionsArg.sshSync;
}
;
Ssh.prototype.addKey = function (sshKeyArg) {
this.sshKeys.push(sshKeyArg);
this.sync();
};
;
Ssh.prototype.getKey = function (hostArg) {
var filteredArray = this.sshKeys.filter(function (keyArg) {
return (keyArg.host == hostArg);
});
if (filteredArray.length > 0) {
return filteredArray[0];
}
else {
return undefined;
}
};
;
Ssh.prototype.removeKey = function (sshKeyArg) {
var keyIndex = helpers.getKeyIndex(sshKeyArg.host);
this.sshKeys.splice(keyIndex, 1);
this.sync();
};
;
Ssh.prototype.replaceKey = function (sshKeyOldArg, sshKeyNewArg) {
var keyIndex = helpers.getKeyIndex(sshKeyOldArg.host);
this.sshKeys.splice(keyIndex, 1, sshKeyNewArg);
this.sync();
};
;
Ssh.prototype.sync = function () {
if (this.sshSync) {
this.sshDir.sync(this.sshConfig, this.sshKeys); // call sync method of sshDir class;
}
};
;
return Ssh;
}());
exports.Ssh = Ssh;
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMuc3NoLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUNQLENBQUMsQ0FEc0I7QUFFdkIsSUFBWSxPQUFPLFdBQU0sNEJBQTRCLENBQUMsQ0FBQTtBQUV0RCx3Q0FBcUIsMkJBQTJCLENBQUMsQ0FBQTtBQUlqRDtJQUtJLGFBQVksVUFBK0M7UUFBL0MsMEJBQStDLEdBQS9DLGVBQStDO1FBQ3ZELEl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