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