-- 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/)
|
||||
Aneem Patrabansha <aneempp@gmail.com> (https://aneem.com.np)
|
||||
|
|
72
lib/index.js
72
lib/index.js
|
@ -12,20 +12,23 @@ module.exports.create = function(config) {
|
|||
var baseUrl = config.baseUrl || defaults.baseUrl;
|
||||
var authtoken = config.token;
|
||||
|
||||
function api(method, path, form) {
|
||||
return request({
|
||||
method: method,
|
||||
url: baseUrl + path,
|
||||
headers: {
|
||||
Authorization: 'Bearer ' + authtoken,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
json: true,
|
||||
form: form
|
||||
});
|
||||
}
|
||||
|
||||
var helpers = {
|
||||
getZonenames: function(/*opts*/) {
|
||||
// { dnsHosts: [ xxxx.foo.example.com ] }
|
||||
var url = baseUrl + '/v2/domains/';
|
||||
|
||||
return request({
|
||||
method: 'GET',
|
||||
url: url,
|
||||
headers: {
|
||||
Authorization: 'Bearer ' + authtoken,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
json: true
|
||||
}).then(function(resp) {
|
||||
return api('GET', '/v2/domains/').then(function(resp) {
|
||||
return resp.body.domains.map(function(x) {
|
||||
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"}
|
||||
var dnsPrefix = data.dnsPrefix;
|
||||
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,
|
||||
// filter the required TXT record
|
||||
|
||||
return request({
|
||||
method: 'GET',
|
||||
url: url,
|
||||
json: true,
|
||||
headers: {
|
||||
Authorization: 'Bearer ' + authtoken,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
}).then(function(resp) {
|
||||
return api('GET', '/v2/domains/' + data.zone + '/records').then(function(
|
||||
resp
|
||||
) {
|
||||
resp = resp.body;
|
||||
var entries =
|
||||
resp &&
|
||||
|
@ -69,25 +65,13 @@ module.exports.create = function(config) {
|
|||
set: function(data) {
|
||||
var ch = data.challenge;
|
||||
var txt = ch.dnsAuthorization;
|
||||
var url = baseUrl + '/v2/domains/' + ch.dnsZone + '/records';
|
||||
|
||||
// console.info('Adding TXT', data);
|
||||
return request({
|
||||
method: 'POST',
|
||||
url: url,
|
||||
headers: {
|
||||
Authorization: 'Bearer ' + authtoken,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
json: {
|
||||
type: 'TXT',
|
||||
// Note: dnsPrefix != dnsHost.split('.')[0]
|
||||
// _greenlock-dryrun-2277.bar.foo.example.com => _greenlock-dryrun-2277.bar.foo
|
||||
name: ch.dnsPrefix,
|
||||
data: txt,
|
||||
// Note: set a LOW ttl so that responses are not cached so long
|
||||
ttl: 300
|
||||
}
|
||||
return api('POST', '/v2/domains/' + ch.dnsZone + '/records', {
|
||||
type: 'TXT',
|
||||
name: ch.dnsPrefix,
|
||||
data: txt,
|
||||
ttl: 300
|
||||
}).then(function(resp) {
|
||||
resp = resp.body;
|
||||
if (resp && resp.domain_record && resp.domain_record.data === txt) {
|
||||
|
@ -112,14 +96,10 @@ module.exports.create = function(config) {
|
|||
var url =
|
||||
baseUrl + '/v2/domains/' + ch.dnsZone + '/records/' + txtRecord.id;
|
||||
|
||||
return request({
|
||||
method: 'DELETE',
|
||||
url: url,
|
||||
headers: {
|
||||
Authorization: 'Bearer ' + authtoken,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
}).then(function(resp) {
|
||||
return api(
|
||||
'DELETE',
|
||||
'/v2/domains/' + ch.dnsZone + '/records/' + txtRecord.id
|
||||
).then(function(resp) {
|
||||
resp = resp.body;
|
||||
return true;
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue