-
-
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.
feat(nginx): move letsencrypt to its own file, add ssl renew command
refs #190 - adds ssl-renew command
- Loading branch information
Showing
3 changed files
with
45 additions
and
12 deletions.
There are no files selected for viewing
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,22 @@ | ||
'use strict'; | ||
const cli = require('../../../lib'); | ||
const letsencrypt = require('../letsencrypt'); | ||
|
||
class SslRenewCommand extends cli.Command { | ||
run() { | ||
let instance = this.system.getInstance(); | ||
|
||
if (!instance.cliConfig.has('extension.sslemail')) { | ||
return Promise.reject(new cli.errors.SystemError('No saved email found, skipping automatic letsencrypt renewal')); | ||
} | ||
|
||
let email = instance.cliConfig.get('extension.sslemail'); | ||
return this.ui.run(letsencrypt(instance, email, false), 'Renewing SSL certificate') | ||
.catch((error) => Promise.reject(new cli.errors.ProcessError(error))); | ||
} | ||
} | ||
|
||
SslRenewCommand.description = 'Renew an SSL certificate for a Ghost installation'; | ||
|
||
module.exports = SslRenewCommand; | ||
|
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
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,20 @@ | ||
'use strict'; | ||
const url = require('url'); | ||
const path = require('path'); | ||
const execa = require('execa'); | ||
|
||
const LIVE_URL = 'https://acme-v01.api.letsencrypt.org/directory'; | ||
const STAGING_URL = 'https://acme-staging.api.letsencrypt.org/directory'; | ||
|
||
module.exports = function letsencrypt(instance, email, staging) { | ||
let hostname = url.parse(instance.config.get('url')).hostname; | ||
let rootPath = path.resolve(instance.dir, 'system', 'nginx-root'); | ||
let letsencryptFolder = path.join(instance.dir, 'system', 'letsencrypt'); | ||
let sslGenArgs = `certonly --agree-tos --email ${email} --webroot --webroot-path ${rootPath}` + | ||
` --config-dir ${letsencryptFolder} --domains ${hostname} --server ${staging ? STAGING_URL : LIVE_URL}`; | ||
|
||
return execa('greenlock', sslGenArgs.split(' '), { | ||
preferLocal: true, | ||
localDir: __dirname | ||
}); | ||
}; |