Merge branch 'publish'
This commit is contained in:
commit
e0548806cf
1
AUTHORS
1
AUTHORS
|
@ -1 +1,2 @@
|
|||
AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)
|
||||
Hitesh Walia <hiteshwar.walia@gmail.com>
|
|
@ -100,6 +100,7 @@ node ./test.js example.com johndoe xxxxxx
|
|||
# Authors
|
||||
|
||||
- AJ ONeal
|
||||
- Hitesh Walia
|
||||
|
||||
See AUTHORS for contact info.
|
||||
|
||||
|
|
108
lib/index.js
108
lib/index.js
|
@ -1,9 +1,44 @@
|
|||
'use strict';
|
||||
|
||||
var request;
|
||||
var defaults = {};
|
||||
var defaults = {
|
||||
baseUrl: 'https://api.dnsimple.com/v2/'
|
||||
};
|
||||
|
||||
module.exports.create = function(config) {
|
||||
var baseUrl = (config.baseUrl || defaults.baseUrl).replace(/\/$/, '');
|
||||
var token = config.token;
|
||||
var account = config.account;
|
||||
|
||||
function api(method, path, form) {
|
||||
var req = {
|
||||
method: method,
|
||||
url: baseUrl + path,
|
||||
headers: {
|
||||
Authorization: 'Bearer ' + token,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
json: true,
|
||||
form: form
|
||||
};
|
||||
return request(req).then(function(resp) {
|
||||
if (2 !== Math.floor(resp.statusCode / 100)) {
|
||||
console.error(resp.statusCode, req.url);
|
||||
console.error();
|
||||
console.error('Request:');
|
||||
console.error(req);
|
||||
console.error();
|
||||
console.error('Response:');
|
||||
console.error(resp.body);
|
||||
console.error();
|
||||
throw new Error(
|
||||
'Error response. Check token, baseUrl, domains, etc.'
|
||||
);
|
||||
}
|
||||
return resp;
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
init: function(opts) {
|
||||
request = opts.request;
|
||||
|
@ -11,7 +46,12 @@ module.exports.create = function(config) {
|
|||
},
|
||||
zones: function(data) {
|
||||
// console.info('List Zones', data);
|
||||
throw Error('listing zones not implemented');
|
||||
return api('GET', '/' + account + '/zones').then(function(resp) {
|
||||
return resp['body']['data'].map(function(elem) {
|
||||
//console.log('DEBUG >>> elem.name: ' + elem.name);
|
||||
return elem.name;
|
||||
});
|
||||
});
|
||||
},
|
||||
set: function(data) {
|
||||
var ch = data.challenge;
|
||||
|
@ -19,15 +59,67 @@ module.exports.create = function(config) {
|
|||
throw new Error('No matching zone for ' + ch.dnsHost);
|
||||
}
|
||||
// console.info('Add TXT', data);
|
||||
throw Error('setting TXT not implemented');
|
||||
},
|
||||
remove: function(data) {
|
||||
// console.info('Remove TXT', data);
|
||||
throw Error('removing TXT not implemented');
|
||||
var ch = data.challenge;
|
||||
var txt = ch.dnsAuthorization;
|
||||
|
||||
return api(
|
||||
'POST',
|
||||
'/' + account + '/zones/' + ch.dnsZone + '/records',
|
||||
{
|
||||
name: '',
|
||||
type: 'TXT',
|
||||
content: txt
|
||||
}
|
||||
).then(function(resp) {
|
||||
if (resp.statusCode === 201) {
|
||||
return true;
|
||||
}
|
||||
throw new Error(
|
||||
'record did not set. check subdomain, api key, etc'
|
||||
);
|
||||
});
|
||||
},
|
||||
get: function(data) {
|
||||
// console.info('List TXT', data);
|
||||
throw Error('listing TXTs not implemented');
|
||||
|
||||
return api(
|
||||
'GET',
|
||||
'/' + account + '/zones/' + data.challenge.dnsZone + '/records'
|
||||
).then(function(resp) {
|
||||
var record = resp.body.data.filter(function(record) {
|
||||
return data.challenge.dnsAuthorization === record.content;
|
||||
})[0];
|
||||
|
||||
if (record) return { dnsAuthorization: record.content };
|
||||
else return null;
|
||||
});
|
||||
},
|
||||
remove: function(data) {
|
||||
return api(
|
||||
'GET',
|
||||
'/' + account + '/zones/' + data.challenge.dnsZone + '/records'
|
||||
).then(function(resp) {
|
||||
var record = resp.body.data.filter(function(record) {
|
||||
return data.challenge.dnsAuthorization === record.content;
|
||||
})[0];
|
||||
|
||||
if (record) {
|
||||
return api(
|
||||
'DELETE',
|
||||
'/' +
|
||||
account +
|
||||
'/zones/' +
|
||||
data.challenge.dnsZone +
|
||||
'/records/' +
|
||||
record.id
|
||||
).then(function(resp) {
|
||||
// console.info('DEBUG >>> resp: ', JSON.stringify(resp, null, 2));
|
||||
return true;
|
||||
});
|
||||
} else {
|
||||
throw new Error('Txt Record not found for removal');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
"acme",
|
||||
"greenlock"
|
||||
],
|
||||
"author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)",
|
||||
"author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/), Hitesh Walia <hiteshwar.walia@gmail.com",
|
||||
"license": "MPL-2.0",
|
||||
"devDependencies": {
|
||||
"acme-challenge-test": "^3.3.2",
|
||||
|
|
6
test.js
6
test.js
|
@ -5,11 +5,11 @@
|
|||
var tester = require('acme-challenge-test');
|
||||
require('dotenv').config();
|
||||
|
||||
// Usage: node ./test.js example.com username xxxxxxxxx
|
||||
// Usage: node ./test.js example.com token account
|
||||
var zone = process.argv[2] || process.env.ZONE;
|
||||
var challenger = require('./index.js').create({
|
||||
username: process.argv[3] || process.env.USERNAME,
|
||||
password: process.argv[4] || process.env.PASSWORD
|
||||
token: process.argv[3] || process.env.TOKEN,
|
||||
account: process.argv[4] || process.env.ACCOUNT
|
||||
});
|
||||
|
||||
// The dry-run tests can pass on, literally, 'example.com'
|
||||
|
|
Loading…
Reference in New Issue