Skip to content

Commit

Permalink
Convert certs auto disable to oclif
Browse files Browse the repository at this point in the history
  • Loading branch information
eablack committed Mar 1, 2024
1 parent e509fd6 commit f38f2f7
Show file tree
Hide file tree
Showing 4 changed files with 68 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.

27 changes: 27 additions & 0 deletions packages/cli/src/commands/certs/auto/disable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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'

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

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

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

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()
}
}
41 changes: 41 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,41 @@
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'

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, '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 f38f2f7

Please sign in to comment.