From ae91c08dd1bee3850917c56bc60f16c65c5b718e Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 5 Aug 2016 18:54:28 -0400 Subject: [PATCH] almost there --- lib/core.js | 27 +++++++-------------------- lib/{common.js => utils.js} | 0 2 files changed, 7 insertions(+), 20 deletions(-) rename lib/{common.js => utils.js} (100%) diff --git a/lib/core.js b/lib/core.js index 93d73b6..a6ec745 100644 --- a/lib/core.js +++ b/lib/core.js @@ -1,16 +1,8 @@ 'use strict'; -var LE = require('../'); -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; - +module.exports.create = function (le) { var PromiseA = require('bluebird'); + var utils = require('./utils'); // merge, tplCopy; var RSA = PromiseA.promisifyAll(require('rsa-compat').RSA); var LeCore = PromiseA.promisifyAll(require('letiny-core')); var crypto = require('crypto'); @@ -28,8 +20,6 @@ module.exports.create = function (defaults, handlers, backend) { } function createAccount(args, handlers) { - args.rsaKeySize = args.rsaKeySize || 2048; - return RSA.generateKeypairAsync(args.rsaKeySize, 65537, { public: true, pem: true }).then(function (keypair) { return LeCore.registerNewAccountAsync({ @@ -73,21 +63,19 @@ module.exports.create = function (defaults, handlers, backend) { var now = Date.now(); // TODO check response header on request for cache time - if ((now - ipc.acmeUrlsUpdatedAt) < 10 * 60 * 1000) { - return PromiseA.resolve(ipc.acmeUrls); + if ((now - le._ipc.acmeUrlsUpdatedAt) < 10 * 60 * 1000) { + return PromiseA.resolve(le._ipc.acmeUrls); } return LeCore.getAcmeUrlsAsync(args.server).then(function (data) { - ipc.acmeUrlsUpdatedAt = Date.now(); - ipc.acmeUrls = data; + le._ipc.acmeUrlsUpdatedAt = Date.now(); + le._ipc.acmeUrls = data; - return ipc.acmeUrls; + return le._ipc.acmeUrls; }); } function getCertificateAsync(args, defaults, handlers) { - args.rsaKeySize = args.rsaKeySize || 2048; - args.challengeType = args.challengeType || 'http-01'; function log() { if (args.debug || defaults.debug) { @@ -223,7 +211,6 @@ module.exports.create = function (defaults, handlers, backend) { var wrapped = { registerAsync: function (args) { - var utils = require('./lib/common'); var err; if (!Array.isArray(args.domains)) { diff --git a/lib/common.js b/lib/utils.js similarity index 100% rename from lib/common.js rename to lib/utils.js