-- wrapped request to api call. Modified Authors
This commit is contained in:
parent
333957ca3d
commit
96a1f55a08
1
AUTHORS
1
AUTHORS
|
@ -1 +1,2 @@
|
||||||
AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)
|
AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)
|
||||||
|
Aneem Patrabansha <aneempp@gmail.com> (https://aneem.com.np)
|
||||||
|
|
60
lib/index.js
60
lib/index.js
|
@ -12,20 +12,23 @@ module.exports.create = function(config) {
|
||||||
var baseUrl = config.baseUrl || defaults.baseUrl;
|
var baseUrl = config.baseUrl || defaults.baseUrl;
|
||||||
var authtoken = config.token;
|
var authtoken = config.token;
|
||||||
|
|
||||||
var helpers = {
|
function api(method, path, form) {
|
||||||
getZonenames: function(/*opts*/) {
|
|
||||||
// { dnsHosts: [ xxxx.foo.example.com ] }
|
|
||||||
var url = baseUrl + '/v2/domains/';
|
|
||||||
|
|
||||||
return request({
|
return request({
|
||||||
method: 'GET',
|
method: method,
|
||||||
url: url,
|
url: baseUrl + path,
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: 'Bearer ' + authtoken,
|
Authorization: 'Bearer ' + authtoken,
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
json: true
|
json: true,
|
||||||
}).then(function(resp) {
|
form: form
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var helpers = {
|
||||||
|
getZonenames: function(/*opts*/) {
|
||||||
|
// { dnsHosts: [ xxxx.foo.example.com ] }
|
||||||
|
return api('GET', '/v2/domains/').then(function(resp) {
|
||||||
return resp.body.domains.map(function(x) {
|
return resp.body.domains.map(function(x) {
|
||||||
return x.name;
|
return x.name;
|
||||||
});
|
});
|
||||||
|
@ -35,20 +38,13 @@ module.exports.create = function(config) {
|
||||||
// data:{dnsPrefix:"_88-acme-challenge-0e.foo",zone:"example.com",txt:"_cdZWaclIbkP1qYpMkZIURTK--ydQIK6d9axFmftWz0"}
|
// data:{dnsPrefix:"_88-acme-challenge-0e.foo",zone:"example.com",txt:"_cdZWaclIbkP1qYpMkZIURTK--ydQIK6d9axFmftWz0"}
|
||||||
var dnsPrefix = data.dnsPrefix;
|
var dnsPrefix = data.dnsPrefix;
|
||||||
var txt = data.txt;
|
var txt = data.txt;
|
||||||
var url = baseUrl + '/v2/domains/' + data.zone + '/records';
|
|
||||||
|
|
||||||
// Digital ocean provides the api to fetch records by ID. Since we do not have id, we fetch all the records,
|
// 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
|
// filter the required TXT record
|
||||||
|
|
||||||
return request({
|
return api('GET', '/v2/domains/' + data.zone + '/records').then(function(
|
||||||
method: 'GET',
|
resp
|
||||||
url: url,
|
) {
|
||||||
json: true,
|
|
||||||
headers: {
|
|
||||||
Authorization: 'Bearer ' + authtoken,
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
}).then(function(resp) {
|
|
||||||
resp = resp.body;
|
resp = resp.body;
|
||||||
var entries =
|
var entries =
|
||||||
resp &&
|
resp &&
|
||||||
|
@ -69,25 +65,13 @@ module.exports.create = function(config) {
|
||||||
set: function(data) {
|
set: function(data) {
|
||||||
var ch = data.challenge;
|
var ch = data.challenge;
|
||||||
var txt = ch.dnsAuthorization;
|
var txt = ch.dnsAuthorization;
|
||||||
var url = baseUrl + '/v2/domains/' + ch.dnsZone + '/records';
|
|
||||||
|
|
||||||
// console.info('Adding TXT', data);
|
// console.info('Adding TXT', data);
|
||||||
return request({
|
return api('POST', '/v2/domains/' + ch.dnsZone + '/records', {
|
||||||
method: 'POST',
|
|
||||||
url: url,
|
|
||||||
headers: {
|
|
||||||
Authorization: 'Bearer ' + authtoken,
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
json: {
|
|
||||||
type: 'TXT',
|
type: 'TXT',
|
||||||
// Note: dnsPrefix != dnsHost.split('.')[0]
|
|
||||||
// _greenlock-dryrun-2277.bar.foo.example.com => _greenlock-dryrun-2277.bar.foo
|
|
||||||
name: ch.dnsPrefix,
|
name: ch.dnsPrefix,
|
||||||
data: txt,
|
data: txt,
|
||||||
// Note: set a LOW ttl so that responses are not cached so long
|
|
||||||
ttl: 300
|
ttl: 300
|
||||||
}
|
|
||||||
}).then(function(resp) {
|
}).then(function(resp) {
|
||||||
resp = resp.body;
|
resp = resp.body;
|
||||||
if (resp && resp.domain_record && resp.domain_record.data === txt) {
|
if (resp && resp.domain_record && resp.domain_record.data === txt) {
|
||||||
|
@ -112,14 +96,10 @@ module.exports.create = function(config) {
|
||||||
var url =
|
var url =
|
||||||
baseUrl + '/v2/domains/' + ch.dnsZone + '/records/' + txtRecord.id;
|
baseUrl + '/v2/domains/' + ch.dnsZone + '/records/' + txtRecord.id;
|
||||||
|
|
||||||
return request({
|
return api(
|
||||||
method: 'DELETE',
|
'DELETE',
|
||||||
url: url,
|
'/v2/domains/' + ch.dnsZone + '/records/' + txtRecord.id
|
||||||
headers: {
|
).then(function(resp) {
|
||||||
Authorization: 'Bearer ' + authtoken,
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
}).then(function(resp) {
|
|
||||||
resp = resp.body;
|
resp = resp.body;
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue