add .prettierrc, and make prettier

This commit is contained in:
AJ ONeal 2019-06-13 03:53:54 -06:00
parent 3cd68f93e8
commit 1afddd9aae
4 changed files with 80 additions and 65 deletions

8
.prettierrc Normal file
View File

@ -0,0 +1,8 @@
{
"bracketSpacing": true,
"printWidth": 80,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": true
}

View File

@ -30,14 +30,14 @@ module.exports.create = function(config) {
form: { form: {
type: 'TXT', type: 'TXT',
name: dnsPrefix, name: dnsPrefix,
data: '"'+txt+'"', // vultr requires the TXT record wraped in quotes data: '"' + txt + '"', // vultr requires the TXT record wraped in quotes
domain: config.domain, domain: config.domain,
ttl: 300 ttl: 300
} }
}).then(function(resp) { }).then(function(resp) {
if(resp.statusCode==200){ if (resp.statusCode == 200) {
return true; return true;
}else{ } else {
console.log(resp.statusCode); console.log(resp.statusCode);
console.log(resp.body); console.log(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');
@ -53,37 +53,40 @@ module.exports.create = function(config) {
return request({ return request({
method: 'GET', method: 'GET',
url: url+'?domain='+config.domain, url: url + '?domain=' + config.domain,
// PROBLEM (fixed): Remember to set json: true (not need to JSON.parse) // PROBLEM (fixed): Remember to set json: true (not need to JSON.parse)
json: true, json: true,
headers: { headers: {
'API-Key': apiKey 'API-Key': apiKey
} }
}).then(function(resp) { })
if(resp.statusCode==200){ .then(function(resp) {
resp = resp.body; if (resp.statusCode == 200) {
console.log(resp); resp = resp.body;
var entries = console.log(resp);
resp.filter(function(x) { var entries = resp.filter(function(x) {
return x.type === 'TXT'; return x.type === 'TXT';
}); });
var entry = entries.filter(function(x) { var entry = entries.filter(function(x) {
// vultr wraps the TXT record in double quotes // vultr wraps the TXT record in double quotes
return x.data.substring(1, x.data.length - 1) === ch.dnsAuthorization; return (
})[0]; x.data.substring(1, x.data.length - 1) === ch.dnsAuthorization
);
})[0];
if (entry) { if (entry) {
return entry['RECORDID']; return entry['RECORDID'];
} else {
throw new Error(
"Couldn't remove record. check subdomain, api key, etc"
);
}
} else { } else {
throw new Error( throw new Error(
"Couldn't remove record. check subdomain, api key, etc" 'record did not set. check subdomain, api key, etc'
); );
} }
}else{
throw new Error("record did not set. check subdomain, api key, etc");
}
}) })
.then(function(recordId) { .then(function(recordId) {
var domainname = data.challenge.altname; var domainname = data.challenge.altname;
@ -94,19 +97,21 @@ module.exports.create = function(config) {
method: 'POST', method: 'POST',
url: url, url: url,
headers: { headers: {
'API-Key': apiKey 'API-Key': apiKey
}, },
form: { form: {
domain: config.domain, domain: config.domain,
'RECORDID': recordId RECORDID: recordId
} }
}).then(function(resp) { }).then(function(resp) {
if(resp.statusCode==200){ if (resp.statusCode == 200) {
return true; return true;
}else{ } else {
console.log(resp.statusCode); console.log(resp.statusCode);
console.log(resp.body); console.log(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'
);
} }
}); });
}); });
@ -122,16 +127,16 @@ module.exports.create = function(config) {
return request({ return request({
method: 'GET', method: 'GET',
url: url+'?domain='+config.domain, url: url + '?domain=' + config.domain,
json: true, json: true,
headers: { headers: {
'API-Key': apiKey 'API-Key': apiKey
} }
}).then(function(resp) { }).then(function(resp) {
resp = resp.body; resp = resp.body;
var entries = resp.filter(function(x) { var entries = resp.filter(function(x) {
return x.type === 'TXT'; return x.type === 'TXT';
}); });
var entry = entries.filter(function(x) { var entry = entries.filter(function(x) {
@ -140,9 +145,11 @@ module.exports.create = function(config) {
})[0]; })[0];
if (entry) { if (entry) {
return { dnsAuthorization: entry.data.substring(1, entry.data.length - 1)}; return {
dnsAuthorization: entry.data.substring(1, entry.data.length - 1)
};
} else { } else {
return null; return null;
} }
}); });
} }

View File

@ -1,29 +1,29 @@
{ {
"name": "acme-dns-01-vultr", "name": "acme-dns-01-vultr",
"version": "3.0.0", "version": "3.0.0",
"description": "Vultr DNS for Let's Encrypt / ACME dns-01 challenges with ACME.js and Greenlock.js", "description": "Vultr DNS for Let's Encrypt / ACME dns-01 challenges with ACME.js and Greenlock.js",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "node ./test.js" "test": "node ./test.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://git.rootprojects.org/root/acme-dns-01-vultr.git" "url": "https://git.rootprojects.org/root/acme-dns-01-vultr.git"
}, },
"keywords": [ "keywords": [
"vultr", "vultr",
"dns", "dns",
"dns-01", "dns-01",
"letsencrypt", "letsencrypt",
"acme", "acme",
"greenlock" "greenlock"
], ],
"author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)", "author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)",
"license": "MPL-2.0", "license": "MPL-2.0",
"dependencies": { "dependencies": {
"@root/request": "^1.3.11" "@root/request": "^1.3.11"
}, },
"devDependencies": { "devDependencies": {
"acme-challenge-test": "^3.1.2" "acme-challenge-test": "^3.1.2"
} }
} }

View File

@ -8,7 +8,7 @@ var tester = require('acme-challenge-test');
var zone = process.argv[2]; var zone = process.argv[2];
var challenger = require('./index.js').create({ var challenger = require('./index.js').create({
apiKey: process.argv[3], apiKey: process.argv[3],
domain:zone domain: zone
}); });
// The dry-run tests can pass on, literally, 'example.com' // The dry-run tests can pass on, literally, 'example.com'
@ -19,7 +19,7 @@ tester
.test('dns-01', domain, challenger) .test('dns-01', domain, challenger)
.then(function() { .then(function() {
console.info('PASS', domain); console.info('PASS', domain);
///* ///*
domain = 'foo.' + zone; domain = 'foo.' + zone;
return tester return tester
@ -34,7 +34,7 @@ tester
console.info('PASS', domain); console.info('PASS', domain);
}); });
}); });
//*/ //*/
}) })
.catch(function(e) { .catch(function(e) {
console.error(e.message); console.error(e.message);