make cluster safe

This commit is contained in:
AJ ONeal 2016-09-07 17:10:04 -06:00
parent b41f09df11
commit d1814341a5
2 changed files with 41 additions and 17 deletions

View File

@ -4,7 +4,8 @@
var PromiseA = require('bluebird'); var PromiseA = require('bluebird');
var dns = PromiseA.promisifyAll(require('dns')); var dns = PromiseA.promisifyAll(require('dns'));
var DDNS = require('ddns-cli'); var DDNS = require('/Users/aj/Dropbox/Code/ddns-cli');
//var DDNS = require('ddns-cli');
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
@ -73,22 +74,34 @@ Challenge.create = function (options) {
// if you need access to them. // if you need access to them.
// //
Challenge.set = function (args, domain, challenge, keyAuthorization, done) { Challenge.set = function (args, domain, challenge, keyAuthorization, done) {
var me = this;
// Note: keyAuthorization is not used for dns-01 // Note: keyAuthorization is not used for dns-01
this._memstore.set(domain, { me._memstore.set(domain, {
email: args.email email: args.email
, refreshToken: args.refreshToken , refreshToken: args.refreshToken
}, function () { }, function (err) {
if (err) { done(err); return; }
return DDNS.run({ var challengeDomain = args.test + args.acmeChallengeDns + domain;
return DDNS.update({
email: args.email email: args.email
, refreshToken: args.refreshToken , refreshToken: args.refreshToken
, name: args.test + args.acmeChallengeDns + '.' + domain , name: challengeDomain
, type: "TXT" , type: "TXT"
, value: challenge , value: challenge
, ttl: 60 , ttl: 60
}).then(function () { done(null); }, done); }, {
//debug: true
}).then(function () {
if (args.debug) {
console.log("Test DNS Record:");
console.log("dig TXT +noall +answer @ns1.redirect-www.org '" + challengeDomain + "' # " + challenge);
}
done(null);
}, done);
}); });
}; };
@ -103,51 +116,61 @@ Challenge.get = function (defaults, domain, challenge, done) {
}; };
Challenge.remove = function (defaults, domain, challenge, done) { Challenge.remove = function (defaults, domain, challenge, done) {
this._memstore.get(domain, function (data) { var me = this;
return DDNS.run({
me._memstore.get(domain, function (err, data) {
if (err) { done(err); return; }
var challengeDomain = defaults.test + defaults.acmeChallengeDns + domain;
return DDNS.update({
email: data.email email: data.email
, refreshToken: data.refreshToken , refreshToken: data.refreshToken
, name: defaults.test + defaults.acmeChallengeDns + '.' + domain , name: challengeDomain
, type: "TXT" , type: "TXT"
, value: challenge , value: challenge
, ttl: 60 , ttl: 60
, remove: true , remove: true
}, {
//debug: true
}).then(function () { }).then(function () {
done(null); done(null);
}, done).then(function () { }, done).then(function () {
this._memstore.remove(domain); me._memstore.destroy(domain);
}); });
}); });
}; };
// same as get, but external // same as get, but external
Challenge.loopback = function (defaults, domain, challenge, done) { Challenge.loopback = function (defaults, domain, challenge, done) {
var subdomain = defaults.test + defaults.acmeChallengeDns + '.' + domain; var challengeDomain = defaults.test + defaults.acmeChallengeDns + domain;
dns.resolveAsync(subdomain).then(function () { done(null); }, done); dns.resolveTxtAsync(challengeDomain).then(function () { done(null); }, done);
}; };
Challenge.test = function (args, domain, challenge, keyAuthorization, done) { Challenge.test = function (args, domain, challenge, keyAuthorization, done) {
var me = this;
// Note: keyAuthorization is not used for dns-01 // Note: keyAuthorization is not used for dns-01
args.test = '_test.'; args.test = args.test || '_test.';
defaults.test = args.test;
Challenge.set(args, domain, challenge, keyAuthorization, function (err) { me.set(args, domain, challenge, null, function (err) {
if (err) { done(err); return; } if (err) { done(err); return; }
Challenge.loopback(defaults, domain, challenge, function (err) { me.loopback(defaults, domain, challenge, function (err) {
if (err) { done(err); return; } if (err) { done(err); return; }
Challenge.remove(defaults, domain, challenge, function (err) { me.remove(defaults, domain, challenge, function (err) {
if (err) { done(err); return; } if (err) { done(err); return; }
// TODO needs to use native-dns so that specific nameservers can be used // TODO needs to use native-dns so that specific nameservers can be used
// (otherwise the cache will still have the old answer) // (otherwise the cache will still have the old answer)
done(); done();
/* /*
Challenge.loopback(defaults, domain, challenge, function (err) { me.loopback(defaults, domain, challenge, function (err) {
if (err) { done(err); return; } if (err) { done(err); return; }
done(); done();

View File

@ -31,6 +31,7 @@
"dependencies": { "dependencies": {
"daplie-dns": "git+https://github.com/Daplie/daplie-cli-dns.git#master", "daplie-dns": "git+https://github.com/Daplie/daplie-cli-dns.git#master",
"daplie-domains": "git+https://github.com/Daplie/daplie-cli-domains.git#master", "daplie-domains": "git+https://github.com/Daplie/daplie-cli-domains.git#master",
"memstore-cluster": "^1.0.0",
"oauth3-cli": "git+https://github.com/OAuth3/oauth3-cli.git#master" "oauth3-cli": "git+https://github.com/OAuth3/oauth3-cli.git#master"
} }
} }