diff --git a/packages/cli/src/commands/spaces/drains/get.ts b/packages/cli/src/commands/spaces/drains/get.ts new file mode 100644 index 0000000000..26213a6350 --- /dev/null +++ b/packages/cli/src/commands/spaces/drains/get.ts @@ -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 { + const {flags} = await this.parse(Get) + const {space, json} = flags + const {body: drain} = await this.heroku.get>( + `/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)})`) + } + } +} diff --git a/packages/cli/src/commands/drains/set.ts b/packages/cli/src/commands/spaces/drains/set.ts similarity index 94% rename from packages/cli/src/commands/drains/set.ts rename to packages/cli/src/commands/spaces/drains/set.ts index 4124450b63..7ef4fb9822 100644 --- a/packages/cli/src/commands/drains/set.ts +++ b/packages/cli/src/commands/spaces/drains/set.ts @@ -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 = { diff --git a/packages/cli/src/commands/spaces/outbound-rules/add.ts b/packages/cli/src/commands/spaces/outbound-rules/add.ts index d32892e2ea..dac5c44efb 100644 --- a/packages/cli/src/commands/spaces/outbound-rules/add.ts +++ b/packages/cli/src/commands/spaces/outbound-rules/add.ts @@ -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 @@ -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', diff --git a/packages/cli/src/commands/spaces/outbound-rules/index.ts b/packages/cli/src/commands/spaces/outbound-rules/index.ts index 99f99c3b82..a67616b27f 100644 --- a/packages/cli/src/commands/spaces/outbound-rules/index.ts +++ b/packages/cli/src/commands/spaces/outbound-rules/index.ts @@ -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. @@ -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}), diff --git a/packages/cli/src/commands/spaces/outbound-rules/remove.ts b/packages/cli/src/commands/spaces/outbound-rules/remove.ts index e16e778ac6..d419805247 100644 --- a/packages/cli/src/commands/spaces/outbound-rules/remove.ts +++ b/packages/cli/src/commands/spaces/outbound-rules/remove.ts @@ -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 diff --git a/packages/cli/src/commands/spaces/trusted-ips/add.ts b/packages/cli/src/commands/spaces/trusted-ips/add.ts index b07a5b4d70..3374ef76ed 100644 --- a/packages/cli/src/commands/spaces/trusted-ips/add.ts +++ b/packages/cli/src/commands/spaces/trusted-ips/add.ts @@ -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.`) diff --git a/packages/cli/src/commands/spaces/trusted-ips/index.ts b/packages/cli/src/commands/spaces/trusted-ips/index.ts index 711bb2c02c..41d3ab37d6 100644 --- a/packages/cli/src/commands/spaces/trusted-ips/index.ts +++ b/packages/cli/src/commands/spaces/trusted-ips/index.ts @@ -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. diff --git a/packages/cli/src/commands/spaces/trusted-ips/remove.ts b/packages/cli/src/commands/spaces/trusted-ips/remove.ts index 97bbbd705c..933195cb41 100644 --- a/packages/cli/src/commands/spaces/trusted-ips/remove.ts +++ b/packages/cli/src/commands/spaces/trusted-ips/remove.ts @@ -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.`) diff --git a/packages/cli/test/unit/commands/spaces/drains/get.unit.test.ts b/packages/cli/test/unit/commands/spaces/drains/get.unit.test.ts new file mode 100644 index 0000000000..a371e4bc82 --- /dev/null +++ b/packages/cli/test/unit/commands/spaces/drains/get.unit.test.ts @@ -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) + }) +}) diff --git a/packages/cli/test/unit/commands/drains/set.unit.test.ts b/packages/cli/test/unit/commands/spaces/drains/set.unit.test.ts similarity index 82% rename from packages/cli/test/unit/commands/drains/set.unit.test.ts rename to packages/cli/test/unit/commands/spaces/drains/set.unit.test.ts index c74ca2985b..bfef68b4ef 100644 --- a/packages/cli/test/unit/commands/drains/set.unit.test.ts +++ b/packages/cli/test/unit/commands/spaces/drains/set.unit.test.ts @@ -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', { diff --git a/packages/spaces/commands/drains/get.js b/packages/spaces/commands/drains/get.js deleted file mode 100644 index 21a57b5ace..0000000000 --- a/packages/spaces/commands/drains/get.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict' - -let cli = require('@heroku/heroku-cli-util') - -async function run(context, heroku) { - let lib = require('../../lib/log-drains')(heroku) - let drain = await lib.getLogDrain(context.flags.space) - if (context.flags.json) { - cli.log(JSON.stringify(drain, null, 2)) - } else { - let output = `${cli.color.cyan(drain.url)} (${cli.color.green(drain.token)})` - cli.log(output) - } -} - -module.exports = { - topic: 'drains', - command: 'get', - hidden: true, - description: 'display the log drain for a space', - needsApp: false, - needsAuth: true, - flags: [ - {name: 'space', char: 's', hasValue: true, description: 'space for which to get log drain', required: true}, - {name: 'json', description: 'output in json format'}, - ], - run: cli.command(run), -} diff --git a/packages/spaces/index.js b/packages/spaces/index.js index 62aac7bebb..7af0e8d278 100644 --- a/packages/spaces/index.js +++ b/packages/spaces/index.js @@ -11,5 +11,4 @@ exports.commands = [ require('./commands/vpn/wait'), require('./commands/vpn/destroy'), require('./commands/vpn/update'), - require('./commands/drains/get'), ] diff --git a/packages/spaces/lib/log-drains.js b/packages/spaces/lib/log-drains.js deleted file mode 100644 index d874a12364..0000000000 --- a/packages/spaces/lib/log-drains.js +++ /dev/null @@ -1,14 +0,0 @@ -'use strict' - -module.exports = function (heroku) { - function getLogDrain(space) { - return heroku.request({ - path: `/spaces/${space}/log-drain`, - headers: {Accept: 'application/vnd.heroku+json; version=3.dogwood'}, - }) - } - - return { - getLogDrain, - } -} diff --git a/packages/spaces/test/unit/commands/drains/get.unit.test.js b/packages/spaces/test/unit/commands/drains/get.unit.test.js deleted file mode 100644 index 85622cd8a5..0000000000 --- a/packages/spaces/test/unit/commands/drains/get.unit.test.js +++ /dev/null @@ -1,47 +0,0 @@ -'use strict' -/* globals beforeEach */ - -let nock = require('nock') -let cmd = require('../../../../commands/drains/get') -let expect = require('chai').expect -let cli = require('@heroku/heroku-cli-util') - -describe('drains:get', function () { - beforeEach(() => cli.mockConsole()) - - it('shows the log drain', function () { - let api = nock('https://api.heroku.com:443') - .get('/spaces/my-space/log-drain') - .reply(200, { - 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', - }) - return cmd.run({flags: {space: 'my-space'}}) - .then(() => expect(cli.stdout).to.equal( - `https://example.com (d.a55ecbe1-5513-4d19-91e4-58a08b419d19) -`, - )).then(() => api.done()) - }) - - it('shows the log drain --json', function () { - let 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('https://api.heroku.com:443') - .get('/spaces/my-space/log-drain') - .reply(200, drain) - return cmd.run({flags: {space: 'my-space', json: true}}) - .then(() => expect(JSON.parse(cli.stdout)).to.eql(drain)) - .then(() => api.done()) - }) -})