Skip to content

Commit

Permalink
refactor(certs-v5): move certs:auto:disable to CLI & upgrade to oclif (
Browse files Browse the repository at this point in the history
…#2667)

* Convert certs auto disable to oclif

* Fix test and apply tsheredoc to clean up output

* Make confirm flag hidden
  • Loading branch information
eablack authored Mar 6, 2024
1 parent 058c586 commit 2f8cb84
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 71 deletions.
35 changes: 0 additions & 35 deletions packages/certs-v5/commands/certs/auto/disable.js

This file was deleted.

This file was deleted.

36 changes: 36 additions & 0 deletions packages/cli/src/commands/certs/auto/disable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import color from '@heroku-cli/color'
import {Command, flags} from '@heroku-cli/command'
import {ux} from '@oclif/core'
import confirmApp from '../../../lib/apps/confirm-app'
import heredoc from 'tsheredoc'

export default class Disable extends Command {
static topic = 'certs';
static description = 'disable ACM for an app';
static flags = {
confirm: flags.string({char: 'c', hidden: true}),
app: flags.app({required: true}),
};

public async run(): Promise<void> {
const {flags} = await this.parse(Disable)
const {app, confirm} = flags

const warning = heredoc(`
This command will disable Automatic Certificate Management from ${color.app(app)}.
This will cause the certificate to be removed from ${color.app(app)} causing SSL
validation errors. In order to avoid downtime, the recommended steps
are preferred which will also disable Automatic Certificate Management.
1) Request a new SSL certificate for your domains names from your certificate provider
2) heroku certs:update CRT KEY
`)
await confirmApp(app, confirm, warning)

ux.action.start('Disabling Automatic Certificate Management')
await this.heroku.delete(`/apps/${app}/acm`, {
headers: {Accept: 'application/vnd.heroku+json; version=3.cedar-acm'},
})
ux.action.stop()
}
}
47 changes: 47 additions & 0 deletions packages/cli/test/unit/commands/certs/auto/disable.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {stdout, stderr} from 'stdout-stderr'
import Cmd from '../../../../../src/commands/certs/auto/disable'
import runCommand from '../../../../helpers/runCommand'
import * as nock from 'nock'
import expectOutput from '../../../../helpers/utils/expectOutput'
import stripAnsi = require('strip-ansi')
import {expect} from 'chai'
import heredoc from 'tsheredoc'

describe('heroku certs:auto:disable', function () {
beforeEach(function () {
nock.cleanAll()
})

it('disables acm', async function () {
nock('https://api.heroku.com', {
reqheaders: {
Accept: 'application/vnd.heroku+json; version=3.cedar-acm',
},
})
.delete('/apps/example/acm')
.reply(200, {acm: true})
await runCommand(Cmd, [
'--app',
'example',
'--confirm',
'example',
])
expectOutput(stderr.output, heredoc(`
Disabling Automatic Certificate Management...
Disabling Automatic Certificate Management... done
`))
expectOutput(stdout.output, '')
})

it('confirms that they want to disable', async function () {
await runCommand(Cmd, [
'--app',
'example',
'--confirm',
'notexample',
])
.catch(error => {
expect(stripAnsi(error.message)).to.equal('Confirmation notexample did not match example. Aborted.')
})
})
})

0 comments on commit 2f8cb84

Please sign in to comment.