getting pretty close

This commit is contained in:
AJ ONeal 2016-08-05 18:16:29 -04:00
parent 5ff91ec37e
commit 63b9cb5ec9
1 changed files with 75 additions and 51 deletions

126
index.js
View File

@ -23,58 +23,82 @@ Object.keys(LE.defaults).forEach(function (key) {
LE[key] = LE.defaults[key]; LE[key] = LE.defaults[key];
}); });
LE.create = function (defaults, handlers, backend) { var u; // undefined
var Core = require('./lib/core'); LE._undefined = {
var core; store: u
if (!backend) { backend = require('./lib/pycompat'); } , challenger: u
if (!handlers) { handlers = {}; } , register: u
if (!handlers.renewWithin) { handlers.renewWithin = 3 * 24 * 60 * 60 * 1000; } , check: u
if (!handlers.memorizeFor) { handlers.memorizeFor = 1 * 24 * 60 * 60 * 1000; } , renewWithin: u
if (!handlers.sniRegisterCallback) { , memorizeFor: u
handlers.sniRegisterCallback = function (args, cache, cb) { , acmeChallengePrefix: u
// TODO when we have ECDSA, just do this automatically };
cb(null, null); LE._undefine = function (le) {
}; Object.keys(LE._undefined).forEach(function (key) {
if (!(key in le)) {
le[key] = u;
} }
});
if (backend.create) {
backend = backend.create(defaults); return le;
} };
backend = PromiseA.promisifyAll(backend); LE.create = function (le) {
core = Core.create(defaults, handlers, backend); le = LE._undefine(le);
var store = le.store || require('le-store-certbot').create({ debug: le.debug });
var le = { var challenger = le.challenge || require('le-store-certbot').create({ debug: le.debug });
backend: backend var core = le.core = require('./lib/core');
, core: core
// register le.acmeChallengePrefix = LE.acmeChallengePrefix;
, create: function (args, cb) {
return core.registerAsync(args).then(function (pems) { if (!le.renewWithin) { le.renewWithin = 3 * 24 * 60 * 60 * 1000; }
cb(null, pems); if (!le.memorizeFor) { le.memorizeFor = 1 * 24 * 60 * 60 * 1000; }
}, cb);
} if (!le.server) {
// fetch throw new Error("opts.server must be set to 'staging' or a production url, such as LE.productionServerUrl'");
, domain: function (args, cb) { }
// TODO must return email, domains, tos, pems if ('staging' === le.server) {
return core.fetchAsync(args).then(function (certInfo) { le.server = LE.stagingServerUrl;
cb(null, certInfo); }
}, cb); else if ('production' === le.server) {
} le.server = LE.productionServerUrl;
, domains: function (args, cb) { }
// TODO show all domains or limit by account
throw new Error('not implemented'); if (store.create) {
} store = store.create(le);
, accounts: function (args, cb) { }
// TODO show all accounts or limit by domain store = PromiseA.promisifyAll(store);
throw new Error('not implemented'); le._storeOpts = store.getOptions();
} Object.keys(le._storeOpts).forEach(function (key) {
, account: function (args, cb) { if (!(key in le._storeOpts)) {
// TODO return one account le[key] = le._storeOpts[key];
throw new Error('not implemented'); }
} });
};
if (challenger.create) {
// exists challenger = challenger.create(le);
// get }
challenger = PromiseA.promisifyAll(challenger);
le._challengerOpts = challenger.getOptions();
Object.keys(le._storeOpts).forEach(function (key) {
if (!(key in le._challengerOpts)) {
le[key] = le._challengerOpts[key];
}
});
core = le.core = core.create(le);
le.register = function (args) {
return core.registerAsync(args);
};
le.check = function (args) {
// TODO must return email, domains, tos, pems
return core.fetchAsync(args);
};
le.middleware = function () {
return require('./lib/middleware')(le);
};
return le; return le;
}; };