2016-06-01 00:31:29 +00:00
|
|
|
"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 = {};
|
2016-06-01 01:57:17 +00:00
|
|
|
this.sshDir = new smartssh_classes_sshdir_1.SshDir(this, optionsArg.sshDirPath);
|
2016-06-01 02:18:31 +00:00
|
|
|
this.sshKeyArray = this.sshDir.getKeys();
|
2016-06-01 00:31:29 +00:00
|
|
|
this.sshSync = optionsArg.sshSync;
|
|
|
|
}
|
|
|
|
;
|
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-01 01:57:17 +00:00
|
|
|
this.sync("from");
|
2016-06-01 02:18:31 +00:00
|
|
|
this.sshKeyArray.push(sshKeyArg);
|
2016-06-01 01:57:17 +00:00
|
|
|
this.sync("to");
|
2016-06-01 00:31:29 +00:00
|
|
|
};
|
|
|
|
;
|
2016-06-01 01:57:17 +00:00
|
|
|
SshInstance.prototype.removeKey = function (sshKeyArg) {
|
|
|
|
this.sync("from");
|
2016-06-01 02:18:31 +00:00
|
|
|
var filteredArray = this.sshKeyArray.filter(function (sshKeyArg2) {
|
|
|
|
return (sshKeyArg != sshKeyArg2);
|
|
|
|
});
|
|
|
|
this.sshKeyArray = filteredArray;
|
2016-06-01 01:57:17 +00:00
|
|
|
this.sync("to");
|
|
|
|
};
|
|
|
|
;
|
|
|
|
SshInstance.prototype.replaceKey = function (sshKeyOldArg, sshKeyNewArg) {
|
|
|
|
this.sync("from");
|
2016-06-01 02:25:59 +00:00
|
|
|
this.removeKey(sshKeyOldArg);
|
|
|
|
this.addKey(sshKeyNewArg);
|
2016-06-01 01:57:17 +00:00
|
|
|
this.sync("to");
|
|
|
|
};
|
|
|
|
;
|
|
|
|
//
|
2016-06-01 00:31:29 +00:00
|
|
|
SshInstance.prototype.getKey = function (hostArg) {
|
2016-06-01 01:57:17 +00:00
|
|
|
this.sync("from");
|
2016-06-01 02:18:31 +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-01 02:25:59 +00:00
|
|
|
this.sync("from");
|
2016-06-01 02:18:31 +00:00
|
|
|
return this.sshKeyArray;
|
2016-06-01 01:57:17 +00:00
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
SshInstance.prototype.sync = function (directionArg) {
|
2016-06-01 02:18:31 +00:00
|
|
|
if (this.sshSync && directionArg == "from") {
|
|
|
|
this.sshDir.syncFromDir(); // call sync method of sshDir class;
|
2016-06-01 01:57:17 +00:00
|
|
|
}
|
2016-06-01 02:18:31 +00:00
|
|
|
else if (this.sshSync && directionArg == "to") {
|
|
|
|
this.sshDir.syncToDir();
|
2016-06-01 01:57:17 +00:00
|
|
|
}
|
2016-06-01 02:18:31 +00:00
|
|
|
else if (this.sshSync) {
|
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-01 02:25:59 +00:00
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,ey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