-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(certs-v5): move certs:auto:disable to CLI & upgrade to oclif (…
…#2667) * Convert certs auto disable to oclif * Fix test and apply tsheredoc to clean up output * Make confirm flag hidden
- Loading branch information
Showing
4 changed files
with
83 additions
and
71 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
packages/certs-v5/test/unit/commands/certs/auto/disable.unit.test.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
47
packages/cli/test/unit/commands/certs/auto/disable.unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.') | ||
}) | ||
}) | ||
}) |