Skip to content

Commit

Permalink
Move trusted-ip commands to use v3. (#3086)
Browse files Browse the repository at this point in the history
  • Loading branch information
eablack authored Nov 12, 2024
1 parent f7db68e commit 4f7472f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/commands/spaces/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class Create extends Command {
CIDR: 10.0.0.0/16
Data CIDR: 172.23.0.0/20
State: allocating
Generation: fir
Generation: cedar
Created at: 2016-01-06T03:23:13Z
`]

Expand Down
7 changes: 2 additions & 5 deletions packages/cli/src/commands/spaces/trusted-ips/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@ export default class Add extends Command {
const {flags, args} = await this.parse(Add)
const {space} = flags
const url = `/spaces/${space}/inbound-ruleset`
const options = {
headers: {Accept: 'application/vnd.heroku+json; version=3.dogwood'},
}
const {body: ruleset} = await this.heroku.get<Heroku.InboundRuleset>(url, options)
const {body: ruleset} = await this.heroku.get<Heroku.InboundRuleset>(url)
if (!this.isUniqueRule(ruleset, args.source)) {
throw new Error(`A rule already exists for ${args.source}.`)
}

ruleset.rules.push({action: 'allow', source: args.source})
await this.heroku.put(url, {...options, body: ruleset})
await this.heroku.put(url, {body: ruleset})
ux.log(`Added ${color.cyan.bold(args.source)} to trusted IP ranges on ${color.cyan.bold(space)}`)
ux.warn('It may take a few moments for the changes to take effect.')
}
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/src/commands/spaces/trusted-ips/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ export default class Index extends Command {
throw new Error('Space name required.\nUSAGE: heroku trusted-ips my-space')
}

const {body: rules} = await this.heroku.get<Required<Heroku.InboundRuleset>>(`/spaces/${space}/inbound-ruleset`,
{
headers: {Accept: 'application/vnd.heroku+json; version=3.dogwood'},
})
const {body: rules} = await this.heroku.get<Required<Heroku.InboundRuleset>>(`/spaces/${space}/inbound-ruleset`)

if (flags.json) {
ux.log(JSON.stringify(rules, null, 2))
Expand Down
5 changes: 2 additions & 3 deletions packages/cli/src/commands/spaces/trusted-ips/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ export default class Remove extends Command {
const {flags, args} = await this.parse(Remove)
const space = flags.space
const url = `/spaces/${space}/inbound-ruleset`
const opts = {headers: {Accept: 'application/vnd.heroku+json; version=3.dogwood'}}
const {body: rules} = await this.heroku.get<Heroku.InboundRuleset>(url, opts)
const {body: rules} = await this.heroku.get<Heroku.InboundRuleset>(url)
if (rules.rules?.length === 0) {
throw new Error('No IP ranges are configured. Nothing to do.')
}
Expand All @@ -41,7 +40,7 @@ export default class Remove extends Command {
throw new Error(`No IP range matching ${args.source} was found.`)
}

await this.heroku.put(url, {...opts, body: rules})
await this.heroku.put(url, {body: rules})
ux.log(`Removed ${color.cyan.bold(args.source)} from trusted IP ranges on ${color.cyan.bold(space)}`)
ux.warn('It may take a few moments for the changes to take effect.')
}
Expand Down

0 comments on commit 4f7472f

Please sign in to comment.