make Prettier
This commit is contained in:
parent
c33c42899f
commit
393d25621c
66
lib/index.js
66
lib/index.js
|
@ -11,18 +11,18 @@ var defaults = {
|
|||
};
|
||||
|
||||
module.exports.create = function(config) {
|
||||
var baseUrl = (config.baseUrl || defaults.baseUrl);
|
||||
var baseUrl = config.baseUrl || defaults.baseUrl;
|
||||
var apiKey = config.key || config.apiKey;
|
||||
var apiSecret = config.secret || config.apiSecret;
|
||||
|
||||
var auth = 'sso-key '+apiKey+':'+apiSecret;
|
||||
var auth = 'sso-key ' + apiKey + ':' + apiSecret;
|
||||
|
||||
function api(method, path, form) {
|
||||
return request({
|
||||
method: method,
|
||||
url: baseUrl + path,
|
||||
headers: {
|
||||
'Authorization': auth
|
||||
Authorization: auth
|
||||
},
|
||||
json: form || true
|
||||
});
|
||||
|
@ -45,7 +45,6 @@ module.exports.create = function(config) {
|
|||
return resp.body.map(function(x) {
|
||||
return x.domain;
|
||||
});
|
||||
|
||||
});
|
||||
},
|
||||
set: function(data) {
|
||||
|
@ -53,37 +52,43 @@ module.exports.create = function(config) {
|
|||
var txt = ch.dnsAuthorization;
|
||||
// If the domain to be verified is
|
||||
|
||||
|
||||
// optional params commented
|
||||
var records = [
|
||||
{
|
||||
"data": txt,
|
||||
"name": ch.dnsPrefix,
|
||||
data: txt,
|
||||
name: ch.dnsPrefix,
|
||||
// "port": 0,
|
||||
// "priority": 0,
|
||||
// "protocol": "string",
|
||||
// "service": "string",
|
||||
"ttl": 600,
|
||||
"type": "TXT",
|
||||
ttl: 600,
|
||||
type: 'TXT'
|
||||
// "weight": 0
|
||||
}
|
||||
];
|
||||
|
||||
return api('PATCH', 'domains/'+ch.dnsZone+'/records', records).then(function(resp) {
|
||||
return api('PATCH', 'domains/' + ch.dnsZone + '/records', records).then(
|
||||
function(resp) {
|
||||
if (200 !== resp.statusCode) {
|
||||
console.error(resp.statusCode);
|
||||
console.error(resp.body);
|
||||
throw new Error('record did not set. check subdomain, api key, etc');
|
||||
throw new Error(
|
||||
'record did not set. check subdomain, api key, etc'
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
);
|
||||
},
|
||||
remove: function(data) {
|
||||
var ch = data.challenge;
|
||||
|
||||
// get all domain records of type or name
|
||||
return api('GET', 'domains/'+ch.dnsZone+'/records/TXT/'+ch.dnsPrefix)
|
||||
return api(
|
||||
'GET',
|
||||
'domains/' + ch.dnsZone + '/records/TXT/' + ch.dnsPrefix
|
||||
)
|
||||
.then(function(resp) {
|
||||
if (200 !== resp.statusCode) {
|
||||
console.error(resp.statusCode);
|
||||
|
@ -95,11 +100,12 @@ module.exports.create = function(config) {
|
|||
// filter all TXT records without record to remove
|
||||
for (let i = 0; i < resp.body.length; i++) {
|
||||
if (resp.body[i]['data'] !== ch.dnsAuthorization) {
|
||||
newEntries.push(resp.body[i])
|
||||
newEntries.push(resp.body[i]);
|
||||
}
|
||||
}
|
||||
return newEntries;
|
||||
}).then(function(newRecords) {
|
||||
})
|
||||
.then(function(newRecords) {
|
||||
// godaddy doesn't provide an endpoint for a single record removal
|
||||
// but provides this endpoint to replace all records of a given type
|
||||
// https://developer.godaddy.com/doc/endpoint/domains#/v1/recordReplaceType
|
||||
|
@ -107,42 +113,48 @@ module.exports.create = function(config) {
|
|||
// hence when only a single record of type exists and is the one to remove
|
||||
// we call the endpoint with this dummy record
|
||||
|
||||
if(!newRecords.length) {
|
||||
if (!newRecords.length) {
|
||||
newRecords.push({
|
||||
"data": 'free_to_delete',
|
||||
"name": 'remove_placeholder',
|
||||
"ttl": 600
|
||||
|
||||
data: 'free_to_delete',
|
||||
name: 'remove_placeholder',
|
||||
ttl: 600
|
||||
});
|
||||
}
|
||||
|
||||
// update - overwrite all type and name records under domain
|
||||
return api('PUT', 'domains/'+ch.dnsZone+'/records/TXT', newRecords).then(function(resp) {
|
||||
return api(
|
||||
'PUT',
|
||||
'domains/' + ch.dnsZone + '/records/TXT',
|
||||
newRecords
|
||||
).then(function(resp) {
|
||||
if (200 !== resp.statusCode) {
|
||||
console.error(resp.statusCode);
|
||||
console.error(resp.body);
|
||||
throw new Error('record did not remove. check subdomain, api key, etc');
|
||||
throw new Error(
|
||||
'record did not remove. check subdomain, api key, etc'
|
||||
);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
get: function(data) {
|
||||
var ch = data.challenge;
|
||||
return api('GET', 'domains/'+ch.dnsZone+'/records/TXT/'+ch.dnsPrefix).then(function(resp) {
|
||||
return api(
|
||||
'GET',
|
||||
'domains/' + ch.dnsZone + '/records/TXT/' + ch.dnsPrefix
|
||||
).then(function(resp) {
|
||||
resp = resp.body;
|
||||
|
||||
var entry = null;
|
||||
|
||||
if(resp.length) {
|
||||
if (resp.length) {
|
||||
entry = resp.filter(function(x) {
|
||||
return x.data === ch.dnsAuthorization;
|
||||
})[0];
|
||||
}
|
||||
|
||||
return entry? { dnsAuthorization: entry.data }:null;
|
||||
return entry ? { dnsAuthorization: entry.data } : null;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue