Compare commits

..

2 Commits

Author SHA1 Message Date
AJ ONeal d80562fbf7 v3.0.0: Gandi + Let's Encrypt for Node.js 2019-07-11 22:20:52 -06:00
AJ ONeal 806b0e4535 make prettier 2019-07-11 21:58:22 -06:00
6 changed files with 209 additions and 118 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
.env
# ---> Node # ---> Node
# Logs # Logs
logs logs

View File

@ -1,39 +1,47 @@
# [acme-dns-01-gandi.js](https://git.rootprojects.org/root/acme-dns-01-gandi.js) | a [Root](https://rootprojects.org/) project # [acme-dns-01-gandi.js](https://git.rootprojects.org/root/acme-dns-01-gandi.js) | a [Root](https://rootprojects.org/) project
###### Gandi LiveDNS + Let's Encrypt for Node.js - ACME dns-01 challenges w/ ACME.js and Greenlock.js Gandi LiveDNS + Let's Encrypt for Node.js - ACME dns-01 challenges w/ ACME.js and Greenlock.js
###### This handles ACME dns-01 challenges, compatible with ACME.js and Greenlock.js. Passes acme-dns-01-test.
This handles ACME dns-01 challenges, compatible with ACME.js and Greenlock.js. Passes acme-dns-01-test.
# Features # Features
* Compatible
* Lets Encrypt v2.1 / ACME draft 18 (2019) - Compatible
* Gandi.net LiveDNS API - Lets Encrypt v2.1 / ACME draft 18 (2019)
* ACME.js, Greenlock.js, and others - Gandi.net LiveDNS API
* Quality - ACME.js, Greenlock.js, and others
* node v6 compatible VanillaJS - Quality
* < 150 lines of code - node v6 compatible VanillaJS
* Zero Dependencies - < 150 lines of code
- Zero Dependencies
# Install # Install
`npm install --save acme-dns-01-gandi`
```js
npm install --save acme-dns-01-gandi
```
Generate Gandi LiveDNS API Token: Generate Gandi LiveDNS API Token:
* Login to your account at: https://account.gandi.net/ - Login to your account at: https://account.gandi.net/
* Under the Security section, click the link next to 'Production API key' to generate a token. - Under the Security section, click the link next to 'Production API key' to generate a token.
# Usage # Usage
First you create an instance with your credentials: First you create an instance with your credentials:
``` ```js
var dns01 = require('acme-dns-01-gandi').create({ var dns01 = require('acme-dns-01-gandi').create({
baseUrl: 'https://dns.api.gandi.net/api/v5/', // default baseUrl: 'https://dns.api.gandi.net/api/v5/', // default
token: 'xxxx' token: 'xxxx'
}); });
``` ```
Then you can use it with any compatible ACME library, such as Greenlock.js or ACME.js. Then you can use it with any compatible ACME library, such as Greenlock.js or ACME.js.
## Greenlock.js ## Greenlock.js
```
```js
var Greenlock = require('greenlock-express'); var Greenlock = require('greenlock-express');
var greenlock = Greenlock.create({ var greenlock = Greenlock.create({
challenges: { challenges: {
@ -42,28 +50,28 @@ var greenlock = Greenlock.create({
} }
}); });
``` ```
See [Greenlock Express](https://git.rootprojects.org/root/greenlock-express.js) and/or [Greenlock.js](https://git.rootprojects.org/root/greenlock.js) documentation for more details. See [Greenlock Express](https://git.rootprojects.org/root/greenlock-express.js) and/or [Greenlock.js](https://git.rootprojects.org/root/greenlock.js) documentation for more details.
## ACME.js ## ACME.js
``` ```js
// TODO // TODO
``` ```
See the [ACME.js](https://git.rootprojects.org/root/acme-v2.js) for more details. See the [ACME.js](https://git.rootprojects.org/root/acme-v2.js) for more details.
## Build your own ## Build your own
There are only 5 methods: There are only 5 methods:
* ```init(config)``` - `init(config)`
* ```zones(opts)``` - `zones(opts)`
* ```set(opts)``` - `set(opts)`
* ```get(opts)``` - `get(opts)`
* ```remove(opts)``` - `remove(opts)`
``` ```js
dns01 dns01
.set({ .set({
identifier: { value: 'foo.example.co.uk' }, identifier: { value: 'foo.example.co.uk' },
@ -79,19 +87,27 @@ dns01
console.log('Failed to set TXT record'); console.log('Failed to set TXT record');
}); });
``` ```
See acme-dns-01-test for more implementation details. See acme-dns-01-test for more implementation details.
# Tests # Tests
```
```bash
# node ./test.js domain-zone api-token # node ./test.js domain-zone api-token
node ./test.js example.com xxxxxx node ./test.js example.com xxxxxx
``` ```
# Authors # Authors
* Jarom Bridges
* AJ ONeal - Jarom Bridges
- AJ ONeal
See AUTHORS for contact info. See AUTHORS for contact info.
# Legal # Legal
[acme-dns-01-gandi.js](https://git.coolaj86.com/coolaj86/acme-dns-01-gandi.js) | MPL-2.0 | [Terms of Use](https://therootcompany.com/legal/#terms) | [Privacy Policy](https://therootcompany.com/legal/#privacy) [acme-dns-01-gandi.js](https://git.coolaj86.com/coolaj86/acme-dns-01-gandi.js) | MPL-2.0 | [Terms of Use](https://therootcompany.com/legal/#terms) | [Privacy Policy](https://therootcompany.com/legal/#privacy)
Copyright 2019 Jarom Bridges
Copyright 2019 AJ ONeal
Copyright 2019 The Root Group LLC Copyright 2019 The Root Group LLC

View File

@ -4,20 +4,19 @@ var defaults = {
baseUrl: 'https://dns.api.gandi.net/api/v5/' baseUrl: 'https://dns.api.gandi.net/api/v5/'
}; };
module.exports.create = function (config) { module.exports.create = function(config) {
var baseUrl = (config.baseUrl || defaults.baseUrl).replace(/\/$/, ''); var baseUrl = (config.baseUrl || defaults.baseUrl).replace(/\/$/, '');
var authtoken = config.token; var authtoken = config.token;
var request; var request;
return { return {
init: function (opts) { init: function(opts) {
request = opts.request; request = opts.request;
return null; return null;
}, },
zones: function (opts) { zones: function(opts) {
console.log(opts); //console.log(opts);
return request({ return request({
method: 'GET', method: 'GET',
url: baseUrl + '/zones', url: baseUrl + '/zones',
@ -25,97 +24,140 @@ module.exports.create = function (config) {
'X-Api-Key': authtoken 'X-Api-Key': authtoken
}, },
json: true json: true
}).then(function (resp) { }).then(function(resp) {
return resp.body.map(function (zone) { return resp.body.map(function(zone) {
return zone.name; return zone.name;
});; });
});; });
}, },
set: function (opts) { set: function(opts) {
console.log(opts); //console.log(opts);
return request({ return request({
method: 'GET', method: 'GET',
url: baseUrl + '/domains/' + opts.challenge.dnsZone + '/records/' + opts.challenge.dnsPrefix + '/TXT', url:
baseUrl +
'/domains/' +
opts.challenge.dnsZone +
'/records/' +
opts.challenge.dnsPrefix +
'/TXT',
headers: { headers: {
'X-Api-Key': authtoken 'X-Api-Key': authtoken
}, },
json: true json: true
}).then(function (resp) { }).then(function(resp) {
if (resp.body.cause === 'Not Found') { function create() {
return request({ return request({
method: 'POST', method: 'POST',
url: baseUrl + '/domains/' + opts.challenge.dnsZone + '/records', url:
baseUrl +
'/domains/' +
opts.challenge.dnsZone +
'/records',
headers: { headers: {
'X-Api-Key': authtoken 'X-Api-Key': authtoken
}, },
json: { json: {
'rrset_name': opts.challenge.dnsPrefix, rrset_name: opts.challenge.dnsPrefix,
'rrset_type': 'TXT', rrset_type: 'TXT',
'rrset_ttl': 300, rrset_ttl: 300,
'rrset_values': [opts.challenge.dnsAuthorization] rrset_values: [opts.challenge.dnsAuthorization]
} }
}) });
} else {
const body = resp.body
let value = body.rrset_values.map(x => JSON.parse(x))
if (body.rrset_values) {
return request({
method: 'PUT',
url: baseUrl + '/domains/' + opts.challenge.dnsZone + '/records/' + opts.challenge.dnsPrefix + '/TXT',
headers: {
'X-Api-Key': authtoken
},
json: {
'rrset_ttl': 300,
'rrset_values': value.concat([opts.challenge.dnsAuthorization])
}
})
}
} }
});;
function replace() {
var body = resp.body;
var value = body.rrset_values.map(function(x) {
return JSON.parse(x);
});
if (!body.rrset_values) {
return null;
}
return request({
method: 'PUT',
url:
baseUrl +
'/domains/' +
opts.challenge.dnsZone +
'/records/' +
opts.challenge.dnsPrefix +
'/TXT',
headers: {
'X-Api-Key': authtoken
},
json: {
rrset_ttl: 300,
rrset_values: value.concat([
opts.challenge.dnsAuthorization
])
}
});
}
if (resp.body.cause === 'Not Found') {
return create();
} else {
return replace();
}
});
}, },
remove: function (opts) { remove: function(opts) {
console.log(opts); //console.log(opts);
return request({ return request({
method: 'DELETE', method: 'DELETE',
url: baseUrl + '/domains/' + opts.challenge.dnsZone + '/records/' + opts.challenge.dnsPrefix + '/TXT', url:
baseUrl +
'/domains/' +
opts.challenge.dnsZone +
'/records/' +
opts.challenge.dnsPrefix +
'/TXT',
headers: { headers: {
'X-Api-Key': authtoken 'X-Api-Key': authtoken
}, },
json: true json: true
}) });
}, },
get: function (opts) { get: function(opts) {
console.log(opts); //console.log(opts);
return request({ return request({
method: 'GET', method: 'GET',
url: baseUrl + '/domains/' + opts.challenge.dnsZone + '/records/' + opts.challenge.dnsPrefix, url:
baseUrl +
'/domains/' +
opts.challenge.dnsZone +
'/records/' +
opts.challenge.dnsPrefix,
headers: { headers: {
'X-Api-Key': authtoken 'X-Api-Key': authtoken
}, },
json: true json: true
}).then(function (resp) { }).then(function(resp) {
const body = resp.body var body = resp.body;
if (body.length > 0) { if (!(body.length > 0)) {
let value = body[0].rrset_values.map(x => JSON.parse(x)).filter(field => field === opts.challenge.dnsAuthorization) return null;
if (value !== []) {
return {
dnsAuthorization: value[0]
}
} else {
return null
}
} else {
return null
} }
})
var value = body[0].rrset_values
.map(function(x) {
return JSON.parse(x);
})
.filter(function(field) {
return field === opts.challenge.dnsAuthorization;
})[0];
if (!value) {
return null;
}
return {
dnsAuthorization: value
};
});
} }
} };
}; };

29
package-lock.json generated Normal file
View File

@ -0,0 +1,29 @@
{
"name": "acme-dns-01-gandi",
"version": "3.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@root/request": {
"version": "1.3.11",
"resolved": "https://registry.npmjs.org/@root/request/-/request-1.3.11.tgz",
"integrity": "sha512-3a4Eeghcjsfe6zh7EJ+ni1l8OK9Fz2wL1OjP4UCa0YdvtH39kdXB9RGWuzyNv7dZi0+Ffkc83KfH0WbPMiuJFw==",
"dev": true
},
"acme-challenge-test": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/acme-challenge-test/-/acme-challenge-test-3.3.2.tgz",
"integrity": "sha512-0AbMcaON20wpI5vzFDAqwcv2VerY4xIlNCqX0w1xEJUIu/EQtQNmkje+rKNuy2TUl2KBMdIaR6YBbJUdaEiC4w==",
"dev": true,
"requires": {
"@root/request": "^1.3.11"
}
},
"dotenv": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.0.0.tgz",
"integrity": "sha512-30xVGqjLjiUOArT4+M5q9sYdvuR4riM6yK9wMcas9Vbp6zZa+ocC9dp6QoftuhTPhFAiLK/0C5Ni2nou/Bk8lg==",
"dev": true
}
}
}

View File

@ -1,27 +1,28 @@
{ {
"name": "acme-dns-01-gandi", "name": "acme-dns-01-gandi",
"version": "0.0.1", "version": "3.0.0",
"description": "Gandi + Let's Encrypt for Node.js - ACME dns-01 challenges w/ ACME.js and Greenlock.js", "description": "Gandi + Let's Encrypt for Node.js - ACME dns-01 challenges w/ 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.coolaj86.com/coolaj86/acme-dns-01-gandi.js.git" "url": "https://git.coolaj86.com/coolaj86/acme-dns-01-gandi.js.git"
}, },
"keywords": [ "keywords": [
"digitalocean", "digitalocean",
"digital-ocean", "digital-ocean",
"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",
"devDependencies": { "devDependencies": {
"dotenv": "^8.0.0" "acme-challenge-test": "^3.3.2",
} "dotenv": "^8.0.0"
}
} }

View File

@ -3,6 +3,7 @@
// See https://git.coolaj86.com/coolaj86/acme-challenge-test.js // See https://git.coolaj86.com/coolaj86/acme-challenge-test.js
var tester = require('acme-challenge-test'); var tester = require('acme-challenge-test');
require('dotenv').config();
// Usage: node ./test.js example.com xxxxxxxxx // Usage: node ./test.js example.com xxxxxxxxx
var zone = process.argv[2] || process.env.ZONE; var zone = process.argv[2] || process.env.ZONE;