1 | 'use strict'
|
2 |
|
3 | const cli = require('heroku-cli-util')
|
4 | const co = require('co')
|
5 |
|
6 | function check (val, message) {
|
7 | if (!val) throw new Error(`${message}.\nUSAGE: heroku spaces:vpn:destroy --space example-space vpn-connection-name`)
|
8 | }
|
9 |
|
10 | function * run (context, heroku) {
|
11 | let space = context.flags.space
|
12 | check(space, 'Space name required')
|
13 |
|
14 | let name = context.flags.name || context.args.name
|
15 | check(name, 'VPN name required')
|
16 |
|
17 | let lib = require('../../lib/vpn-connections')(heroku)
|
18 |
|
19 | yield cli.confirmApp(name, context.flags.confirm, `Destructive Action
|
20 | This command will attempt to destroy the specified VPN Connection in space ${cli.color.green(space)}`)
|
21 | yield cli.action(`Tearing down VPN Connection ${cli.color.cyan(name)} in space ${cli.color.cyan(space)}`, lib.deleteVPNConnection(space, name))
|
22 | }
|
23 |
|
24 | module.exports = {
|
25 | topic: 'spaces',
|
26 | command: 'vpn:destroy',
|
27 | description: 'destroys VPN in a private space',
|
28 | help: `Example:
|
29 |
|
30 | $ heroku spaces:vpn:destroy --space example-space vpn-connection-name --confirm vpn-connection-name
|
31 | Tearing down VPN Connection vpn-connection-name in space example-space
|
32 | `,
|
33 | needsApp: false,
|
34 | needsAuth: true,
|
35 | args: [
|
36 | { name: 'name', optional: true, hidden: true }
|
37 | ],
|
38 | flags: [
|
39 | { name: 'space', char: 's', hasValue: true, description: 'space to get peering info from' },
|
40 | { name: 'name', char: 'n', hasValue: true, description: 'name or id of the VPN connection to retrieve config from' },
|
41 | { name: 'confirm', hasValue: true, description: 'set to VPN connection name to bypass confirm prompt' }
|
42 | ],
|
43 | run: cli.command(co.wrap(run))
|
44 | }
|