Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Ability to pass in ssh2 client to transport #319

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

abmusse
Copy link
Member

@abmusse abmusse commented Jan 15, 2021

Part of #315

Here is an example on how this could be used:

/**
 * Example using an existing ssh2 client with itoolkit's ssh transport
 */

const { Connection, CommandCall } = require('itoolkit');
const { Client } = require('ssh2');
const { parseString } = require('xml2js');

const client = new Client();

// add ready listener
// then call itoolkit after client is connected and ready
client.on('ready', () => {
  const connection = new Connection({
    transport: 'ssh',
    transportOptions: {
      sshClient: client,
    },
  });

  const command = new CommandCall({ type: 'cl', command: 'RTVJOBA USRLIBL(?) SYSLIBL(?)' });

  connection.add(command);
  connection.run((error, xmlOutput) => {
    if (error) {
      throw error;
    }
    parseString(xmlOutput, (parseError, result) => {
      if (parseError) {
        throw parseError;
      }
      console.log(JSON.stringify(result));
    });
    // user closes the connection as needed
    client.end();
    client.destroy();
  });
});

client.connect({
  host: process.env.HOST,
  username: process.env.USER,
  password: process.env.PASS,
});

@abmusse abmusse added this to the Version 1.1 milestone Jan 15, 2021
@abmusse abmusse marked this pull request as ready for review January 19, 2021 16:37
@abmusse abmusse requested a review from kadler January 20, 2021 20:20
@github-actions
Copy link

👋 Hi! This pull request has been marked stale due to inactivity. If no further activity occurs, it will automatically be closed.

@github-actions github-actions bot added the stale label Feb 20, 2021
@abmusse abmusse added keep-open Exempts stale action from auto closing the issue/pr. and removed stale labels Feb 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep-open Exempts stale action from auto closing the issue/pr.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant