2015-12-13 05:03:48 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var PromiseA = require('bluebird');
|
|
|
|
var fs = PromiseA.promisifyAll(require('fs'));
|
|
|
|
|
2015-12-13 08:05:24 +00:00
|
|
|
module.exports.create = function (leBinPath, defaults, opts) {
|
|
|
|
defaults.webroot = true;
|
2015-12-13 05:03:48 +00:00
|
|
|
defaults.renewByDefault = true;
|
2015-12-13 06:39:37 +00:00
|
|
|
defaults.text = true;
|
2015-12-13 05:03:48 +00:00
|
|
|
|
|
|
|
var LEP = require('letsencrypt-python');
|
2015-12-13 08:05:24 +00:00
|
|
|
var lep = PromiseA.promisifyAll(LEP.create(leBinPath, opts));
|
2015-12-13 05:03:48 +00:00
|
|
|
var wrapped = {
|
|
|
|
registerAsync: function (args) {
|
|
|
|
return lep.registerAsync('certonly', args);
|
|
|
|
}
|
|
|
|
, fetchAsync: function (args) {
|
|
|
|
var hostname = args.domains[0];
|
|
|
|
var crtpath = defaults.configDir + defaults.fullchainTpl.replace(/:hostname/, hostname);
|
|
|
|
var privpath = defaults.configDir + defaults.privkeyTpl.replace(/:hostname/, hostname);
|
|
|
|
|
|
|
|
return PromiseA.all([
|
|
|
|
fs.readFileAsync(privpath, 'ascii')
|
|
|
|
, fs.readFileAsync(crtpath, 'ascii')
|
|
|
|
// stat the file, not the link
|
|
|
|
, fs.statAsync(crtpath)
|
|
|
|
]).then(function (arr) {
|
|
|
|
return {
|
|
|
|
key: arr[0] // privkey.pem
|
|
|
|
, cert: arr[1] // fullchain.pem
|
2015-12-13 08:05:24 +00:00
|
|
|
// TODO parse centificate for lifetime / expiresAt
|
2015-12-13 05:03:48 +00:00
|
|
|
, issuedAt: arr[2].mtime.valueOf()
|
|
|
|
};
|
|
|
|
}, function () {
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return wrapped;
|
2015-12-13 08:05:24 +00:00
|
|
|
};
|