smartssh/dist/smartssh.classes.sshinstance.js
2016-06-25 15:30:57 +02:00

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, this._sshConfig, 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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMuc3NoaW5zdGFuY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQ1AsQ0FBQyxDQURzQjtBQUl2Qix3Q0FBcUIsMkJBQTJCLENBQUMsQ0FBQTtBQUNqRCwyQ0FBd0IsOEJBQThCLENBQUMsQ0FBQTtBQUd2RDtJQUtJLHFCQUFZLFVBQW1EO1FBQW5ELDBCQUFtRCxHQUFuRCxlQUFtRDtRQUMzRCxVQUFVLEdBQUcsS0FBSSxDQUFDLENBQUMsQ0FBQyxHQUFHLFVBQVUsR0FBRyxFQUFFLENBQUM7UUFDdkMsSUFBSSxDQUFDLFlBQVksR0FBRyxFQUFFLENBQUM7UUFDdkIsSUFBSSxDQUFDLFVBQVUsR0FBRyxJQUFJLHNDQUFTLENBQUMsSUFBSSxDQUFDLFlBQVksQ0FBQyxDQUFDO1FBQ25ELElBQUksQ0FBQyxPQUFPLEdBQUcsSUFBSSxnQ0FBTSxDQUFDLElBQUksQ0FBQyxZQUFZLEVBQUMsSUFBSSxDQUFDLFVBQVUsRUFBQyxVQUFVLENBQUMsVUFBVSxDQUFDLENBQUM7UUFDbkYsSUFBSSxDQUFDLFFBQVEsR0FBRyxVQUFVLENBQUMsT0FBTyxDQUFDO0lBQ3ZDLENBQUM7O0lBRUQsa0JBQWtCO0lBQ2xCLDRCQUF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dW5kZWZpbmVkO1xuICAgICAgICB9XG4gICAgfTtcbiAgICBnZXQgc3NoS2V5cygpOlNzaEtleVtdIHtcbiAgICAgICAgdGhpcy5fc3luY0F1dG8oXCJmcm9tXCIpO1xuICAgICAgICByZXR1cm4gdGhpcy5fc3NoS2V5QXJyYXk7XG4gICAgfTtcblxuICAgIC8vRlMgbWV0aG9kc1xuXG4gICAgLyoqXG4gICAgICogd3JpdGUgU3NoSW5zdGFuY2UgdG8gZGlza1xuICAgICAqL1xuICAgIHdyaXRlVG9EaXNrKCl7XG4gICAgICAgIHRoaXMuX3N5bmMoXCJ0b1wiKTtcbiAgICB9XG5cbiAgICAvKipcbiAgICAgKiByZWFkIGFiIFNzaEluc3RhbmNlIGZyb20gZGlza1xuICAgICAqL1xuICAgIHJlYWRGcm9tRGlzaygpe1xuICAgICAgICB0aGlzLl9zeW5jKFwiZnJvbVwiKTtcbiAgICB9XG5cbiAgICAvKiA9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT1cbiAgICA9PT09PT09PT09PT09PT09PT09PT09PT09IFByaXZhdGUgTWV0aG9kcyA9PT09PT09PT09PT09PT09PT09PT09PT1cbiAgICA9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ki9cblxuICAgIHByaXZhdGUgX21ha2VDb25maWcgKCl7XG5cbiAgICB9XG5cbiAgICAvKipcbiAgICAgKiBtZXRob2QgdG8gaW52b2tlIFNzaEluc3RhbmNlIF9zeW5jIGF1dG9tYXRpY2FsbHkgd2hlbiBzc2hTeW5jIGlzIHRydWVcbiAgICAgKi9cbiAgICBwcml2YXRlIF9zeW5jQXV0byhkaXJlY3Rpb25Bcmcpe1xuICAgICAgICBpZih0aGlzLl9zc2hTeW5jKSB0aGlzLl9zeW5jKGRpcmVjdGlvbkFyZyk7XG4gICAgfVxuXG4gICAgLyoqXG4gICAgICogcHJpdmF0ZSBtZXRob2QgdG8gc3luYyBTc2hJbnN0YW5jZVxuICAgICAqL1xuICAgIHByaXZhdGUgX3N5bmMoZGlyZWN0aW9uQXJnOnN0cmluZyl7XG4gICAgICAgIGlmKGRpcmVjdGlvbkFyZyA9PSBcImZyb21cIil7XG4gICAgICAgICAgICB0aGlzLl9zc2hEaXIucmVhZEZyb21EaXIoKTsgLy8gY2FsbCBzeW5jIG1ldGhvZCBvZiBzc2hEaXIgY2xhc3M7XG4gICAgICAgIH0gZWxzZSBpZihkaXJlY3Rpb25BcmcgPT0gXCJ0b1wiKSB7XG4gICAgICAgICAgICB0aGlzLl9zc2hEaXIud3JpdGVUb0RpcigpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKFwiZGlyZWN0aW9uQXJnIG5vdCByZWNvZ25pc2VkLiBNdXN0IGJlICd0bycgb3IgJ2Zyb20nXCIpO1xuICAgICAgICB9XG4gICAgfTtcbn1cbiJdfQ==