1 | 'use strict'
|
2 |
|
3 | const cli = require('heroku-cli-util')
|
4 | const co = require('co')
|
5 | const lib = require('../lib/spaces')
|
6 |
|
7 | function * run (context, heroku) {
|
8 | let spaceName = context.flags.space || context.args.space
|
9 | if (!spaceName) throw new Error('Space name required.\nUSAGE: heroku spaces:destroy my-space')
|
10 | let natWarning = ''
|
11 |
|
12 | let space = yield heroku.get(`/spaces/${spaceName}`)
|
13 | if (space.state === 'allocated') {
|
14 | space.outbound_ips = yield heroku.get(`/spaces/${spaceName}/nat`)
|
15 | if (space.outbound_ips && space.outbound_ips.state === 'enabled') {
|
16 | natWarning = `
|
17 | The Outbound IPs for this space will be reused!
|
18 | Ensure that external services no longer trust (whitelist) these Outbound IPs: ${lib.displayNat(space.outbound_ips)}`
|
19 | }
|
20 | }
|
21 |
|
22 | yield cli.confirmApp(spaceName, context.flags.confirm, `Destructive Action
|
23 | This command will destroy the space ${cli.color.bold.red(spaceName)}
|
24 | ${natWarning}
|
25 | `)
|
26 | let request = heroku.delete(`/spaces/${spaceName}`)
|
27 | yield cli.action(`Destroying space ${cli.color.cyan(spaceName)}`, request)
|
28 | }
|
29 |
|
30 | module.exports = {
|
31 | topic: 'spaces',
|
32 | command: 'destroy',
|
33 | description: 'destroy a space',
|
34 | help: `Example:
|
35 |
|
36 | $ heroku spaces:destroy --space my-space
|
37 | Destroying my-space... done
|
38 | `,
|
39 | needsApp: false,
|
40 | needsAuth: true,
|
41 | args: [{ name: 'space', optional: true, hidden: true }],
|
42 | flags: [
|
43 | { name: 'space', char: 's', hasValue: true, description: 'space to destroy' },
|
44 | { name: 'confirm', hasValue: true, description: 'set to space name to bypass confirm prompt' }
|
45 | ],
|
46 | run: cli.command(co.wrap(run))
|
47 | }
|