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

Commit ba1d8c2

Browse files
SiebeVEgregberge
authored andcommitted
feat(ssh-pool): Added ssh config array to remote server (#248)
1 parent 3586c21 commit ba1d8c2

File tree

6 files changed

+46
-1
lines changed

6 files changed

+46
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ The server can use the shorthand syntax or an object:
197197

198198
- `user@host`: user and host
199199
- `user@host:4000`: user, host and port
200-
- `{ user, host, port }`: an object
200+
- `{ user, host, port, extraSshOptions }`: an object
201201

202202
### Shipit Deploy configuration
203203

packages/ssh-pool/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ new Connection({
5858
port: 4000,
5959
},
6060
})
61+
62+
// When defined as an object you can add extra ssh parameters
63+
new Connection({
64+
remote: {
65+
user: 'user',
66+
host: 'localhost',
67+
port: 4000,
68+
extraSshOptions: {
69+
ServerAliveInterval: '30',
70+
}
71+
},
72+
})
6173
```
6274

6375
The log method is used to log output directly:

packages/ssh-pool/src/Connection.js

+2
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ class Connection {
301301
key: this.options.key,
302302
strict: this.options.strict,
303303
tty: this.options.tty,
304+
extraSshOptions: this.remote.extraSshOptions,
304305
verbosityLevel: this.options.verbosityLevel,
305306
remote: formatRemote(this.remote),
306307
command: formatRawCommand({ command, asUser: this.options.asUser }),
@@ -328,6 +329,7 @@ class Connection {
328329
port: this.remote.port,
329330
key: this.options.key,
330331
strict: this.options.strict,
332+
extraSshOptions: this.remote.extraSshOptions,
331333
tty: this.options.tty,
332334
})
333335

packages/ssh-pool/src/Connection.test.js

+19
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,25 @@ describe('Connection', () => {
140140
)
141141
})
142142

143+
it('should use extra ssh options on remote if present', async () => {
144+
connection = new Connection({
145+
remote: {
146+
host: 'host',
147+
user: 'user',
148+
extraSshOptions: {
149+
ExtraOption: 'option',
150+
SshForwardAgent: 'forward',
151+
}
152+
},
153+
})
154+
await connection.run('my-command -x')
155+
expect(exec).toHaveBeenCalledWith(
156+
'ssh -o ExtraOption=option -o SshForwardAgent=forward user@host "my-command -x"',
157+
{ maxBuffer: 1024000 },
158+
expect.any(Function),
159+
)
160+
})
161+
143162
it('should use port and key if both are present', async () => {
144163
connection = new Connection({
145164
remote: 'user@host:12345',

packages/ssh-pool/src/commands/ssh.js

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export function formatSshCommand({
1212
remote,
1313
cwd,
1414
command,
15+
extraSshOptions,
1516
verbosityLevel,
1617
}) {
1718
let args = ['ssh']
@@ -33,6 +34,11 @@ export function formatSshCommand({
3334
if (tty) args = [...args, '-tt']
3435
if (port) args = [...args, '-p', port]
3536
if (key) args = [...args, '-i', key]
37+
if(extraSshOptions && typeof extraSshOptions === 'object') {
38+
Object.keys(extraSshOptions).forEach((sshOptionsKey) => {
39+
args = [...args, '-o', `${sshOptionsKey}=${extraSshOptions[sshOptionsKey]}`]
40+
})
41+
}
3642
if (strict !== undefined)
3743
args = [...args, '-o', `StrictHostKeyChecking=${strict}`]
3844
if (remote) args = [...args, remote]

packages/ssh-pool/src/commands/ssh.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ describe('ssh', () => {
2929
)
3030
})
3131

32+
it('should support extra ssh options', () => {
33+
expect(formatSshCommand({ extraSshOptions: {ExtraOption: 'test option', MoreOptions: 'more option'} })).toBe(
34+
'ssh -o ExtraOption=test option -o MoreOptions=more option',
35+
)
36+
})
37+
3238
it('should support remote', () => {
3339
expect(
3440
formatSshCommand({

0 commit comments

Comments
 (0)