Skip to content

Commit

Permalink
feature: Update command warning message for Fir spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
justinwilaby committed Jan 10, 2025
1 parent 7947ef4 commit 318cf36
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
15 changes: 14 additions & 1 deletion packages/cli/src/commands/spaces/destroy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as Heroku from '@heroku-cli/schema'
import heredoc from 'tsheredoc'
import confirmCommand from '../../lib/confirmCommand'
import {displayNat} from '../../lib/spaces/spaces'
import chalk from 'chalk'

type RequiredSpaceWithNat = Required<Heroku.Space> & {outbound_ips?: Required<Heroku.SpaceNetworkAddressTranslation>}

Expand Down Expand Up @@ -43,7 +44,19 @@ export default class Destroy extends Command {
if (space.state === 'allocated') {
({body: space.outbound_ips} = await this.heroku.get<Required<Heroku.SpaceNetworkAddressTranslation>>(`/spaces/${spaceName}/nat`))
if (space.outbound_ips && space.outbound_ips.state === 'enabled') {
natWarning = `The Outbound IPs for this space will be reused!\nEnsure that external services no longer allow these Outbound IPs: ${displayNat(space.outbound_ips)}\n`
natWarning = heredoc`
${chalk.dim('===')} ${chalk.bold('WARNING: Outbound IPs Will Be Reused')}
${chalk.yellow('⚠️ The following outbound IPs (IPv4 and IPv6) will become available for reuse:')}
${chalk.bold(displayNat(space.outbound_ips) ?? '')}
${chalk.dim('Please update the following configurations:')}
${chalk.dim('=')} IP allowlists
${chalk.dim('=')} Firewall rules
${chalk.dim('=')} Security group configurations
${chalk.dim('=')} Network ACLs
${chalk.yellow('Ensure all IPv4 and IPv6 addresses are removed from your security configurations.')}
`
}
}

Expand Down
36 changes: 29 additions & 7 deletions packages/cli/test/unit/commands/spaces/destroy.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import {stderr} from 'stdout-stderr'
import { stderr, stdout } from 'stdout-stderr'

Check failure on line 1 in packages/cli/test/unit/commands/spaces/destroy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-latest)

There should be no space after '{'

Check failure on line 1 in packages/cli/test/unit/commands/spaces/destroy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-latest)

There should be no space before '}'
import Cmd from '../../../../src/commands/spaces/destroy'
import runCommand from '../../../helpers/runCommand'
import * as nock from 'nock'
import {expect} from 'chai'
import heredoc from 'tsheredoc'

import {ux} from '@oclif/core'
import * as sinon from 'sinon'
describe('spaces:destroy', function () {
const now = new Date()

beforeEach(function () {
sinon.stub(ux, 'prompt').resolves('my-space')
})

afterEach(function () {
nock.cleanAll()
sinon.restore()
})

it('destroys a space', async function () {
Expand All @@ -21,13 +27,29 @@ describe('spaces:destroy', function () {
.delete('/spaces/my-space')
.reply(200)

await runCommand(Cmd, ['--space', 'my-space', '--confirm', 'my-space'])

await runCommand(Cmd, ['--space', 'my-space'])
api.done()

expect(stderr.output).to.eq(heredoc`
Destroying space my-space...
Destroying space my-space... done
expect(stderr.output).to.eq(heredoc` › Warning: Destructive Action
› This command will destroy the space my-space
› === WARNING: Outbound IPs Will Be Reused
› ⚠️ The following outbound IPs (IPv4 and IPv6) will become available for
› reuse:
› 1.1.1.1, 2.2.2.2
› Please update the following configurations:
› = IP allowlists
› = Firewall rules
› = Security group configurations
› = Network ACLs
› Ensure all IPv4 and IPv6 addresses are removed from your security
› configurations.
Destroying space my-space...
Destroying space my-space... done
`)
})
})

0 comments on commit 318cf36

Please sign in to comment.