UNPKG

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