From 03826d845d9f1d043f17fa73caca38b68d55dd22 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 15 Dec 2015 12:12:15 +0000 Subject: [PATCH] can register new accounts --- backends/ursa.js | 12 +++++++----- examples/config-minimal.js | 2 +- index.js | 5 +++-- package.json | 1 + 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/backends/ursa.js b/backends/ursa.js index e22989d..ac4b251 100644 --- a/backends/ursa.js +++ b/backends/ursa.js @@ -123,6 +123,7 @@ function createAccount(args, handlers) { } function getAccount(args, accountId) { + console.log(args.accountsDir, accountId); var accountDir = path.join(args.accountsDir, accountId); var files = {}; var configs = ['meta.json', 'private_key.json', 'regr.json']; @@ -174,7 +175,7 @@ function getAccountByEmail(args) { } module.exports.create = function (defaults, opts) { - var LE = require('./'); + var LE = require('../'); var pyconf = PromiseA.promisifyAll(require('pyconf')); if (!opts) { @@ -191,10 +192,10 @@ module.exports.create = function (defaults, opts) { var wrapped = { registerAsync: function (args) { 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; - args.renewalDir = args.renewalDir || path.join(configDir, 'renewal', hostname + '.conf'); - args.accountsDir = args.accountsDir || path.join(configDir, 'accounts', hostname, 'directory'); + args.renewalDir = args.renewalDir || path.join(configDir, 'renewal', args.domains[0] + '.conf'); + args.accountsDir = args.accountsDir || path.join(configDir, 'accounts', acmeHostname, 'directory'); pyconf.readFileAsync(args.renewalDir).then(function (renewal) { return renewal.account; @@ -203,7 +204,7 @@ module.exports.create = function (defaults, opts) { return getAccountByEmail(args); } - return err; + return PromiseA.reject(err); }).then(function (accountId) { // Note: the ACME urls are always fetched fresh on purpose return getAcmeUrls(args).then(function (urls) { @@ -216,6 +217,7 @@ module.exports.create = function (defaults, opts) { } }); }).then(function (account) { + console.log(account); throw new Error("IMPLEMENTATION NOT COMPLETE"); }); /* diff --git a/examples/config-minimal.js b/examples/config-minimal.js index 2a88cb9..3708bcc 100644 --- a/examples/config-minimal.js +++ b/examples/config-minimal.js @@ -2,7 +2,7 @@ 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 = { diff --git a/index.js b/index.js index ac3085f..8fee0af 100644 --- a/index.js +++ b/index.js @@ -57,7 +57,7 @@ LE.create = function (backend, defaults, handlers) { if (defaults.agreeTos) { 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) { backend = backend.create(defaults, handlers); @@ -119,7 +119,8 @@ LE.create = function (backend, defaults, handlers) { } le = { - validate: function (hostnames, cb) { + backend: backend + , validate: function (hostnames, cb) { // TODO check dns, etc if ((!hostnames.length && hostnames.every(le.isValidDomain))) { cb(new Error("node-letsencrypt: invalid hostnames: " + hostnames.join(','))); diff --git a/package.json b/package.json index bc441d3..9ab1dcf 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ }, "dependencies": { "bluebird": "^3.0.6", + "homedir": "^0.6.0", "mkdirp": "^0.5.1", "pyconf": "^1.0.0", "request": "^2.67.0",