1 | 'use strict'
|
2 |
|
3 | const cli = require('heroku-cli-util')
|
4 | const co = require('co')
|
5 | const format = require('../../lib/format')()
|
6 |
|
7 | function displayVPNInfo (space, name, info) {
|
8 | cli.styledHeader(`${name} VPN Info`)
|
9 | cli.styledObject({
|
10 | Name: name,
|
11 | ID: info.id,
|
12 | 'Public IP': info.public_ip,
|
13 | 'Routable CIDRs': format.CIDR(info.routable_cidrs),
|
14 | 'Status': `${format.VPNStatus(info.status)}`,
|
15 | 'Status Message': info.status_message
|
16 | }, ['Name', 'ID', 'Public IP', 'Routable CIDRs', 'State', 'Status', 'Status Message'])
|
17 |
|
18 |
|
19 | info.tunnels.forEach((val, i) => { val.tunnel_id = 'Tunnel ' + (i + 1) })
|
20 | cli.styledHeader(`${name} VPN Tunnel Info`)
|
21 | cli.table(info.tunnels, {
|
22 | columns: [
|
23 | { key: 'tunnel_id', label: 'VPN Tunnel' },
|
24 | { key: 'ip', label: 'IP Address' },
|
25 | { key: 'status', label: 'Status', format: status => format.VPNStatus(status) },
|
26 | { key: 'last_status_change', label: 'Status Last Changed' },
|
27 | { key: 'status_message', label: 'Details' }
|
28 | ]
|
29 | })
|
30 | }
|
31 |
|
32 | function render (space, name, info, flags) {
|
33 | if (flags.json) {
|
34 | cli.styledJSON(info)
|
35 | } else {
|
36 | displayVPNInfo(space, name, info)
|
37 | }
|
38 | }
|
39 |
|
40 | function check (val, message) {
|
41 | if (!val) throw new Error(`${message}.\nUSAGE: heroku spaces:vpn:info --space my-space vpn-connection-name`)
|
42 | }
|
43 |
|
44 | function * run (context, heroku) {
|
45 | let space = context.flags.space || context.args.space
|
46 | check(space, 'Space name required')
|
47 |
|
48 | let name = context.flags.name || context.args.name
|
49 | check(name, 'VPN connection name required')
|
50 |
|
51 | let lib = require('../../lib/vpn-connections')(heroku)
|
52 | let info = yield lib.getVPNConnection(space, name)
|
53 |
|
54 | if (info.name) {
|
55 | name = info.name
|
56 | }
|
57 | render(space, name, info, context.flags)
|
58 | }
|
59 |
|
60 | module.exports = {
|
61 | topic: 'spaces',
|
62 | command: 'vpn:info',
|
63 | description: 'display the information for VPN',
|
64 | help: `Example:
|
65 |
|
66 | $ heroku spaces:vpn:info --space my-space vpn-connection-name
|
67 | === vpn-connection-name VPN Tunnel Info
|
68 | Name: vpn-connection-name
|
69 | ID: 123456789012
|
70 | Public IP: 35.161.69.30
|
71 | Routable CIDRs: 172.16.0.0/16
|
72 | Status: failed
|
73 | Status Message: supplied CIDR block already in use
|
74 | === my-space Tunnel Info
|
75 | VPN Tunnel IP Address Status Status Last Changed Details
|
76 | ────────── ───────────── ────── ──────────────────── ──────────────
|
77 | Tunnel 1 52.44.146.197 UP 2016-10-25T22:09:05Z status message
|
78 | Tunnel 2 52.44.146.197 UP 2016-10-25T22:09:05Z status message`,
|
79 | needsApp: false,
|
80 | needsAuth: true,
|
81 | args: [{ name: 'name', optional: true, hidden: true }],
|
82 | flags: [
|
83 | { name: 'space', char: 's', hasValue: true, description: 'space the vpn connection belongs to' },
|
84 | { name: 'json', description: 'output in json format' },
|
85 | { name: 'name', char: 'n', hasValue: true, description: 'name or id of the VPN connection to get info from' }
|
86 | ],
|
87 | run: cli.command(co.wrap(run)),
|
88 | render: render
|
89 | }
|