UNPKG

1.8 kBJavaScriptView Raw
1'use strict'
2
3const child = require('child_process')
4const cli = require('heroku-cli-util')
5const exec = require('heroku-exec-util')
6const co = require('co')
7const Client = require('ssh2').Client
8const https = require('https')
9const url = require('url')
10const tty = require('tty')
11const stream = require('stream')
12
13module.exports = function (topic, command) {
14 return {
15 topic: topic,
16 command: command,
17 description: 'Create an SSH session to a dyno',
18 help: `Example:
19
20 $ heroku ps:exec 'node -i' --app murmuring-headland-14719`,
21 variableArgs: true,
22 flags: [
23 { name: 'dyno', char: 'd', hasValue: true, description: 'specify the dyno to connect to' },
24 { name: 'ssh', hasValue: false, description: 'use native ssh' },
25 { name: 'status', hasValue: false, description: 'lists the status of the SSH server in the dyno' }],
26 needsApp: true,
27 needsAuth: true,
28 run: cli.command(co.wrap(run))
29 }
30}
31
32function * run (context, heroku) {
33 yield exec.initFeature(context, heroku, function *(configVars) {
34 if (context.flags.status) {
35 yield exec.checkStatus(context, heroku, configVars)
36 } else {
37 yield exec.updateClientKey(context, heroku, configVars, function (privateKey, dyno, response) {
38 var message = `Connecting to ${cli.color.cyan.bold(dyno)} on ${cli.color.app(context.app)}`
39 cli.action(message, {success: false}, co(function* () {
40 cli.hush(response.body)
41 var json = JSON.parse(response.body)
42 if (context.flags.ssh) {
43 exec.ssh(context, json['client_user'], json['tunnel_host'], privateKey)
44 } else {
45 exec.connect(context, json['tunnel_host'], json['client_user'], privateKey)
46 }
47 }))
48 })
49 }
50 })
51 return new Promise(resolve => {})
52}