Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move command 'spaces:vpn:connect' to CLI #2873

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions packages/cli/src/commands/spaces/vpn/connect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import color from '@heroku-cli/color'
import {Command, flags} from '@heroku-cli/command'
import {Args, ux} from '@oclif/core'
import heredoc from 'tsheredoc'
import {splitCsv} from '../../../lib/spaces/parsers'

export default class Connect extends Command {
static topic = 'spaces'
static description = heredoc`
create VPN
Private Spaces can be connected to another private network via an IPSec VPN connection allowing dynos to connect to hosts on your private networks and vice versa.
The connection is established over the public Internet but all traffic is encrypted using IPSec.
`
static examples = [heredoc`
$ heroku spaces:vpn:connect --name office --ip 35.161.69.30 --cidrs 172.16.0.0/16,10.0.0.0/24 --space my-space
Creating VPN Connection in space my-space... done
▸ Use spaces:vpn:wait to track allocation.
`]

static flags = {
ip: flags.string({char: 'i', description: 'public IP of customer gateway', required: true}),
cidrs: flags.string({char: 'c', description: 'a list of routable CIDRs separated by commas', required: true}),
space: flags.string({char: 's', description: 'space name', required: true}),
}

static args = {
name: Args.string({required: true}),
}

public async run(): Promise<void> {
const {flags, args} = await this.parse(Connect)
const {space, cidrs, ip} = flags
const {name} = args
const parsed_cidrs = splitCsv(cidrs)

ux.action.start(`Creating VPN Connection in space ${color.green(space)}`)
await this.heroku.post(`/spaces/${space}/vpn-connections`, {
body: {
name,
public_ip: ip,
routable_cidrs: parsed_cidrs,
},
})
ux.action.stop()

ux.warn(`Use ${color.cmd('heroku spaces:vpn:wait')} to track allocation.`)
}
}
40 changes: 40 additions & 0 deletions packages/cli/test/unit/commands/spaces/vpn/connect.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {stderr} from 'stdout-stderr'
import Cmd from '../../../../../src/commands/spaces/vpn/connect'
import runCommand from '../../../../helpers/runCommand'
import * as nock from 'nock'
import heredoc from 'tsheredoc'
import {expect} from 'chai'
import stripAnsi = require('strip-ansi')

describe('spaces:vpn:connect', function () {
it('creates a VPN', async function () {
const api = nock('https://api.heroku.com')
.post('/spaces/my-space/vpn-connections', {
name: 'office',
public_ip: '192.168.0.1',
routable_cidrs: ['192.168.0.1/16', '192.168.0.2/16'],
})
.reply(201)

await runCommand(Cmd, [
'office',
'--space',
'my-space',
'--ip',
'192.168.0.1',
'--cidrs',
'192.168.0.1/16,192.168.0.2/16',
])

api.done()
expect(stderr.output).to.contain(heredoc`
Creating VPN Connection in space my-space...
Creating VPN Connection in space my-space... done
`)
expect(stripAnsi(stderr.output)).to.contain(heredoc`
Use heroku spaces:vpn:wait to track allocation.
`)

nock.cleanAll()
})
})
52 changes: 0 additions & 52 deletions packages/spaces/commands/vpn/connect.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/spaces/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ exports.topics = [
]

exports.commands = [
require('./commands/vpn/connect'),
require('./commands/vpn/index'),
require('./commands/vpn/wait'),
require('./commands/vpn/destroy'),
Expand Down
31 changes: 0 additions & 31 deletions packages/spaces/test/unit/commands/vpn/connect.unit.test.js

This file was deleted.

Loading