106 lines
11 KiB
JavaScript
106 lines
11 KiB
JavaScript
"use strict";
|
|
require("typings-global");
|
|
var smartssh_classes_sshdir_1 = require("./smartssh.classes.sshdir");
|
|
var smartssh_classes_sshconfig_1 = require("./smartssh.classes.sshconfig");
|
|
var SshInstance = (function () {
|
|
function SshInstance(optionsArg) {
|
|
if (optionsArg === void 0) { optionsArg = {}; }
|
|
optionsArg ? void (0) : optionsArg = {};
|
|
this._sshKeyArray = [];
|
|
this._sshConfig = new smartssh_classes_sshconfig_1.SshConfig(this._sshKeyArray);
|
|
this._sshDir = new smartssh_classes_sshdir_1.SshDir(this._sshKeyArray, optionsArg.sshDirPath);
|
|
this._sshSync = optionsArg.sshSync;
|
|
}
|
|
;
|
|
//altering methods
|
|
SshInstance.prototype.addKey = function (sshKeyArg) {
|
|
this._syncAuto("from");
|
|
this._sshKeyArray.push(sshKeyArg);
|
|
this._syncAuto("to");
|
|
};
|
|
;
|
|
SshInstance.prototype.removeKey = function (sshKeyArg) {
|
|
this._syncAuto("from");
|
|
var filteredArray = this._sshKeyArray.filter(function (sshKeyArg2) {
|
|
return (sshKeyArg != sshKeyArg2);
|
|
});
|
|
this._sshKeyArray = filteredArray;
|
|
this._syncAuto("to");
|
|
};
|
|
;
|
|
SshInstance.prototype.replaceKey = function (sshKeyOldArg, sshKeyNewArg) {
|
|
this._syncAuto("from");
|
|
this.removeKey(sshKeyOldArg);
|
|
this.addKey(sshKeyNewArg);
|
|
this._syncAuto("to");
|
|
};
|
|
;
|
|
//
|
|
SshInstance.prototype.getKey = function (hostArg) {
|
|
this._syncAuto("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._syncAuto("from");
|
|
return this._sshKeyArray;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
;
|
|
//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");
|
|
};
|
|
/* ===============================================================
|
|
========================= Private Methods ========================
|
|
================================================================*/
|
|
SshInstance.prototype._makeConfig = function () {
|
|
};
|
|
/**
|
|
* 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") {
|
|
this._sshDir.readFromDir(); // call sync method of sshDir class;
|
|
}
|
|
else if (directionArg == "to") {
|
|
this._sshDir.writeToDir();
|
|
}
|
|
else {
|
|
throw new Error("directionArg not recognised. Must be 'to' or 'from'");
|
|
}
|
|
};
|
|
;
|
|
return SshInstance;
|
|
}());
|
|
exports.SshInstance = SshInstance;
|
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMuc3NoaW5zdGFuY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQ1AsQ0FBQyxDQURzQjtBQUl2Qix3Q0FBcUIsMkJBQTJCLENBQUMsQ0FBQTtBQUNqRCwyQ0FBd0IsOEJBQThCLENBQUMsQ0FBQTtBQUd2RDtJQUtJLHFCQUFZLFVBQW1EO1FBQW5ELDBCQUFtRCxHQUFuRCxlQUFtRDtRQUMzRCxVQUFVLEdBQUcsS0FBSSxDQUFDLENBQUMsQ0FBQyxHQUFHLFVBQVUsR0FBRyxFQUFFLENBQUM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biAgICAgICAgbGV0IGZpbHRlcmVkQXJyYXkgPSB0aGlzLl9zc2hLZXlBcnJheS5maWx0ZXIoZnVuY3Rpb24oa2V5QXJnKXtcbiAgICAgICAgICAgIHJldHVybiAoa2V5QXJnLmhvc3QgPT0gaG9zdEFyZyk7XG4gICAgICAgIH0pO1xuICAgICAgICBpZihmaWx0ZXJlZEFycmF5Lmxlbmd0aCA+IDApe1xuICAgICAgICAgICAgcmV0dXJuIGZpbHRlcmVkQXJyYXlbMF07XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXR1cm4gdW5kZWZpbmVkO1xuICAgICAgICB9XG4gICAgfTtcbiAgICBnZXQgc3NoS2V5cygpOlNzaEtleVtdIHtcbiAgICAgICAgdGhpcy5fc3luY0F1dG8oXCJmcm9tXCIpO1xuICAgICAgICByZXR1cm4gdGhpcy5fc3NoS2V5QXJyYXk7XG4gICAgfTtcblxuICAgIC8vRlMgbWV0aG9kc1xuXG4gICAgLyoqXG4gICAgICogd3JpdGUgU3NoSW5zdGFuY2UgdG8gZGlza1xuICAgICAqL1xuICAgIHdyaXRlVG9EaXNrKCl7XG4gICAgICAgIHRoaXMuX3N5bmMoXCJ0b1wiKTtcbiAgICB9XG5cbiAgICAvKipcbiAgICAgKiByZWFkIGFiIFNzaEluc3RhbmNlIGZyb20gZGlza1xuICAgICAqL1xuICAgIHJlYWRGcm9tRGlzaygpe1xuICAgICAgICB0aGlzLl9zeW5jKFwiZnJvbVwiKTtcbiAgICB9XG5cbiAgICAvKiA9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT1cbiAgICA9PT09PT09PT09PT09PT09PT09PT09PT09IFByaXZhdGUgTWV0aG9kcyA9PT09PT09PT09PT09PT09PT09PT09PT1cbiAgICA9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ki9cblxuICAgIHByaXZhdGUgX21ha2VDb25maWcgKCl7XG5cbiAgICB9XG5cbiAgICAvKipcbiAgICAgKiBtZXRob2QgdG8gaW52b2tlIFNzaEluc3RhbmNlIF9zeW5jIGF1dG9tYXRpY2FsbHkgd2hlbiBzc2hTeW5jIGlzIHRydWVcbiAgICAgKi9cbiAgICBwcml2YXRlIF9zeW5jQXV0byhkaXJlY3Rpb25Bcmcpe1xuICAgICAgICBpZih0aGlzLl9zc2hTeW5jKSB0aGlzLl9zeW5jKGRpcmVjdGlvbkFyZyk7XG4gICAgfVxuXG4gICAgLyoqXG4gICAgICogcHJpdmF0ZSBtZXRob2QgdG8gc3luYyBTc2hJbnN0YW5jZVxuICAgICAqL1xuICAgIHByaXZhdGUgX3N5bmMoZGlyZWN0aW9uQXJnOnN0cmluZyl7XG4gICAgICAgIGlmKGRpcmVjdGlvbkFyZyA9PSBcImZyb21cIil7XG4gICAgICAgICAgICB0aGlzLl9zc2hEaXIucmVhZEZyb21EaXIoKTsgLy8gY2FsbCBzeW5jIG1ldGhvZCBvZiBzc2hEaXIgY2xhc3M7XG4gICAgICAgIH0gZWxzZSBpZihkaXJlY3Rpb25BcmcgPT0gXCJ0b1wiKSB7XG4gICAgICAgICAgICB0aGlzLl9zc2hEaXIud3JpdGVUb0RpcigpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKFwiZGlyZWN0aW9uQXJnIG5vdCByZWNvZ25pc2VkLiBNdXN0IGJlICd0bycgb3IgJ2Zyb20nXCIpO1xuICAgICAgICB9XG4gICAgfTtcbn1cblxuXG4iXX0=
|