UNPKG

1.67 kBJavaScriptView Raw
1'use strict'
2
3let co = require('co')
4let cli = require('heroku-cli-util')
5
6let flags = require('../../lib/flags.js')
7let error = require('../../lib/error.js')
8let displayWarnings = require('../../lib/display_warnings.js')
9let formatEndpoint = require('../../lib/format_endpoint.js')
10let certificateDetails = require('../../lib/certificate_details.js')
11
12function * run (context, heroku) {
13 let endpoint = yield flags(context, heroku)
14 if (endpoint._meta.type === 'SNI') {
15 error.exit(1, 'SNI Endpoints cannot be rolled back, please update with a new cert.')
16 }
17
18 let formattedEndpoint = formatEndpoint(endpoint)
19
20 yield cli.confirmApp(context.app, context.flags.confirm, `Potentially Destructive Action\nThis command will change the certificate of endpoint ${formattedEndpoint} from ${cli.color.app(context.app)}.`)
21
22 let cert = yield cli.action(`Rolling back SSL certificate ${formattedEndpoint} for ${cli.color.app(context.app)}`, {}, heroku.request({
23 path: `/apps/${context.app}/ssl-endpoints/${encodeURIComponent(endpoint.cname)}/rollback`,
24 method: 'POST',
25 headers: {'X-Heroku-API-Version': '2', 'Accept': 'application/json'}
26 }))
27
28 displayWarnings(cert)
29 certificateDetails(cert, 'New active certificate details:')
30}
31
32module.exports = {
33 topic: 'certs',
34 command: 'rollback',
35 flags: [
36 {name: 'confirm', hasValue: true, optional: true, hidden: true},
37 {name: 'name', hasValue: true, description: 'name to rollback'},
38 {name: 'endpoint', hasValue: true, description: 'endpoint to rollback'}
39 ],
40 description: 'rollback an SSL certificate from an app',
41 needsApp: true,
42 needsAuth: true,
43 run: cli.command(co.wrap(run))
44}