Skip to content

Commit

Permalink
migrate(W-14169233): spaces: Upgrade drains:set (#2851)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinwilaby authored Apr 30, 2024
1 parent 89201a4 commit ed67ab2
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 71 deletions.
29 changes: 29 additions & 0 deletions packages/cli/src/commands/drains/set.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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'

export default class Set extends Command {
static topic = 'drains'
static hidden = true
static description = 'replaces the log drain for a space'
static flags = {
space: flags.string({char: 's', description: 'space for which to set log drain', required: true}),
}

static args = {
url: Args.string({required: true}),
}

public async run(): Promise<void> {
const {flags, args} = await this.parse(Set)
const {url} = args
const {space} = flags
const {body: drain} = await this.heroku.put<Heroku.LogDrain>(`/spaces/${space}/log-drain`, {
body: {url},
headers: {Accept: 'application/vnd.heroku+json; version=3.dogwood'},
})
ux.log(`Successfully set drain ${color.cyan(drain.url)} for ${color.cyan.bold(space)}.`)
ux.warn('It may take a few moments for the changes to take effect.')
}
}
25 changes: 25 additions & 0 deletions packages/cli/test/unit/commands/drains/set.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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'

describe('drains:set', function () {
it('shows the log drain', async function () {
const api = nock('https://api.heroku.com:443')
.put('/spaces/my-space/log-drain', {
url: 'https://example.com',
})
.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',
})
await runCommand(Cmd, ['https://example.com', '--space', 'my-space'])
expect(stdout.output).to.equal('Successfully set drain https://example.com for my-space.\n')
api.done()
})
})
27 changes: 0 additions & 27 deletions packages/spaces/commands/drains/set.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 @@ -19,7 +19,6 @@ exports.commands = [
require('./commands/vpn/update'),
require('./commands/transfer'),
require('./commands/drains/get'),
require('./commands/drains/set'),
require('./commands/trusted-ips'),
require('./commands/trusted-ips/add'),
require('./commands/trusted-ips/remove'),
Expand Down
12 changes: 0 additions & 12 deletions packages/spaces/lib/log-drains.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,7 @@ module.exports = function (heroku) {
})
}

function putLogDrain(space, url) {
return heroku.request({
method: 'PUT',
path: `/spaces/${space}/log-drain`,
body: {
url: url,
},
headers: {Accept: 'application/vnd.heroku+json; version=3.dogwood'},
})
}

return {
getLogDrain,
putLogDrain,
}
}
31 changes: 0 additions & 31 deletions packages/spaces/test/unit/commands/drains/set.unit.test.js

This file was deleted.

0 comments on commit ed67ab2

Please sign in to comment.