Skip to content
This repository has been archived by the owner on Mar 14, 2023. It is now read-only.

Added ssh config array to remote server #248

Merged
merged 1 commit into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ The server can use the shorthand syntax or an object:

- `user@host`: user and host
- `user@host:4000`: user, host and port
- `{ user, host, port }`: an object
- `{ user, host, port, extraSshOptions }`: an object

### Shipit Deploy configuration

Expand Down
12 changes: 12 additions & 0 deletions packages/ssh-pool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ new Connection({
port: 4000,
},
})

// When defined as an object you can add extra ssh parameters
new Connection({
remote: {
user: 'user',
host: 'localhost',
port: 4000,
extraSshOptions: {
ServerAliveInterval: '30',
}
},
})
```

The log method is used to log output directly:
Expand Down
2 changes: 2 additions & 0 deletions packages/ssh-pool/src/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ class Connection {
key: this.options.key,
strict: this.options.strict,
tty: this.options.tty,
extraSshOptions: this.remote.extraSshOptions,
verbosityLevel: this.options.verbosityLevel,
remote: formatRemote(this.remote),
command: formatRawCommand({ command, asUser: this.options.asUser }),
Expand Down Expand Up @@ -328,6 +329,7 @@ class Connection {
port: this.remote.port,
key: this.options.key,
strict: this.options.strict,
extraSshOptions: this.remote.extraSshOptions,
tty: this.options.tty,
})

Expand Down
19 changes: 19 additions & 0 deletions packages/ssh-pool/src/Connection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,25 @@ describe('Connection', () => {
)
})

it('should use extra ssh options on remote if present', async () => {
connection = new Connection({
remote: {
host: 'host',
user: 'user',
extraSshOptions: {
ExtraOption: 'option',
SshForwardAgent: 'forward',
}
},
})
await connection.run('my-command -x')
expect(exec).toHaveBeenCalledWith(
'ssh -o ExtraOption=option -o SshForwardAgent=forward user@host "my-command -x"',
{ maxBuffer: 1024000 },
expect.any(Function),
)
})

it('should use port and key if both are present', async () => {
connection = new Connection({
remote: 'user@host:12345',
Expand Down
6 changes: 6 additions & 0 deletions packages/ssh-pool/src/commands/ssh.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function formatSshCommand({
remote,
cwd,
command,
extraSshOptions,
verbosityLevel,
}) {
let args = ['ssh']
Expand All @@ -33,6 +34,11 @@ export function formatSshCommand({
if (tty) args = [...args, '-tt']
if (port) args = [...args, '-p', port]
if (key) args = [...args, '-i', key]
if(extraSshOptions && typeof extraSshOptions === 'object') {
Object.keys(extraSshOptions).forEach((sshOptionsKey) => {
args = [...args, '-o', `${sshOptionsKey}=${extraSshOptions[sshOptionsKey]}`]
})
}
if (strict !== undefined)
args = [...args, '-o', `StrictHostKeyChecking=${strict}`]
if (remote) args = [...args, remote]
Expand Down
6 changes: 6 additions & 0 deletions packages/ssh-pool/src/commands/ssh.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ describe('ssh', () => {
)
})

it('should support extra ssh options', () => {
expect(formatSshCommand({ extraSshOptions: {ExtraOption: 'test option', MoreOptions: 'more option'} })).toBe(
'ssh -o ExtraOption=test option -o MoreOptions=more option',
)
})

it('should support remote', () => {
expect(
formatSshCommand({
Expand Down