smartssh/dist/smartssh.classes.sshinstance.js

57 lines
6.6 KiB
JavaScript
Raw Normal View History

2016-06-01 00:31:29 +00:00
"use strict";
require("typings-global");
var helpers = require("./smartssh.classes.helpers");
var smartssh_classes_sshdir_1 = require("./smartssh.classes.sshdir");
var SshInstance = (function () {
function SshInstance(optionsArg) {
if (optionsArg === void 0) { optionsArg = {}; }
optionsArg ? void (0) : optionsArg = {};
this.sshDir = new smartssh_classes_sshdir_1.SshDir(optionsArg.sshDir);
this.sshKeys = this.sshDir.getKeys();
this.sshSync = optionsArg.sshSync;
}
;
SshInstance.prototype.addKey = function (sshKeyArg) {
this.sshKeys.push(sshKeyArg);
this.sync();
};
;
SshInstance.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;
}
};
;
2016-06-01 00:48:38 +00:00
SshInstance.prototype.getKeys = function () {
return this.sshKeys;
};
2016-06-01 00:31:29 +00:00
SshInstance.prototype.removeKey = function (sshKeyArg) {
var keyIndex = helpers.getKeyIndex(sshKeyArg.host);
this.sshKeys.splice(keyIndex, 1);
this.sync();
};
;
SshInstance.prototype.replaceKey = function (sshKeyOldArg, sshKeyNewArg) {
var keyIndex = helpers.getKeyIndex(sshKeyOldArg.host);
this.sshKeys.splice(keyIndex, 1, sshKeyNewArg);
this.sync();
};
;
SshInstance.prototype.sync = function () {
if (this.sshSync) {
this.sshDir.sync(this.sshConfig, this.sshKeys); // call sync method of sshDir class;
}
};
;
return SshInstance;
}());
exports.SshInstance = SshInstance;
2016-06-01 00:48:38 +00:00
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMuc3NoaW5zdGFuY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQ1AsQ0FBQyxDQURzQjtBQUV2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