smartssh/dist/smartssh.classes.sshinstance.js
2016-06-01 04:18:31 +02:00

76 lines
8.8 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");
var filteredArray = this.sshKeyArray.filter(function (sshKeyArg) {
return (sshKeyArg.host == "some"); //TODO
});
this.sshKeyArray = filteredArray;
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 () {
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNt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