can register new accounts

This commit is contained in:
AJ ONeal 2015-12-15 12:12:15 +00:00
parent c38d44a69f
commit 03826d845d
4 changed files with 12 additions and 8 deletions

View File

@ -123,6 +123,7 @@ function createAccount(args, handlers) {
} }
function getAccount(args, accountId) { function getAccount(args, accountId) {
console.log(args.accountsDir, accountId);
var accountDir = path.join(args.accountsDir, accountId); var accountDir = path.join(args.accountsDir, accountId);
var files = {}; var files = {};
var configs = ['meta.json', 'private_key.json', 'regr.json']; var configs = ['meta.json', 'private_key.json', 'regr.json'];
@ -174,7 +175,7 @@ function getAccountByEmail(args) {
} }
module.exports.create = function (defaults, opts) { module.exports.create = function (defaults, opts) {
var LE = require('./'); var LE = require('../');
var pyconf = PromiseA.promisifyAll(require('pyconf')); var pyconf = PromiseA.promisifyAll(require('pyconf'));
if (!opts) { if (!opts) {
@ -191,10 +192,10 @@ module.exports.create = function (defaults, opts) {
var wrapped = { var wrapped = {
registerAsync: function (args) { registerAsync: function (args) {
args.server = args.server || defaults.server || LE.liveServer; // https://acme-v01.api.letsencrypt.org/directory args.server = args.server || defaults.server || LE.liveServer; // https://acme-v01.api.letsencrypt.org/directory
var hostname = require('url').parse(args.server).hostname; var acmeHostname = require('url').parse(args.server).hostname;
var configDir = args.configDir || defaults.configDir || LE.configDir; var configDir = args.configDir || defaults.configDir || LE.configDir;
args.renewalDir = args.renewalDir || path.join(configDir, 'renewal', hostname + '.conf'); args.renewalDir = args.renewalDir || path.join(configDir, 'renewal', args.domains[0] + '.conf');
args.accountsDir = args.accountsDir || path.join(configDir, 'accounts', hostname, 'directory'); args.accountsDir = args.accountsDir || path.join(configDir, 'accounts', acmeHostname, 'directory');
pyconf.readFileAsync(args.renewalDir).then(function (renewal) { pyconf.readFileAsync(args.renewalDir).then(function (renewal) {
return renewal.account; return renewal.account;
@ -203,7 +204,7 @@ module.exports.create = function (defaults, opts) {
return getAccountByEmail(args); return getAccountByEmail(args);
} }
return err; return PromiseA.reject(err);
}).then(function (accountId) { }).then(function (accountId) {
// Note: the ACME urls are always fetched fresh on purpose // Note: the ACME urls are always fetched fresh on purpose
return getAcmeUrls(args).then(function (urls) { return getAcmeUrls(args).then(function (urls) {
@ -216,6 +217,7 @@ module.exports.create = function (defaults, opts) {
} }
}); });
}).then(function (account) { }).then(function (account) {
console.log(account);
throw new Error("IMPLEMENTATION NOT COMPLETE"); throw new Error("IMPLEMENTATION NOT COMPLETE");
}); });
/* /*

View File

@ -2,7 +2,7 @@
var path = require('path'); var path = require('path');
var binpath = require('os').homedir() + '/.local/share/letsencrypt/bin/letsencrypt'; var binpath = require('homedir') + '/.local/share/letsencrypt/bin/letsencrypt';
var config = { var config = {

View File

@ -57,7 +57,7 @@ LE.create = function (backend, defaults, handlers) {
if (defaults.agreeTos) { if (defaults.agreeTos) {
console.warn("[WARN] Agreeing to terms by default is risky business..."); console.warn("[WARN] Agreeing to terms by default is risky business...");
} }
handlers.removeChallenge = require('lib/default-handlers').agreeToTerms; handlers.removeChallenge = require('./lib/default-handlers').agreeToTerms;
} }
if ('function' === typeof backend.create) { if ('function' === typeof backend.create) {
backend = backend.create(defaults, handlers); backend = backend.create(defaults, handlers);
@ -119,7 +119,8 @@ LE.create = function (backend, defaults, handlers) {
} }
le = { le = {
validate: function (hostnames, cb) { backend: backend
, validate: function (hostnames, cb) {
// TODO check dns, etc // TODO check dns, etc
if ((!hostnames.length && hostnames.every(le.isValidDomain))) { if ((!hostnames.length && hostnames.every(le.isValidDomain))) {
cb(new Error("node-letsencrypt: invalid hostnames: " + hostnames.join(','))); cb(new Error("node-letsencrypt: invalid hostnames: " + hostnames.join(',')));

View File

@ -43,6 +43,7 @@
}, },
"dependencies": { "dependencies": {
"bluebird": "^3.0.6", "bluebird": "^3.0.6",
"homedir": "^0.6.0",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"pyconf": "^1.0.0", "pyconf": "^1.0.0",
"request": "^2.67.0", "request": "^2.67.0",