import * as plugins from './smartssh.plugins.js'; import * as helpers from './smartssh.classes.helpers.js'; import { SshKey } from './smartssh.classes.sshkey.js'; export class SshConfig { private _sshKeyArray: SshKey[]; constructor(sshKeyArrayArg: SshKey[]) { this._sshKeyArray = sshKeyArrayArg; } /** * stores a config file */ store(dirPathArg: string) { plugins.fs.ensureDirSync(dirPathArg); let configArray: configObject[] = []; for (const sshKey of this._sshKeyArray) { let configString = ''; if (sshKey.host) { configString = 'Host ' + sshKey.host + '\n' + ' HostName ' + sshKey.host + '\n' + ' IdentityFile ~/.ssh/' + sshKey.host + '\n' + ' StrictHostKeyChecking no' + '\n'; } configArray.push({ configString: configString, authorized: sshKey.authorized, sshKey: sshKey, }); } let configFile: string = ''; for (const config of configArray) { configFile = configFile + config.configString + '\n'; } plugins.fs.writeFileSync(plugins.path.join(dirPathArg, 'config'), configFile); } read(dirPathArg: string) { return plugins.fs.readFileSync(plugins.path.join(dirPathArg, 'config'), 'utf8'); } } export interface configObject { configString: string; authorized: boolean; sshKey: SshKey; }