update to list zones

This commit is contained in:
AJ ONeal 2019-06-13 13:32:42 -06:00
parent 1afddd9aae
commit c7cda58cc1
5 changed files with 70 additions and 47 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*secret*
node_modules

View File

@ -11,16 +11,34 @@ module.exports.create = function(config) {
var baseUrl = config.baseUrl || defaults.baseUrl;
var apiKey = config.apiKey;
return {
zones: function(data) {
var url = baseUrl + 'v1/dns/list';
return request({
method: 'GET',
url: url,
headers: {
'API-Key': apiKey
},
json: true
}).then(function(resp) {
if (resp.statusCode == 200) {
return resp.body.map(function(x) {
return x.domain;
});
} else {
console.error(resp.statusCode);
console.error(resp.body);
throw new Error('Could not get list of zones. Check api key, etc');
}
});
},
set: function(data) {
var ch = data.challenge;
var domainname = ch.identifier.value;
var zone = domainname;
var dnsPrefix = ch.dnsHost.replace(new RegExp('.' + zone + '$'), '');
var txt = ch.dnsAuthorization;
// If the domain to be verified is
var url = baseUrl + 'v1/dns/create_record';
console.log('adding txt', data);
//console.debug('adding txt', data);
return request({
method: 'POST',
url: url,
@ -29,32 +47,28 @@ module.exports.create = function(config) {
},
form: {
type: 'TXT',
name: dnsPrefix,
name: ch.dnsPrefix,
data: '"' + txt + '"', // vultr requires the TXT record wraped in quotes
domain: config.domain,
domain: ch.dnsZone,
ttl: 300
}
}).then(function(resp) {
if (resp.statusCode == 200) {
return true;
} else {
console.log(resp.statusCode);
console.log(resp.body);
console.error(resp.statusCode);
console.error(resp.body);
throw new Error('record did not set. check subdomain, api key, etc');
}
});
},
remove: function(data) {
var ch = data.challenge;
var domainname = data.challenge.altname;
var zone = domainname;
var url = baseUrl + 'v1/dns/records';
return request({
method: 'GET',
url: url + '?domain=' + config.domain,
// PROBLEM (fixed): Remember to set json: true (not need to JSON.parse)
url: url + '?domain=' + ch.dnsZone,
json: true,
headers: {
'API-Key': apiKey
@ -63,7 +77,7 @@ module.exports.create = function(config) {
.then(function(resp) {
if (resp.statusCode == 200) {
resp = resp.body;
console.log(resp);
//console.debug(resp);
var entries = resp.filter(function(x) {
return x.type === 'TXT';
});
@ -89,8 +103,6 @@ module.exports.create = function(config) {
}
})
.then(function(recordId) {
var domainname = data.challenge.altname;
var zone = domainname;
var url = baseUrl + 'v1/dns/delete_record';
return request({
@ -100,15 +112,15 @@ module.exports.create = function(config) {
'API-Key': apiKey
},
form: {
domain: config.domain,
domain: ch.dnsZone,
RECORDID: recordId
}
}).then(function(resp) {
if (resp.statusCode == 200) {
return true;
} else {
console.log(resp.statusCode);
console.log(resp.body);
console.error(resp.statusCode);
console.error(resp.body);
throw new Error(
'record did not remove. check subdomain, api key, etc'
);
@ -118,16 +130,15 @@ module.exports.create = function(config) {
},
get: function(data) {
var ch = data.challenge;
var domainname = data.challenge.altname;
var url = baseUrl + 'v1/dns/records';
console.log('getting txt', data);
//console.debug('getting txt', data);
// Digital ocean provides the api to fetch records by ID. Since we do not have id, we fetch all the records,
// filter the required TXT record
return request({
method: 'GET',
url: url + '?domain=' + config.domain,
url: url + '?domain=' + ch.dnsZone,
json: true,
headers: {
'API-Key': apiKey

28
package-lock.json generated Normal file
View File

@ -0,0 +1,28 @@
{
"name": "acme-dns-01-vultr",
"version": "3.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@root/request": {
"version": "1.3.11",
"resolved": "https://registry.npmjs.org/@root/request/-/request-1.3.11.tgz",
"integrity": "sha512-3a4Eeghcjsfe6zh7EJ+ni1l8OK9Fz2wL1OjP4UCa0YdvtH39kdXB9RGWuzyNv7dZi0+Ffkc83KfH0WbPMiuJFw=="
},
"acme-challenge-test": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/acme-challenge-test/-/acme-challenge-test-3.2.1.tgz",
"integrity": "sha512-8MwL2oWx7vM/SBIeEQfeoRyW0kYCtLFS4FfgIx3lsQmSKhbDo9J88Ud6DejdupRp2T+DlEkWIBVI3qOCVViUaQ==",
"dev": true
},
"acme-dns-01-test": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/acme-dns-01-test/-/acme-dns-01-test-3.2.1.tgz",
"integrity": "sha512-m4UxltZzTNbQTK30iQQ6BQ99oRJA9p69+eg/u/Plxiw10bD+qsmRZR9rsqZuiSc62wfng/upGvXWMQZ/csn3lA==",
"dev": true,
"requires": {
"acme-challenge-test": "^3.2.0"
}
}
}
}

View File

@ -24,6 +24,6 @@
"@root/request": "^1.3.11"
},
"devDependencies": {
"acme-challenge-test": "^3.1.2"
"acme-dns-01-test": "^3.2.1"
}
}

30
test.js
View File

@ -1,42 +1,24 @@
#!/usr/bin/env node
'use strict';
// https://git.coolaj86.com/coolaj86/acme-challenge-test.js
var tester = require('acme-challenge-test');
// https://git.rootprojects.org/root/acme-dns-01-test.js
var tester = require('acme-dns-01-test');
// Usage: node ./test.js example.com xxxxxxxxx
var zone = process.argv[2];
var challenger = require('./index.js').create({
apiKey: process.argv[3],
domain: zone
apiKey: process.argv[3]
});
// The dry-run tests can pass on, literally, 'example.com'
// but the integration tests require that you have control over the domain
var domain = zone;
tester
.test('dns-01', domain, challenger)
.testZone('dns-01', zone, challenger)
.then(function() {
console.info('PASS', domain);
///*
domain = 'foo.' + zone;
return tester
.test('dns-01', domain, challenger)
.then(function() {
console.info('PASS', domain);
})
.then(function() {
domain = '*.foo.' + zone;
return tester.test('dns-01', domain, challenger).then(function() {
console.info('PASS', domain);
});
});
//*/
console.info('PASS', zone);
})
.catch(function(e) {
console.info('FAIL', zone);
console.error(e.message);
console.error(e.stack);
});