2016-06-01 00:31:29 +00:00
|
|
|
"use strict";
|
|
|
|
require("typings-global");
|
|
|
|
var smartssh_classes_sshdir_1 = require("./smartssh.classes.sshdir");
|
2016-06-25 00:29:34 +00:00
|
|
|
var smartssh_classes_sshconfig_1 = require("./smartssh.classes.sshconfig");
|
2016-06-01 00:31:29 +00:00
|
|
|
var SshInstance = (function () {
|
|
|
|
function SshInstance(optionsArg) {
|
|
|
|
if (optionsArg === void 0) { optionsArg = {}; }
|
|
|
|
optionsArg ? void (0) : optionsArg = {};
|
2016-06-25 00:29:34 +00:00
|
|
|
this._sshKeyArray = [];
|
|
|
|
this._sshConfig = new smartssh_classes_sshconfig_1.SshConfig(this._sshKeyArray);
|
|
|
|
this._sshDir = new smartssh_classes_sshdir_1.SshDir(this._sshKeyArray, optionsArg.sshDirPath);
|
2016-06-24 00:49:55 +00:00
|
|
|
this._sshSync = optionsArg.sshSync;
|
2016-06-01 00:31:29 +00:00
|
|
|
}
|
|
|
|
;
|
2016-06-01 01:57:17 +00:00
|
|
|
//altering methods
|
2016-06-01 00:31:29 +00:00
|
|
|
SshInstance.prototype.addKey = function (sshKeyArg) {
|
2016-06-24 00:49:55 +00:00
|
|
|
this._syncAuto("from");
|
2016-06-25 00:29:34 +00:00
|
|
|
this._sshKeyArray.push(sshKeyArg);
|
2016-06-24 00:49:55 +00:00
|
|
|
this._syncAuto("to");
|
2016-06-01 00:31:29 +00:00
|
|
|
};
|
|
|
|
;
|
2016-06-01 01:57:17 +00:00
|
|
|
SshInstance.prototype.removeKey = function (sshKeyArg) {
|
2016-06-24 00:49:55 +00:00
|
|
|
this._syncAuto("from");
|
2016-06-25 00:29:34 +00:00
|
|
|
var filteredArray = this._sshKeyArray.filter(function (sshKeyArg2) {
|
2016-06-01 02:18:31 +00:00
|
|
|
return (sshKeyArg != sshKeyArg2);
|
|
|
|
});
|
2016-06-25 00:29:34 +00:00
|
|
|
this._sshKeyArray = filteredArray;
|
2016-06-24 00:49:55 +00:00
|
|
|
this._syncAuto("to");
|
2016-06-01 01:57:17 +00:00
|
|
|
};
|
|
|
|
;
|
|
|
|
SshInstance.prototype.replaceKey = function (sshKeyOldArg, sshKeyNewArg) {
|
2016-06-24 00:49:55 +00:00
|
|
|
this._syncAuto("from");
|
2016-06-01 02:25:59 +00:00
|
|
|
this.removeKey(sshKeyOldArg);
|
|
|
|
this.addKey(sshKeyNewArg);
|
2016-06-24 00:49:55 +00:00
|
|
|
this._syncAuto("to");
|
2016-06-01 01:57:17 +00:00
|
|
|
};
|
|
|
|
;
|
|
|
|
//
|
2016-06-01 00:31:29 +00:00
|
|
|
SshInstance.prototype.getKey = function (hostArg) {
|
2016-06-24 00:49:55 +00:00
|
|
|
this._syncAuto("from");
|
2016-06-25 00:29:34 +00:00
|
|
|
var filteredArray = this._sshKeyArray.filter(function (keyArg) {
|
2016-06-01 00:31:29 +00:00
|
|
|
return (keyArg.host == hostArg);
|
|
|
|
});
|
|
|
|
if (filteredArray.length > 0) {
|
|
|
|
return filteredArray[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
;
|
2016-06-01 01:57:17 +00:00
|
|
|
Object.defineProperty(SshInstance.prototype, "sshKeys", {
|
|
|
|
get: function () {
|
2016-06-24 00:49:55 +00:00
|
|
|
this._syncAuto("from");
|
2016-06-25 00:29:34 +00:00
|
|
|
return this._sshKeyArray;
|
2016-06-01 01:57:17 +00:00
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
2016-06-24 00:49:55 +00:00
|
|
|
;
|
|
|
|
//FS methods
|
|
|
|
/**
|
|
|
|
* write SshInstance to disk
|
|
|
|
*/
|
|
|
|
SshInstance.prototype.writeToDisk = function () {
|
|
|
|
this._sync("to");
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* read ab SshInstance from disk
|
|
|
|
*/
|
|
|
|
SshInstance.prototype.readFromDisk = function () {
|
|
|
|
this._sync("from");
|
|
|
|
};
|
2016-06-25 00:29:34 +00:00
|
|
|
/* ===============================================================
|
|
|
|
========================= Private Methods ========================
|
|
|
|
================================================================*/
|
|
|
|
SshInstance.prototype._makeConfig = function () {
|
|
|
|
};
|
2016-06-24 00:49:55 +00:00
|
|
|
/**
|
|
|
|
* method to invoke SshInstance _sync automatically when sshSync is true
|
|
|
|
*/
|
|
|
|
SshInstance.prototype._syncAuto = function (directionArg) {
|
|
|
|
if (this._sshSync)
|
|
|
|
this._sync(directionArg);
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* private method to sync SshInstance
|
|
|
|
*/
|
|
|
|
SshInstance.prototype._sync = function (directionArg) {
|
|
|
|
if (directionArg == "from") {
|
2016-06-25 00:29:34 +00:00
|
|
|
this._sshDir.readFromDir(); // call sync method of sshDir class;
|
2016-06-01 01:57:17 +00:00
|
|
|
}
|
2016-06-24 00:49:55 +00:00
|
|
|
else if (directionArg == "to") {
|
2016-06-25 00:29:34 +00:00
|
|
|
this._sshDir.writeToDir();
|
2016-06-01 01:57:17 +00:00
|
|
|
}
|
2016-06-24 00:49:55 +00:00
|
|
|
else {
|
2016-06-01 01:57:17 +00:00
|
|
|
throw new Error("directionArg not recognised. Must be 'to' or 'from'");
|
2016-06-01 00:31:29 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
;
|
|
|
|
return SshInstance;
|
|
|
|
}());
|
|
|
|
exports.SshInstance = SshInstance;
|
|
|
|
|
2016-06-25 00:29:34 +00:00
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMuc3NoaW5zdGFuY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQ1AsQ0FBQyxDQURzQjtBQUl2Qix3Q0FBcUIsMkJBQTJCLENBQUMsQ0FBQTtBQUNqRCwyQ0FBd0IsOEJBQThCLENBQUMsQ0FBQTtBQUd2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