greenlock.js/lib/common.js

45 lines
1.6 KiB
JavaScript
Raw Normal View History

2015-12-15 15:21:27 +00:00
'use strict';
var fs = require('fs');
var PromiseA = require('bluebird');
module.exports.fetchFromDisk = function (args, defaults) {
var hostname = args.domains[0];
var certPath = (args.fullchainPath || defaults.fullchainPath)
2015-12-16 12:57:53 +00:00
|| (defaults.configDir
+ (args.fullchainTpl || defaults.fullchainTpl || ':hostname/fullchain.pem').replace(/:hostname/, hostname));
var privkeyPath = (args.privkeyPath || defaults.privkeyPath)
2015-12-16 12:57:53 +00:00
|| (defaults.configDir
+ (args.privkeyTpl || defaults.privkeyTpl || ':hostname/privkey.pem').replace(/:hostname/, hostname));
var chainPath = (args.chainPath || defaults.chainPath)
|| (defaults.configDir
+ (args.chainTpl || defaults.chainTpl || ':hostname/chain.pem').replace(/:hostname/, hostname));
/*
var fullchainPath = (args.fullchainPath || defaults.fullchainPath)
|| (defaults.configDir
+ (args.fullchainTpl || defaults.fullchainTpl || ':hostname/fullchain.pem').replace(/:hostname/, hostname));
*/
2015-12-15 15:21:27 +00:00
return PromiseA.all([
fs.readFileAsync(privkeyPath, 'ascii')
, fs.readFileAsync(certPath, 'ascii')
, fs.readFileAsync(chainPath, 'ascii')
//, fs.readFileAsync(fullchainPath, 'ascii')
2015-12-15 15:21:27 +00:00
// stat the file, not the link
, fs.statAsync(certPath)
2015-12-15 15:21:27 +00:00
]).then(function (arr) {
// TODO parse certificate to determine lifetime and expiresAt
2015-12-15 15:21:27 +00:00
return {
key: arr[0] // privkey.pem
, cert: arr[1] // cert.pem
, chain: arr[2] // chain.pem
, fullchain: arr[1] + '\n' + arr[2] // fullchain.pem
, issuedAt: arr[4].mtime.valueOf() // ???
2015-12-15 15:21:27 +00:00
};
}, function () {
return null;
});
};