How to use the ssh-config.parse function in ssh-config

To help you get started, we’ve selected a few ssh-config examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NickCarneiro / remtail / lib / creds.js View on Github external
function parseSshConfig(sshConfigFileContents) {
    // Previously we were using a library that parsed ssh config files into arrays.
    // Mimic that behavior here so the rest of the code doesn't need to change.
    return objectToArray(sshConfig.parse(sshConfigFileContents));
}
github sebas5384 / hades / app / lib / ConfigFile.js View on Github external
const loadFromLocal = () => {
    const managedConfig = readManagedLocalConfig()
    const config = sshConfig.parse(managedConfig)

    // Return an empty array in case the local file is empty.
    if (!0 in config) return []

    // Extract items.
    const items = Object.keys(config)
      .filter((key) => {
        const index = Number(key)
        return Number.isInteger(index)
      })
      .map((key) => config[key])
      .map((item) => convertToAppFormat(item))

    return items
  }
github ionic-team / ionic-cli / packages / ionic / src / lib / __tests__ / ssh-config.ts View on Github external
it('should stringify with config5 file', async () => {
        const config5 = await readFile(path.resolve(__dirname, 'fixtures/ssh-config/config5'), { encoding: 'utf8' });
        const conf = SSHConfig.parse(config5);
        ensureHostAndKeyPath(conf, { host: 'bar' }, '/id_rsa');
        expect(SSHConfig.stringify(conf)).toEqual(config5);
      });
github microsoft / vscode-pull-request-github / src / common / ssh.ts View on Github external
export function resolverFromConfig(text: string): ConfigResolver {
	const config = parseConfig(text);
	return h => config.compute(h.Host);
}
github ionic-team / ionic-cli / packages / cli-plugin-cloud / src / commands / ssh / use.ts View on Github external
ensureSection(conf: SSHConfig.SSHConfig, host: string, newline: boolean): SSHConfig.ConfigDirective {
    const section = conf.find({ Host: host });

    if (!section) {
      conf.push(SSHConfig.parse(`${newline ? '\n' : ''}Host ${host}\n`)[0]);
    }

    return conf.find({ Host: host });
  }
github ionic-team / ionic-cli / packages / cli-plugin-cloud / src / commands / ssh / use.ts View on Github external
async applyConfig(text: string, keyPath: string): Promise {
    const c = await this.config.load();
    const conf = SSHConfig.parse(text);
    const host = c.git.host;
    const section = this.ensureSection(conf, host, Boolean(text));

    this.ensureSectionLine(section, 'IdentityFile', keyPath);

    if (typeof c.git.port === 'number') {
      this.ensureSectionLine(section, 'Port', String(c.git.port));
    }

    return SSHConfig.stringify(conf);
  }
github ionic-team / ionic-cli / packages / ionic / src / lib / ssh-config.ts View on Github external
export async function loadFromPath(p: string): Promise {
  const s = await fileToString(p);

  return SSHConfig.parse(s);
}
github ionic-team / ionic-cli / packages / ionic / src / lib / ssh-config.ts View on Github external
function ensureHostSection(conf: SSHConfig.SSHConfig, host: string): SSHConfig.ConfigHostDirective {
  let section = findHostSection(conf, host);

  if (!section) {
    conf.push(SSHConfig.parse(`\nHost ${host}\n`)[0]);
    section = findHostSection(conf, host);
  }

  if (!section) {
    throw new Error(`Could not find/insert section for host: ${host}`);
  }

  return section;
}
github derimagia / sshconfig2iterm / cli.js View on Github external
fs.readFile(process.env.HOME + '/.ssh/config', function (err, data) {
  if (err) {
    throw err;
  }

  sshConfig = sshConfig.parse(data.toString());

  var output = {
    Profiles: [],
  };

  for (var i = 0, len = sshConfig.length; i < len; i++) {
    var section = sshConfig[i];

    var host = section.Host;

    var comment = null;
    var commentIndex = section.Host.indexOf('#');

    if (commentIndex !== -1) {
      host = section.Host.substr(0, commentIndex);
      comment = section.Host.substr(commentIndex + 1).trim();
github ionic-team / ionic-cli / packages / ionic / src / lib / ssh-config.ts View on Github external
function ensureSectionLine(section: SSHConfig.ConfigHostDirective, key: string, value: string): void {
  const found = section.config.some(line => {
    if (isDirective(line)) {
      if (line.param === key) {
        line.value = value;
        return true;
      }
    }

    return false;
  });

  if (!found) {
    section.config = section.config.concat(SSHConfig.parse(`${key} ${value}\n`));
  }
}

ssh-config

SSH config parser and stringifier

MIT
Latest version published 1 month ago

Package Health Score

75 / 100
Full package analysis