75 lines
8.3 KiB
JavaScript
75 lines
8.3 KiB
JavaScript
"use strict";
|
|
require("typings-global");
|
|
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(this, optionsArg.sshDirPath);
|
|
this.sshKeyArray = this.sshDir.getKeys();
|
|
this.sshSync = optionsArg.sshSync;
|
|
}
|
|
;
|
|
//altering methods
|
|
SshInstance.prototype.addKey = function (sshKeyArg) {
|
|
this.sync("from");
|
|
this.sshKeyArray.push(sshKeyArg);
|
|
this.sync("to");
|
|
};
|
|
;
|
|
SshInstance.prototype.removeKey = function (sshKeyArg) {
|
|
this.sync("from");
|
|
var filteredArray = this.sshKeyArray.filter(function (sshKeyArg2) {
|
|
return (sshKeyArg != sshKeyArg2);
|
|
});
|
|
this.sshKeyArray = filteredArray;
|
|
this.sync("to");
|
|
};
|
|
;
|
|
SshInstance.prototype.replaceKey = function (sshKeyOldArg, sshKeyNewArg) {
|
|
this.sync("from");
|
|
this.removeKey(sshKeyOldArg);
|
|
this.addKey(sshKeyNewArg);
|
|
this.sync("to");
|
|
};
|
|
;
|
|
//
|
|
SshInstance.prototype.getKey = function (hostArg) {
|
|
this.sync("from");
|
|
var filteredArray = this.sshKeyArray.filter(function (keyArg) {
|
|
return (keyArg.host == hostArg);
|
|
});
|
|
if (filteredArray.length > 0) {
|
|
return filteredArray[0];
|
|
}
|
|
else {
|
|
return undefined;
|
|
}
|
|
};
|
|
;
|
|
Object.defineProperty(SshInstance.prototype, "sshKeys", {
|
|
get: function () {
|
|
this.sync("from");
|
|
return this.sshKeyArray;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
SshInstance.prototype.sync = function (directionArg) {
|
|
if (this.sshSync && directionArg == "from") {
|
|
this.sshDir.syncFromDir(); // call sync method of sshDir class;
|
|
}
|
|
else if (this.sshSync && directionArg == "to") {
|
|
this.sshDir.syncToDir();
|
|
}
|
|
else if (this.sshSync) {
|
|
throw new Error("directionArg not recognised. Must be 'to' or 'from'");
|
|
}
|
|
};
|
|
;
|
|
return SshInstance;
|
|
}());
|
|
exports.SshInstance = SshInstance;
|
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMuc3NoaW5zdGFuY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQ1AsQ0FBQyxDQURzQjtBQUl2Qix3Q0FBcUIsMkJBQTJCLENBQUMsQ0FBQTtBQUlqRDtJQUtJLHFCQUFZLFVBQW1EO1FBQW5ELDBCQUFtRCxHQUFuRCxlQUFtRDtRQUMzRCxVQUFVLEdBQUcsS0FBSSxDQUFDLENBQUMsQ0FBQyxHQUFHLFVBQVUsR0FBRyxFQUFFLENBQUM7UUFFdkMsSUFBSSxDQUFDLE1BQU0sR0FBRyxJQUFJLGdDQUFNLENBQUMsSUFBSSxFQUFDLFVBQVUsQ0FBQyxVQUFVLENBQUMsQ0FBQztRQUNyRCxJQUFJLENBQUMsV0FBVyxHQUFHLElBQUksQ0FBQyxNQUFNLENBQUMsT0FBTyxFQUFFLENBQUM7UUFDekMsSUFBSSxDQUFDLE9BQU8sR0FBRyxVQUFVLENBQUMsT0FBTyxDQUFDO0lBQ3RDLENBQUM7O0lBRUQsa0JBQWtCO0lBQ2xCLDRCQUFNLEdBQU4sVUFBTyxTQUFnQjtRQUNuQixJQUFJLENBQUMsSUFBSSxDQUFDLE1BQU0sQ0FBQyxDQUFDO1FBQ2xCLElBQUksQ0FBQyxXQUFXLENBQUMsSUFBSSxDQUFDLFNBQVMsQ0FBQyxDQUFDO1FBQ2pDLElBQUksQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUM7SUFDc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