Skip to content

Commit 05d9742

Browse files
author
Jamie Curnow
committed
Certbot commands
1 parent 177bb2e commit 05d9742

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/backend/internal/certificate.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
const fs = require('fs');
44
const _ = require('lodash');
5+
const logger = require('../logger').ssl;
56
const error = require('../lib/error');
67
const certificateModel = require('../models/certificate');
78
const internalAuditLog = require('./audit-log');
89
const tempWrite = require('temp-write');
910
const utils = require('../lib/utils');
1011
const moment = require('moment');
12+
const debug_mode = process.env.NODE_ENV !== 'production';
13+
const certbot_command = '/usr/bin/certbot';
1114

1215
function omissions () {
1316
return ['is_deleted'];
@@ -483,7 +486,39 @@ const internalCertificate = {
483486
}
484487
});
485488
return meta;
486-
}
489+
},
490+
491+
/**
492+
* @param {Object} certificate the certificate row
493+
* @returns {Promise}
494+
*/
495+
requestLetsEncryptSsl: certificate => {
496+
logger.info('Requesting Let\'sEncrypt certificates for Cert #' + certificate.id + ': ' + certificate.domain_names.join(', '));
497+
498+
return utils.exec(certbot_command + ' certonly --cert-name "npm-' + certificate.id + '" --agree-tos ' +
499+
'--email "' + certificate.meta.letsencrypt_email + '" ' +
500+
'--preferred-challenges "http" ' +
501+
'-n -a webroot -d "' + certificate.domain_names.join(',') + '" ' +
502+
(debug_mode ? '--staging' : ''))
503+
.then(result => {
504+
logger.info(result);
505+
return result;
506+
});
507+
},
508+
509+
/**
510+
* @param {Object} certificate the certificate row
511+
* @returns {Promise}
512+
*/
513+
renewLetsEncryptSsl: certificate => {
514+
logger.info('Renewing Let\'sEncrypt certificates for Cert #' + certificate.id + ': ' + certificate.domain_names.join(', '));
515+
516+
return utils.exec(certbot_command + ' renew -n --force-renewal --disable-hook-validation --cert-name "npm-' + certificate.id + '" ' + (debug_mode ? '--staging' : ''))
517+
.then(result => {
518+
logger.info(result);
519+
return result;
520+
});
521+
},
487522
};
488523

489524
module.exports = internalCertificate;

0 commit comments

Comments
 (0)