almost there

This commit is contained in:
AJ ONeal 2016-08-05 18:54:28 -04:00
parent 56736c4f98
commit ae91c08dd1
2 changed files with 7 additions and 20 deletions

View File

@ -1,16 +1,8 @@
'use strict'; 'use strict';
var LE = require('../'); module.exports.create = function (le) {
var ipc = {}; // in-process cache
module.exports.create = function (defaults, handlers, backend) {
var backendDefaults = backend.getDefaults && backend.getDefaults || backend.defaults || {};
defaults.server = defaults.server || LE.liveServer;
handlers.merge = require('./common').merge;
handlers.tplCopy = require('./common').tplCopy;
var PromiseA = require('bluebird'); var PromiseA = require('bluebird');
var utils = require('./utils'); // merge, tplCopy;
var RSA = PromiseA.promisifyAll(require('rsa-compat').RSA); var RSA = PromiseA.promisifyAll(require('rsa-compat').RSA);
var LeCore = PromiseA.promisifyAll(require('letiny-core')); var LeCore = PromiseA.promisifyAll(require('letiny-core'));
var crypto = require('crypto'); var crypto = require('crypto');
@ -28,8 +20,6 @@ module.exports.create = function (defaults, handlers, backend) {
} }
function createAccount(args, handlers) { function createAccount(args, handlers) {
args.rsaKeySize = args.rsaKeySize || 2048;
return RSA.generateKeypairAsync(args.rsaKeySize, 65537, { public: true, pem: true }).then(function (keypair) { return RSA.generateKeypairAsync(args.rsaKeySize, 65537, { public: true, pem: true }).then(function (keypair) {
return LeCore.registerNewAccountAsync({ return LeCore.registerNewAccountAsync({
@ -73,21 +63,19 @@ module.exports.create = function (defaults, handlers, backend) {
var now = Date.now(); var now = Date.now();
// TODO check response header on request for cache time // TODO check response header on request for cache time
if ((now - ipc.acmeUrlsUpdatedAt) < 10 * 60 * 1000) { if ((now - le._ipc.acmeUrlsUpdatedAt) < 10 * 60 * 1000) {
return PromiseA.resolve(ipc.acmeUrls); return PromiseA.resolve(le._ipc.acmeUrls);
} }
return LeCore.getAcmeUrlsAsync(args.server).then(function (data) { return LeCore.getAcmeUrlsAsync(args.server).then(function (data) {
ipc.acmeUrlsUpdatedAt = Date.now(); le._ipc.acmeUrlsUpdatedAt = Date.now();
ipc.acmeUrls = data; le._ipc.acmeUrls = data;
return ipc.acmeUrls; return le._ipc.acmeUrls;
}); });
} }
function getCertificateAsync(args, defaults, handlers) { function getCertificateAsync(args, defaults, handlers) {
args.rsaKeySize = args.rsaKeySize || 2048;
args.challengeType = args.challengeType || 'http-01';
function log() { function log() {
if (args.debug || defaults.debug) { if (args.debug || defaults.debug) {
@ -223,7 +211,6 @@ module.exports.create = function (defaults, handlers, backend) {
var wrapped = { var wrapped = {
registerAsync: function (args) { registerAsync: function (args) {
var utils = require('./lib/common');
var err; var err;
if (!Array.isArray(args.domains)) { if (!Array.isArray(args.domains)) {