Fixed GET and REMOVE functions
This commit is contained in:
parent
4072ae0565
commit
4dfaa01fed
23
lib/index.js
23
lib/index.js
|
@ -39,7 +39,7 @@ module.exports.create = function(config) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Error('Domain not found for: ' + identifier);
|
throw new Error('Domain not found for: ' + identifier);
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
getTXTRecord: function(data) {
|
getTXTRecord: function(data) {
|
||||||
// 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"}
|
||||||
|
@ -60,7 +60,6 @@ module.exports.create = function(config) {
|
||||||
}
|
}
|
||||||
}).then(function(resp) {
|
}).then(function(resp) {
|
||||||
resp = resp.body;
|
resp = resp.body;
|
||||||
|
|
||||||
var entries =
|
var entries =
|
||||||
resp &&
|
resp &&
|
||||||
resp.domain_records &&
|
resp.domain_records &&
|
||||||
|
@ -88,7 +87,7 @@ module.exports.create = function(config) {
|
||||||
var txt = ch.dnsAuthorization;
|
var txt = ch.dnsAuthorization;
|
||||||
var url = baseUrl + '/v2/domains/' + zone + '/records';
|
var url = baseUrl + '/v2/domains/' + zone + '/records';
|
||||||
|
|
||||||
console.info('Adding TXT', data);
|
// console.info('Adding TXT', data);
|
||||||
return request({
|
return request({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: url,
|
url: url,
|
||||||
|
@ -115,18 +114,18 @@ module.exports.create = function(config) {
|
||||||
remove: function(data) {
|
remove: function(data) {
|
||||||
var ch = data.challenge;
|
var ch = data.challenge;
|
||||||
var domainRecord = ch.identifier.value;
|
var domainRecord = ch.identifier.value;
|
||||||
|
|
||||||
// Digital ocean provides the api to remove records by ID. So we first get the recordId and use it to remove the domain record
|
// Digital ocean provides the api to remove records by ID. So we first get the recordId and use it to remove the domain record
|
||||||
return helpers.getDomain(domainRecord).then(function(zone) {
|
return helpers.getDomain(domainRecord).then(function(zone) {
|
||||||
var dnsPrefix = ch.dnsHost.replace(new RegExp('.' + zone + '$'), '');
|
var dnsPrefix = ch.dnsHost.replace(new RegExp('.' + zone + '$'), '');
|
||||||
|
|
||||||
console.info('Removing TXT', data);
|
// console.info('Removing TXT', data);
|
||||||
var payload = {
|
var payload = {
|
||||||
dnsPrefix: dnsPrefix,
|
dnsPrefix: dnsPrefix,
|
||||||
zone: zone,
|
zone: zone,
|
||||||
txt: ch.dnsAuthorization
|
txt: ch.dnsAuthorization
|
||||||
};
|
};
|
||||||
|
|
||||||
return helpers.getTXTRecord(payload).then(function(txtRecord) {
|
return helpers.getTXTRecord(payload).then(function(txtRecord) {
|
||||||
if (txtRecord) {
|
if (txtRecord) {
|
||||||
var url =
|
var url =
|
||||||
|
@ -141,7 +140,6 @@ module.exports.create = function(config) {
|
||||||
}
|
}
|
||||||
}).then(function(resp) {
|
}).then(function(resp) {
|
||||||
resp = resp.body;
|
resp = resp.body;
|
||||||
console.log(resp);
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -152,21 +150,20 @@ module.exports.create = function(config) {
|
||||||
},
|
},
|
||||||
get: function(data) {
|
get: function(data) {
|
||||||
var ch = data.challenge;
|
var ch = data.challenge;
|
||||||
var domainRecord = data.challenge.altname;
|
var domainRecord = ch.identifier.value;
|
||||||
console.log('DATA:xx', data);
|
|
||||||
|
|
||||||
return helpers.getDomain(domainRecord).then(function(zone) {
|
return helpers.getDomain(domainRecord).then(function(zone) {
|
||||||
var dnsPrefix = ch.dnsHost.replace(new RegExp('.' + zone + '$'), '');
|
var dnsPrefix = domainRecord.replace(new RegExp('.' + zone + '$'), '');
|
||||||
|
|
||||||
console.info('Fetching TXT', data);
|
// console.info('Fetching TXT', data);
|
||||||
var payload = {
|
var payload = {
|
||||||
dnsPrefix: dnsPrefix,
|
dnsPrefix: dnsPrefix,
|
||||||
zone: zone,
|
zone: zone,
|
||||||
txt: data.dnsAuthorization
|
txt: ch.dnsAuthorization
|
||||||
};
|
};
|
||||||
return helpers.getTXTRecord(payload).then(function(txtRecord) {
|
return helpers.getTXTRecord(payload).then(function(txtRecord) {
|
||||||
if (txtRecord) {
|
if (txtRecord) {
|
||||||
return { dnsAuthorization: entry.data };
|
return { dnsAuthorization: txtRecord.data };
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue