-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(spaces): Move command spaces:peering:info to oclif (#2854)
* Convert peering info to oclif * Update example to reflect whitespace * Rename to satisfy eslint * Update packages/cli/src/lib/spaces/format.ts Co-authored-by: Justin Wilaby <jwilaby@gmail.com> * Fix linting for pg:info test --------- Co-authored-by: Justin Wilaby <jwilaby@gmail.com>
- Loading branch information
1 parent
90caefe
commit aab717c
Showing
8 changed files
with
147 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import {Command, flags} from '@heroku-cli/command' | ||
import {Args, ux} from '@oclif/core' | ||
import * as Heroku from '@heroku-cli/schema' | ||
import heredoc from 'tsheredoc' | ||
import {displayPeeringInfo} from '../../../lib/spaces/peering' | ||
|
||
export default class Info extends Command { | ||
static topic = 'spaces' | ||
static description = heredoc(` | ||
display the information necessary to initiate a peering connection | ||
You will use the information provided by this command to establish a peering connection request from your AWS VPC to your private space. | ||
To start the peering process, go into your AWS console for the VPC you would like peered with your Private Space, | ||
navigate to the VPC service, choose the "Peering Connections" option and click the "Create peering connection" button. | ||
- The AWS Account ID and VPC ID are necessary for the AWS VPC Peering connection wizard. | ||
- You will also need to configure your VPC route table to route the Dyno CIDRs through the peering connection. | ||
Once you've established the peering connection request, you can use the spaces:peerings:accept command to accept and | ||
configure the peering connection for the space. | ||
`) | ||
|
||
static flags = { | ||
space: flags.string({char: 's', description: 'space to get peering info from'}), | ||
json: flags.boolean({description: 'output in json format'}), | ||
} | ||
|
||
static examples = [heredoc(` | ||
$ heroku spaces:peering:info example-space | ||
=== example-space Peering Info | ||
AWS Account ID: 012345678910 | ||
AWS Region: us-west-2 | ||
AWS VPC ID: vpc-baadf00d | ||
AWS VPC CIDR: 10.0.0.0/16 | ||
Space CIDRs: 10.0.128.0/20, 10.0.144.0/20 | ||
Unavailable CIDRs: 10.1.0.0/16 | ||
`)] | ||
|
||
static args = { | ||
space: Args.string({hidden: true}), | ||
} | ||
|
||
public async run(): Promise<void> { | ||
const {flags, args} = await this.parse(Info) | ||
const spaceName = flags.space || args.space | ||
if (!spaceName) { | ||
ux.error(heredoc(` | ||
Error: Missing 1 required arg: | ||
space | ||
See more help with --help | ||
`)) | ||
} | ||
|
||
const {body: pInfo} = await this.heroku.get<Heroku.PeeringInfo>(`/spaces/${spaceName}/peering-info`) | ||
if (flags.json) | ||
ux.log(JSON.stringify(pInfo, null, 2)) | ||
else | ||
displayPeeringInfo(spaceName as string, pInfo) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function displayCIDR(cidr: string[] | undefined) { | ||
return cidr?.join(', ') ?? '' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {ux} from '@oclif/core' | ||
import {displayCIDR} from './format' | ||
import {PeeringInfo} from '@heroku-cli/schema' | ||
|
||
export function displayPeeringInfo(space: string, info: PeeringInfo) { | ||
ux.styledHeader(`${space} Peering Info`) | ||
ux.styledObject({ | ||
'AWS Account ID': info.aws_account_id, | ||
'AWS Region': info.aws_region, | ||
'AWS VPC ID': info.vpc_id, | ||
'AWS VPC CIDR': info.vpc_cidr, | ||
'Space CIDRs': displayCIDR(info.space_cidr_blocks), | ||
'Unavailable CIDRs': displayCIDR(info.unavailable_cidr_blocks), | ||
}, ['AWS Account ID', 'AWS Region', 'AWS VPC ID', 'AWS VPC CIDR', 'Space CIDRs', 'Unavailable CIDRs']) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/cli/test/unit/commands/spaces/peering/info.unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import {stdout} from 'stdout-stderr' | ||
import Cmd from '../../../../../src/commands/spaces/peering/info' | ||
import runCommand from '../../../../helpers/runCommand' | ||
import * as nock from 'nock' | ||
import heredoc from 'tsheredoc' | ||
import expectOutput from '../../../../helpers/utils/expectOutput' | ||
import {expect} from 'chai' | ||
import * as Heroku from '@heroku-cli/schema' | ||
|
||
describe('spaces:peering:info', function () { | ||
let peeringInfo: Heroku.PeeringInfo | ||
|
||
beforeEach(function () { | ||
peeringInfo = { | ||
aws_account_id: '012345678900', | ||
aws_region: 'us-west-2', | ||
vpc_id: 'vpc-1234568a', | ||
vpc_cidr: '10.0.0.0/16', | ||
space_cidr_blocks: ['10.0.128.0/20', '10.0.144.0/20'], | ||
unavailable_cidr_blocks: ['192.168.2.0/30']} | ||
}) | ||
|
||
it('shows space peering info', async function () { | ||
nock('https://api.heroku.com') | ||
.get('/spaces/my-space/peering-info') | ||
.reply(200, peeringInfo) | ||
|
||
await runCommand(Cmd, [ | ||
'--space', | ||
'my-space', | ||
]) | ||
expectOutput(stdout.output, heredoc(` | ||
=== my-space Peering Info | ||
AWS Account ID: ${peeringInfo.aws_account_id} | ||
AWS Region: ${peeringInfo.aws_region} | ||
AWS VPC ID: ${peeringInfo.vpc_id} | ||
AWS VPC CIDR: ${peeringInfo.vpc_cidr} | ||
Space CIDRs: 10.0.128.0/20, 10.0.144.0/20 | ||
Unavailable CIDRs: 192.168.2.0/30 | ||
`)) | ||
}) | ||
|
||
it('shows peering:info --json', async function () { | ||
nock('https://api.heroku.com') | ||
.get('/spaces/my-space/peering-info') | ||
.reply(200, peeringInfo) | ||
|
||
await runCommand(Cmd, [ | ||
'--space', | ||
'my-space', | ||
'--json', | ||
]) | ||
expect(JSON.parse(stdout.output)).to.eql(peeringInfo) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 0 additions & 47 deletions
47
packages/spaces/test/unit/commands/peering/info.unit.test.js
This file was deleted.
Oops, something went wrong.