1 | 'use strict'
|
2 |
|
3 | const cli = require('heroku-cli-util')
|
4 | const co = require('co')
|
5 | const parsers = require('../../lib/parsers')()
|
6 |
|
7 | function check (val, message) {
|
8 | if (!val) throw new Error(`${message}.\nUSAGE: heroku spaces:vpn:create --ip 35.161.69.30 --cidrs 172.16.0.0/16,10.0.0.0/24 --space example-space`)
|
9 | }
|
10 |
|
11 | function * run (context, heroku) {
|
12 | let lib = require('../../lib/vpn')(heroku)
|
13 |
|
14 | let space = context.flags.space || context.args.space
|
15 | check(space, 'Space name required')
|
16 |
|
17 | let ip = context.flags.ip
|
18 | check(ip, 'IP required')
|
19 |
|
20 | let cidrs = context.flags.cidrs
|
21 | check(cidrs, 'CIDRs required')
|
22 | cidrs = parsers.splitCsv(cidrs)
|
23 |
|
24 | yield cli.action(`Creating VPN in space ${cli.color.green(space)}`, lib.postVPN(space, ip, cidrs))
|
25 | cli.warn('Use spaces:vpn:wait to track allocation.')
|
26 | }
|
27 |
|
28 | module.exports = {
|
29 | topic: 'spaces',
|
30 | command: 'vpn:create',
|
31 | description: 'create VPN',
|
32 | help: `
|
33 | Example:
|
34 | $ heroku spaces:vpn:create --ip 35.161.69.30 --cidrs 172.16.0.0/16,10.0.0.0/24 --space my-space
|
35 | Creating VPN in space my-space... done
|
36 | ▸ Use spaces:vpn:wait to track allocation.
|
37 | `,
|
38 | needsApp: false,
|
39 | needsAuth: true,
|
40 | args: [
|
41 | {name: 'space', optional: true, hidden: true}
|
42 | ],
|
43 | flags: [
|
44 | {name: 'ip', char: 'i', hasValue: true, description: 'public IP of customer gateway'},
|
45 | {name: 'cidrs', char: 'c', hasValue: true, description: 'a list of routable CIDRs separated by commas'},
|
46 | {name: 'space', char: 's', hasValue: true, description: 'space name'}
|
47 | ],
|
48 | run: cli.command(co.wrap(run))
|
49 | }
|