2015-12-11 14:22:46 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-12-13 05:03:48 +00:00
|
|
|
// TODO handle www and no-www together somehow?
|
|
|
|
|
2015-12-12 15:05:45 +00:00
|
|
|
var PromiseA = require('bluebird');
|
2015-12-17 04:59:47 +00:00
|
|
|
var leCore = require('letiny-core');
|
2015-12-12 15:05:45 +00:00
|
|
|
|
2015-12-13 01:04:12 +00:00
|
|
|
var LE = module.exports;
|
2016-08-04 22:49:35 +00:00
|
|
|
|
2016-02-13 02:33:50 +00:00
|
|
|
LE.defaults = {
|
2016-08-04 22:49:35 +00:00
|
|
|
server: leCore.productionServerUrl
|
|
|
|
, stagingServer: leCore.stagingServerUrl
|
|
|
|
, liveServer: leCore.productionServerUrl
|
|
|
|
|
|
|
|
, productionServerUrl: leCore.productionServerUrl
|
|
|
|
, stagingServerUrl: leCore.stagingServerUrl
|
|
|
|
|
|
|
|
, acmeChallengePrefix: leCore.acmeChallengePrefix
|
2016-02-13 02:33:50 +00:00
|
|
|
};
|
2015-12-20 10:41:17 +00:00
|
|
|
|
2015-12-16 09:11:31 +00:00
|
|
|
// backwards compat
|
2016-08-04 22:49:35 +00:00
|
|
|
Object.keys(LE.defaults).forEach(function (key) {
|
|
|
|
LE[key] = LE.defaults[key];
|
|
|
|
});
|
2015-12-13 01:04:12 +00:00
|
|
|
|
2015-12-16 09:11:31 +00:00
|
|
|
LE.create = function (defaults, handlers, backend) {
|
2016-08-05 08:14:40 +00:00
|
|
|
var Core = require('./lib/core');
|
|
|
|
var core;
|
|
|
|
if (!backend) { backend = require('./lib/pycompat'); }
|
2015-12-13 01:04:12 +00:00
|
|
|
if (!handlers) { handlers = {}; }
|
2015-12-13 05:03:48 +00:00
|
|
|
if (!handlers.renewWithin) { handlers.renewWithin = 3 * 24 * 60 * 60 * 1000; }
|
2015-12-13 01:04:12 +00:00
|
|
|
if (!handlers.memorizeFor) { handlers.memorizeFor = 1 * 24 * 60 * 60 * 1000; }
|
2015-12-13 05:03:48 +00:00
|
|
|
if (!handlers.sniRegisterCallback) {
|
|
|
|
handlers.sniRegisterCallback = function (args, cache, cb) {
|
|
|
|
// TODO when we have ECDSA, just do this automatically
|
|
|
|
cb(null, null);
|
|
|
|
};
|
|
|
|
}
|
2015-12-17 08:46:40 +00:00
|
|
|
|
2016-08-05 08:14:40 +00:00
|
|
|
if (backend.create) {
|
|
|
|
backend = backend.create(defaults);
|
2015-12-15 15:40:44 +00:00
|
|
|
}
|
2015-12-13 05:03:48 +00:00
|
|
|
backend = PromiseA.promisifyAll(backend);
|
2016-08-05 08:14:40 +00:00
|
|
|
core = Core.create(defaults, handlers, backend);
|
2015-12-13 01:04:12 +00:00
|
|
|
|
2016-08-05 08:14:40 +00:00
|
|
|
var le = {
|
2015-12-15 12:12:15 +00:00
|
|
|
backend: backend
|
2016-08-05 08:14:40 +00:00
|
|
|
, core: core
|
|
|
|
// register
|
|
|
|
, create: function (args, cb) {
|
|
|
|
return core.registerAsync(args).then(function (pems) {
|
2016-08-04 18:26:49 +00:00
|
|
|
cb(null, pems);
|
|
|
|
}, cb);
|
2015-12-12 14:20:12 +00:00
|
|
|
}
|
2016-08-05 08:14:40 +00:00
|
|
|
// fetch
|
|
|
|
, domain: function (args, cb) {
|
|
|
|
// TODO must return email, domains, tos, pems
|
|
|
|
return core.fetchAsync(args).then(function (certInfo) {
|
2015-12-17 05:44:41 +00:00
|
|
|
cb(null, certInfo);
|
2015-12-13 05:03:48 +00:00
|
|
|
}, cb);
|
|
|
|
}
|
2016-08-05 08:14:40 +00:00
|
|
|
, domains: function (args, cb) {
|
|
|
|
// TODO show all domains or limit by account
|
|
|
|
throw new Error('not implemented');
|
2015-12-20 10:41:17 +00:00
|
|
|
}
|
2016-08-05 08:14:40 +00:00
|
|
|
, accounts: function (args, cb) {
|
|
|
|
// TODO show all accounts or limit by domain
|
|
|
|
throw new Error('not implemented');
|
2015-12-20 10:41:17 +00:00
|
|
|
}
|
2016-08-05 08:14:40 +00:00
|
|
|
, account: function (args, cb) {
|
|
|
|
// TODO return one account
|
|
|
|
throw new Error('not implemented');
|
2015-12-20 10:41:17 +00:00
|
|
|
}
|
2015-12-12 14:20:12 +00:00
|
|
|
};
|
2015-12-11 14:22:46 +00:00
|
|
|
|
2016-08-05 08:14:40 +00:00
|
|
|
// exists
|
|
|
|
// get
|
|
|
|
|
2015-12-12 14:20:12 +00:00
|
|
|
return le;
|
2015-12-11 14:22:46 +00:00
|
|
|
};
|