import * as plugins from './smartssh.plugins.js'; import * as helpers from './smartssh.classes.helpers.js'; import { SshKey } from './smartssh.classes.sshkey.js'; import { SshConfig } from './smartssh.classes.sshconfig.js'; export class SshDir { // sshDir class -> NOT EXPORTED, ONLY FOR INTERNAL USE private _path: string; // the path of the ssh directory private _sshKeyArray: SshKey[]; private _sshConfig: SshConfig; constructor(sshKeyArray: SshKey[], sshConfig: SshConfig, sshDirPathArg?: string) { this._sshKeyArray = sshKeyArray; this._sshConfig = sshConfig; if (sshDirPathArg) { this._path = helpers.resolveSshDirPath(sshDirPathArg); } else { this._path = helpers.resolveSshDirPath(); } } writeToDir(dirPathArg?: string) { // syncs sshInstance to directory let path = this._path; if (dirPathArg) path = helpers.resolveSshDirPath(dirPathArg); this._sshKeyArray.forEach((sshKeyArg) => { sshKeyArg.storeSync(path); }); this._sshConfig.store(path); } readFromDir(dirPathArg?: string) { // syncs sshInstance from directory let path = this._path; if (dirPathArg) path = helpers.resolveSshDirPath(dirPathArg); const sshKeys = helpers.sshKeyArrayFromDir(path); this._sshKeyArray.splice(0, this._sshKeyArray.length, ...sshKeys); } updateDirPath(dirPathArg: string) { this._path = helpers.resolveSshDirPath(dirPathArg); } getKeys() { return helpers.sshKeyArrayFromDir(this._path); } }