greenlock.js/index.js

81 lines
2.1 KiB
JavaScript
Raw Normal View History

2015-12-11 06:22:46 -08: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 18:49:35 -04:00
2016-02-12 21:33:50 -05:00
LE.defaults = {
2016-08-04 18:49:35 -04:00
server: leCore.productionServerUrl
, stagingServer: leCore.stagingServerUrl
, liveServer: leCore.productionServerUrl
, productionServerUrl: leCore.productionServerUrl
, stagingServerUrl: leCore.stagingServerUrl
, acmeChallengePrefix: leCore.acmeChallengePrefix
2016-02-12 21:33:50 -05:00
};
2015-12-20 02:41:17 -08:00
2015-12-16 01:11:31 -08:00
// backwards compat
2016-08-04 18:49:35 -04:00
Object.keys(LE.defaults).forEach(function (key) {
LE[key] = LE.defaults[key];
});
2015-12-13 01:04:12 +00:00
2015-12-16 01:11:31 -08:00
LE.create = function (defaults, handlers, backend) {
2016-08-05 04:14:40 -04: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 04:14:40 -04:00
if (backend.create) {
backend = backend.create(defaults);
}
2015-12-13 05:03:48 +00:00
backend = PromiseA.promisifyAll(backend);
2016-08-05 04:14:40 -04:00
core = Core.create(defaults, handlers, backend);
2015-12-13 01:04:12 +00:00
2016-08-05 04:14:40 -04:00
var le = {
2015-12-15 12:12:15 +00:00
backend: backend
2016-08-05 04:14:40 -04:00
, core: core
// register
, create: function (args, cb) {
return core.registerAsync(args).then(function (pems) {
2016-08-04 14:26:49 -04:00
cb(null, pems);
}, cb);
2015-12-12 14:20:12 +00:00
}
2016-08-05 04:14:40 -04:00
// fetch
, domain: function (args, cb) {
// TODO must return email, domains, tos, pems
return core.fetchAsync(args).then(function (certInfo) {
cb(null, certInfo);
2015-12-13 05:03:48 +00:00
}, cb);
}
2016-08-05 04:14:40 -04:00
, domains: function (args, cb) {
// TODO show all domains or limit by account
throw new Error('not implemented');
2015-12-20 02:41:17 -08:00
}
2016-08-05 04:14:40 -04:00
, accounts: function (args, cb) {
// TODO show all accounts or limit by domain
throw new Error('not implemented');
2015-12-20 02:41:17 -08:00
}
2016-08-05 04:14:40 -04:00
, account: function (args, cb) {
// TODO return one account
throw new Error('not implemented');
2015-12-20 02:41:17 -08:00
}
2015-12-12 14:20:12 +00:00
};
2015-12-11 06:22:46 -08:00
2016-08-05 04:14:40 -04:00
// exists
// get
2015-12-12 14:20:12 +00:00
return le;
2015-12-11 06:22:46 -08:00
};