"use strict"; require("typings-global"); var helpers = require("./smartssh.classes.helpers"); 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.sshKeysVar = this.sshDir.getKeys(); this.sshSync = optionsArg.sshSync; } ; //altering methods SshInstance.prototype.addKey = function (sshKeyArg) { this.sync("from"); this.sshKeysVar.push(sshKeyArg); this.sync("to"); }; ; SshInstance.prototype.removeKey = function (sshKeyArg) { this.sync("from"); var keyIndex = helpers.getKeyIndex(sshKeyArg.host); this.sshKeysVar.splice(keyIndex, 1); this.sync("to"); }; ; SshInstance.prototype.replaceKey = function (sshKeyOldArg, sshKeyNewArg) { this.sync("from"); var keyIndex = helpers.getKeyIndex(sshKeyOldArg.host); this.sshKeysVar.splice(keyIndex, 1, sshKeyNewArg); this.sync("to"); }; ; // SshInstance.prototype.getKey = function (hostArg) { this.sync("from"); var filteredArray = this.sshKeysVar.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.sshKeysVar; }, enumerable: true, configurable: true }); SshInstance.prototype.sync = function (directionArg) { if (this.sshSync && directionArg == "to") { this.sshDir.syncToDir(); // call sync method of sshDir class; } else if (this.sshSync && directionArg == "from") { this.sshDir.syncFromDir(); } else { throw new Error("directionArg not recognised. Must be 'to' or 'from'"); } }; ; return SshInstance; }()); exports.SshInstance = SshInstance; //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMuc3NoaW5zdGFuY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQ1AsQ0FBQyxDQURzQjtBQU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