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

add generation to spaces:create #3040

Merged
merged 2 commits into from
Oct 17, 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
39 changes: 26 additions & 13 deletions packages/cli/src/commands/spaces/create.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import color from '@heroku-cli/color'
import {Command, flags} from '@heroku-cli/command'
import {Args, ux} from '@oclif/core'
import * as Heroku from '@heroku-cli/schema'
import {Space} from '../../lib/types/fir'
import heredoc from 'tsheredoc'
import {displayShieldState} from '../../lib/spaces/spaces'
import {RegionCompletion} from '../../lib/autocomplete/completions'
Expand All @@ -28,15 +28,16 @@ export default class Create extends Command {
`]

static flags = {
space: flags.string({char: 's', description: 'name of space to create'}),
channel: flags.string({hidden: true}),
region: flags.string({description: 'region name', completion: RegionCompletion}),
features: flags.string({hidden: true, description: 'a list of features separated by commas'}),
'log-drain-url': flags.string({hidden: true, description: 'direct log drain url'}),
shield: flags.boolean({hidden: true, description: 'create a Shield space'}),
cidr: flags.string({description: 'RFC-1918 CIDR the space will use'}),
'kpi-url': flags.string({hidden: true, description: 'self-managed KPI endpoint to use'}),
'data-cidr': flags.string({description: 'RFC-1918 CIDR used by Heroku Data resources for the space'}),
// features: flags.string({hidden: true, description: 'a list of features separated by commas'}),
generation: flags.string({description: 'generation for space', default: 'cedar', options: ['cedar', 'fir']}),
'kpi-url': flags.string({hidden: true, description: 'self-managed KPI endpoint to use'}),
'log-drain-url': flags.string({hidden: true, description: 'direct log drain url'}),
region: flags.string({description: 'region name', completion: RegionCompletion}),
shield: flags.boolean({hidden: true, description: 'create a Shield space'}),
space: flags.string({char: 's', description: 'name of space to create'}),
team: flags.team({required: true}),
}

Expand All @@ -46,7 +47,7 @@ export default class Create extends Command {

public async run(): Promise<void> {
const {flags, args} = await this.parse(Create)
const {channel, region, features, 'log-drain-url': logDrainUrl, shield, cidr, 'kpi-url': kpiUrl, 'data-cidr': dataCidr, team} = flags
const {channel, region, features, generation, 'log-drain-url': logDrainUrl, shield, cidr, 'kpi-url': kpiUrl, 'data-cidr': dataCidr, team} = flags
const spaceName = flags.space || args.space

if (!spaceName) {
Expand All @@ -61,10 +62,22 @@ export default class Create extends Command {
const spaceType = shield ? 'Shield' : 'Standard'

ux.action.start(`Creating space ${color.green(spaceName as string)} in team ${color.cyan(team as string)}`)
const {body: space} = await this.heroku.post<Required<Heroku.Space>>('/spaces', {
const {body: space} = await this.heroku.post<Required<Space>>('/spaces', {
headers: {
Accept: 'application/vnd.heroku+json; version=3.sdk',
},
body: {
name: spaceName, team: team, channel_name: channel, region: region, features: splitCsv(features),
log_drain_url: logDrainUrl, shield, cidr, kpi_url: kpiUrl, data_cidr: dataCidr,
channel_name: channel,
cidr,
data_cidr: dataCidr,
// features: splitCsv(features),
generation,
kpi_url: kpiUrl,
log_drain_url: logDrainUrl,
name: spaceName,
region,
shield,
team,
},
})
ux.action.stop()
Expand All @@ -74,7 +87,7 @@ export default class Create extends Command {

ux.styledHeader(space.name)
ux.styledObject({
ID: space.id, Team: space.team.name, Region: space.region.name, CIDR: space.cidr, 'Data CIDR': space.data_cidr, State: space.state, Shield: displayShieldState(space), 'Created at': space.created_at,
}, ['ID', 'Team', 'Region', 'CIDR', 'Data CIDR', 'State', 'Shield', 'Created at'])
ID: space.id, Team: space.team.name, Region: space.region.name, CIDR: space.cidr, 'Data CIDR': space.data_cidr, State: space.state, Shield: displayShieldState(space), Generation: space.generation, 'Created at': space.created_at,
}, ['ID', 'Team', 'Region', 'CIDR', 'Data CIDR', 'State', 'Shield', 'Generation', 'Created at'])
}
}
115 changes: 88 additions & 27 deletions packages/cli/test/unit/commands/spaces/create.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@ describe('spaces:create', function () {
})

it('creates a Standard space', async function () {
const api = nock('https://api.heroku.com')
const api = nock('https://api.heroku.com', {reqheaders: {Accept: 'application/vnd.heroku+json; version=3.sdk'}})
.post('/spaces', {
// features: features,
generation: 'cedar',
name: 'my-space',
team: 'my-team',
region: 'my-region',
features: features,
team: 'my-team',
})
.reply(201, {
shield: false,
name: 'my-space',
team: {name: 'my-team'},
region: {name: 'my-region'},
features: ['one', 'two'],
// features: ['one', 'two'],
generation: 'cedar',
state: 'allocated',
created_at: now,
cidr: '10.0.0.0/16',
Expand All @@ -37,7 +39,7 @@ describe('spaces:create', function () {
'--team=my-team',
'--space=my-space',
'--region=my-region',
'--features=one, two',
// '--features=one, two',
])

api.done()
Expand All @@ -51,24 +53,27 @@ describe('spaces:create', function () {
Data CIDR: 172.23.0.0/20
State: allocated
Shield: off
Generation: cedar
Created at: ${now.toISOString()}
`)
})

it('shows Standard Private Space Add-on cost warning', async function () {
const api = nock('https://api.heroku.com')
const api = nock('https://api.heroku.com', {reqheaders: {Accept: 'application/vnd.heroku+json; version=3.sdk'}})
.post('/spaces', {
// features: features,
generation: 'cedar',
name: 'my-space',
team: 'my-team',
region: 'my-region',
features: features,
team: 'my-team',
})
.reply(201, {
shield: false,
name: 'my-space',
team: {name: 'my-team'},
region: {name: 'my-region'},
features: ['one', 'two'],
// features: ['one', 'two'],
generation: 'cedar',
state: 'allocated',
created_at: now,
cidr: '10.0.0.0/16',
Expand All @@ -79,7 +84,7 @@ describe('spaces:create', function () {
'--team=my-team',
'--space=my-space',
'--region=my-region',
'--features=one, two',
// '--features=one, two',
])

api.done()
Expand All @@ -90,20 +95,22 @@ describe('spaces:create', function () {
})

it('creates a Shield space', async function () {
const api = nock('https://api.heroku.com')
const api = nock('https://api.heroku.com', {reqheaders: {Accept: 'application/vnd.heroku+json; version=3.sdk'}})
.post('/spaces', {
// features: features,
generation: 'cedar',
name: 'my-space',
team: 'my-team',
region: 'my-region',
features: features,
shield: true,
team: 'my-team',
})
.reply(201, {
shield: true,
name: 'my-space',
team: {name: 'my-team'},
region: {name: 'my-region'},
features: ['one', 'two'],
// features: ['one', 'two'],
generation: 'cedar',
state: 'allocated',
created_at: now,
cidr: '10.0.0.0/16',
Expand All @@ -114,7 +121,7 @@ describe('spaces:create', function () {
'--team=my-team',
'--space=my-space',
'--region=my-region',
'--features=one, two',
// '--features=one, two',
'--shield',
])

Expand All @@ -129,25 +136,28 @@ describe('spaces:create', function () {
Data CIDR: 172.23.0.0/20
State: allocated
Shield: on
Generation: cedar
Created at: ${now.toISOString()}
`)
})

it('shows Shield Private Space Add-on cost warning', async function () {
const api = nock('https://api.heroku.com')
const api = nock('https://api.heroku.com', {reqheaders: {Accept: 'application/vnd.heroku+json; version=3.sdk'}})
.post('/spaces', {
// features: features,
generation: 'cedar',
name: 'my-space',
team: 'my-team',
region: 'my-region',
features: features,
shield: true,
team: 'my-team',
})
.reply(201, {
shield: true,
name: 'my-space',
team: {name: 'my-team'},
region: {name: 'my-region'},
features: ['one', 'two'],
// features: ['one', 'two'],
generation: 'cedar',
state: 'allocated',
created_at: now,
cidr: '10.0.0.0/16',
Expand All @@ -158,7 +168,7 @@ describe('spaces:create', function () {
'--team=my-team',
'--space=my-space',
'--region=my-region',
'--features=one, two',
// '--features=one, two',
'--shield',
])

Expand All @@ -170,21 +180,22 @@ describe('spaces:create', function () {
})

it('creates a space with custom cidr and data cidr', async function () {
const api = nock('https://api.heroku.com')
const api = nock('https://api.heroku.com', {reqheaders: {Accept: 'application/vnd.heroku+json; version=3.sdk'}})
.post('/spaces', {
name: 'my-space',
team: 'my-team',
region: 'my-region',
cidr: '10.0.0.0/24',
data_cidr: '172.23.0.0/28',
features: features,
// features: features,
generation: 'cedar',
name: 'my-space',
region: 'my-region',
team: 'my-team',
})
.reply(201, {
shield: false,
name: 'my-space',
team: {name: 'my-team'},
region: {name: 'my-region'},
features: ['one', 'two'],
// features: ['one', 'two'],
state: 'allocated',
created_at: now,
cidr: '10.0.0.0/24',
Expand All @@ -195,7 +206,7 @@ describe('spaces:create', function () {
'--team=my-team',
'--space=my-space',
'--region=my-region',
'--features=one, two',
// '--features=one, two',
'--cidr=10.0.0.0/24',
'--data-cidr=172.23.0.0/28',
])
Expand All @@ -214,4 +225,54 @@ describe('spaces:create', function () {
Created at: ${now.toISOString()}
`)
})

it('creates a fir space', async function () {
const firSpace = {
cidr: '10.0.0.0/16',
created_at: now,
data_cidr: '172.23.0.0/20',
// features: ['one', 'two'],
generation: 'fir',
name: 'my-space',
region: {name: 'my-region'},
shield: false,
state: 'allocated',
team: {name: 'my-team'},
}
nock('https://api.heroku.com', {reqheaders: {Accept: 'application/vnd.heroku+json; version=3.sdk'}})
.post('/spaces', {
// features: firSpace.features,
generation: firSpace.generation,
name: firSpace.name,
region: firSpace.region.name,
team: firSpace.team.name,
})
.reply(201, firSpace)

await runCommand(Cmd, [
'--team',
firSpace.team.name,
'--space',
firSpace.name,
'--region',
firSpace.region.name,
// '--features',
// firSpace.features.join(','),
'--generation',
firSpace.generation,
])

expect(stdout.output).to.eq(heredoc`
=== ${firSpace.name}

Team: ${firSpace.team.name}
Region: ${firSpace.region.name}
CIDR: ${firSpace.cidr}
Data CIDR: ${firSpace.data_cidr}
State: ${firSpace.state}
Shield: off
Generation: ${firSpace.generation}
Created at: ${now.toISOString()}
`)
})
})
Loading