"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); require("typings-global"); const smartssh_classes_sshdir_1 = require("./smartssh.classes.sshdir"); const smartssh_classes_sshconfig_1 = require("./smartssh.classes.sshconfig"); class SshInstance { constructor(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 addKey(sshKeyArg) { this._syncAuto('from'); this._sshKeyArray.push(sshKeyArg); this._syncAuto('to'); } ; removeKey(sshKeyArg) { this._syncAuto('from'); let filteredArray = this._sshKeyArray.filter((sshKeyArg2) => { return (sshKeyArg != sshKeyArg2); }); this._sshKeyArray = filteredArray; this._syncAuto('to'); } ; replaceKey(sshKeyOldArg, sshKeyNewArg) { this._syncAuto('from'); this.removeKey(sshKeyOldArg); this.addKey(sshKeyNewArg); this._syncAuto('to'); } ; // getKey(hostArg) { this._syncAuto('from'); let filteredArray = this._sshKeyArray.filter(function (keyArg) { return (keyArg.host === hostArg); }); if (filteredArray.length > 0) { return filteredArray[0]; } else { return undefined; } } ; get sshKeys() { this._syncAuto('from'); return this._sshKeyArray; } ; // FS methods /** * write SshInstance to disk */ writeToDisk(dirPathArg) { this._sync('to', dirPathArg); } /** * read ab SshInstance from disk */ readFromDisk(dirPathArg) { this._sync('from', dirPathArg); } /* =============================================================== ========================= Private Methods ======================== ================================================================*/ _makeConfig() { } /** * method to invoke SshInstance _sync automatically when sshSync is true */ _syncAuto(directionArg) { if (this._sshSync) this._sync(directionArg); } /** * private method to sync SshInstance */ _sync(directionArg, dirPathArg) { if (directionArg === 'from') { this._sshDir.readFromDir(dirPathArg); // call sync method of sshDir class; } else if (directionArg === 'to') { this._sshDir.writeToDir(dirPathArg); } else { throw new Error("directionArg not recognised. Must be 'to' or 'from'"); } } ; } exports.SshInstance = S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