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

refactor(spaces): Move command 'spaces:drains:get' to CLI #2871

Merged
merged 4 commits 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
30 changes: 30 additions & 0 deletions packages/cli/src/commands/spaces/drains/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import color from '@heroku-cli/color'
import {Command, flags} from '@heroku-cli/command'
import {ux} from '@oclif/core'
import * as Heroku from '@heroku-cli/schema'

export default class Get extends Command {
static topic = 'spaces'
static aliases = ['drains:get']
static hidden = true
static description = 'display the log drain for a space'
static flags = {
space: flags.string({char: 's', description: 'space for which to get log drain', required: true}),
json: flags.boolean({description: 'output in json format'}),
}

public async run(): Promise<void> {
const {flags} = await this.parse(Get)
const {space, json} = flags
const {body: drain} = await this.heroku.get<Required<Heroku.LogDrain>>(
`/spaces/${space}/log-drain`,
{headers: {Accept: 'application/vnd.heroku+json; version=3.dogwood'}},
)

if (json) {
ux.log(JSON.stringify(drain, null, 2))
} else {
ux.log(`${color.cyan(drain.url)} (${color.green(drain.token)})`)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {Args, ux} from '@oclif/core'
import * as Heroku from '@heroku-cli/schema'

export default class Set extends Command {
static topic = 'drains'
static topic = 'spaces'
static aliases = ['drains:set']
static hidden = true
static description = 'replaces the log drain for a space'
static flags = {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/spaces/outbound-rules/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {SpaceCompletion} from '@heroku-cli/command/lib/completions'
import {ProtocolCompletion} from '../../../lib/autocomplete/completions'

export default class Add extends Command {
static topic = 'outbound-rules'
static topic = 'spaces'
static aliases = ['outbound-rules:add']
static description = heredoc(`
Add outbound rules to a Private Space

Expand Down Expand Up @@ -38,7 +39,6 @@ export default class Add extends Command {
]

static hidden = true
static aliases = ['outbound-rules:add']
static flags = {
space: flags.string({
char: 's',
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/spaces/outbound-rules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import * as Heroku from '@heroku-cli/schema'
import {SpaceCompletion} from '@heroku-cli/command/lib/completions'

export default class Index extends Command {
static topic = 'spaces'
static aliases = ['outbound-rules']
static description = heredoc(`
list Outbound Rules for a space
Outbound Rules are only available on Private Spaces.
Expand All @@ -18,7 +20,6 @@ export default class Index extends Command {
You can add specific rules that only allow your dyno to communicate with trusted hosts.
`)

static aliases = ['outbound-rules']
static hidden = true
static flags = {
space: flags.string({char: 's', description: 'space to get outbound rules from', completion: SpaceCompletion}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import heredoc from 'tsheredoc'
import confirmCommand from '../../../lib/confirmCommand'

export default class Remove extends Command {
static topic = 'spaces'
static aliases = ['outbound-rules:remove']
static topic = 'outbound-rules'
static description = 'Remove a Rules from the list of Outbound Rules';
static examples = [heredoc(`
$ heroku outbound-rules:remove --space my-space 4
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/spaces/trusted-ips/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import * as Heroku from '@heroku-cli/schema'
import heredoc from 'tsheredoc'

export default class Add extends Command {
static topic = 'spaces'
static aliases = ['trusted-ips:add']
static topic = 'trusted-ips'
static description = heredoc(`
Add one range to the list of trusted IP ranges
Uses CIDR notation.`)
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/spaces/trusted-ips/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as Heroku from '@heroku-cli/schema'
import heredoc from 'tsheredoc'

export default class Index extends Command {
static topic = 'spaces'
static aliases = ['trusted-ips']
static topic = 'trusted-ips'
static description = heredoc(`
list trusted IP ranges for a space
Trusted IP ranges are only available on Private Spaces.
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/spaces/trusted-ips/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import * as Heroku from '@heroku-cli/schema'
import heredoc from 'tsheredoc'

export default class Remove extends Command {
static topic = 'spaces'
static aliases = ['trusted-ips:remove']
static topic = 'trusted-ips'
static description = heredoc(`
Remove a range from the list of trusted IP ranges
Uses CIDR notation.`)
Expand Down
47 changes: 47 additions & 0 deletions packages/cli/test/unit/commands/spaces/drains/get.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {stdout} from 'stdout-stderr'
import runCommand from '../../../../helpers/runCommand'
import Cmd from '../../../../../src/commands/spaces/drains/get'
import {expect} from 'chai'
import * as nock from 'nock'

describe('spaces:drains:get', function () {
const drain = {
addon: null,
created_at: '2016-03-23T18:31:50Z',
id: '047f80cc-0470-4564-b0cb-e9ad7605314a',
token: 'd.a55ecbe1-5513-4d19-91e4-58a08b419d19',
updated_at: '2016-03-23T18:31:50Z',
url: 'https://example.com',
}
let api: nock.Scope

beforeEach(function () {
api = nock('https://api.heroku.com')
.get('/spaces/my-space/log-drain')
.reply(200, drain)
})

afterEach(function () {
api.done()
nock.cleanAll()
})

it('shows the log drain', async function () {
await runCommand(Cmd, [
'--space',
'my-space',
])

expect(stdout.output).to.eq('https://example.com (d.a55ecbe1-5513-4d19-91e4-58a08b419d19)\n')
})

it('shows the log drain --json', async function () {
await runCommand(Cmd, [
'--space',
'my-space',
'--json',
])

expect(JSON.parse(stdout.output)).to.eql(drain)
})
})
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {expect} from '@oclif/test'
import * as nock from 'nock'
import {stdout} from 'stdout-stderr'
import runCommand from '../../../helpers/runCommand'
import Cmd from '../../../../src/commands/drains/set'
import runCommand from '../../../../helpers/runCommand'
import Cmd from '../../../../../src/commands/spaces/drains/set'

describe('drains:set', function () {
describe('spaces:drains:set', function () {
it('shows the log drain', async function () {
const api = nock('https://api.heroku.com:443')
.put('/spaces/my-space/log-drain', {
Expand Down
28 changes: 0 additions & 28 deletions packages/spaces/commands/drains/get.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 @@ -11,5 +11,4 @@ exports.commands = [
require('./commands/vpn/wait'),
require('./commands/vpn/destroy'),
require('./commands/vpn/update'),
require('./commands/drains/get'),
]
14 changes: 0 additions & 14 deletions packages/spaces/lib/log-drains.js

This file was deleted.

47 changes: 0 additions & 47 deletions packages/spaces/test/unit/commands/drains/get.unit.test.js

This file was deleted.

Loading