Compare commits
	
		
			5 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 9b6d363328 | |||
| 6676b6412d | |||
| 5b9417dc44 | |||
|  | c8087a7f53 | ||
| ef5bd3ced2 | 
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -1,2 +1,3 @@ | |||||||
|  | .env | ||||||
| *secret* | *secret* | ||||||
| node_modules | node_modules | ||||||
|  | |||||||
							
								
								
									
										75
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										75
									
								
								README.md
									
									
									
									
									
								
							| @ -1,10 +1,77 @@ | |||||||
| # [acme-dns-01-vultr](https://git.rootprojects.org/root/acme-dns-01-vultr) | a [Root](https://rootrpojects.org) project | # [acme-dns-01-vultr](https://git.rootprojects.org/root/acme-dns-01-vultr.js) | a [Root](https://rootprojects.org) project | ||||||
| 
 | 
 | ||||||
| Vultr DNS for Let's Encrypt / ACME dns-01 challenges with ACME.js and Greenlock.js (Node.js). | Vultr DNS + Let's Encrypt for Node.js | ||||||
|  | 
 | ||||||
|  | This handles ACME dns-01 challenges, compatible with ACME.js and Greenlock.js. | ||||||
|  | Passes [acme-dns-01-test](https://git.rootprojects.org/root/acme-dns-01-test.js). | ||||||
|  | 
 | ||||||
|  | # Install | ||||||
|  | 
 | ||||||
|  | ```bash | ||||||
|  | npm install --save acme-dns-01-vultr@3.x | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | # Usage | ||||||
|  | 
 | ||||||
|  | First you create an instance with your API token: | ||||||
|  | 
 | ||||||
|  | ```js | ||||||
|  | var dns01 = require('acme-dns-01-vultr').create({ | ||||||
|  | 	baseUrl: 'https://api.vultr.com/v1/dns', // default | ||||||
|  | 	token: 'xxxx' | ||||||
|  | }); | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | Then you can use it with any compatible ACME module, | ||||||
|  | such as Greenlock.js or ACME.js. | ||||||
|  | 
 | ||||||
|  | ### Greenlock.js | ||||||
|  | 
 | ||||||
|  | ```js | ||||||
|  | var Greenlock = require('greenlock-express'); | ||||||
|  | var greenlock = Greenlock.create({ | ||||||
|  | 	challenges: { | ||||||
|  | 		'dns-01': dns01 | ||||||
|  | 		// ... | ||||||
|  | 	} | ||||||
|  | }); | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | 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 | ||||||
|  | 
 | ||||||
|  | ```js | ||||||
|  | // TODO | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | See the [ACME.js](https://git.rootprojects.org/root/acme-v2.js) for more details. | ||||||
|  | 
 | ||||||
|  | ### Build your own | ||||||
|  | 
 | ||||||
|  | ```js | ||||||
|  | dns01 | ||||||
|  | 	.set({ | ||||||
|  | 		identifier: { value: 'foo.example.com' }, | ||||||
|  | 		wildcard: false, | ||||||
|  | 		dnsHost: '_acme-challenge.foo.example.com', | ||||||
|  | 		dnsAuthorization: 'xxx_secret_xxx' | ||||||
|  | 	}) | ||||||
|  | 	.then(function() { | ||||||
|  | 		console.log('TXT record set'); | ||||||
|  | 	}) | ||||||
|  | 	.catch(function() { | ||||||
|  | 		console.log('Failed to set TXT record'); | ||||||
|  | 	}); | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | See [acme-dns-01-test](https://git.rootprojects.org/root/acme-dns-01-test.js) | ||||||
|  | for more implementation details. | ||||||
| 
 | 
 | ||||||
| # Tests | # Tests | ||||||
| 
 | 
 | ||||||
| ``` | ```bash | ||||||
| # node ./test.js domain-zone api-token | # node ./test.js domain-zone api-key | ||||||
| node ./test.js example.com xxxxxx | node ./test.js example.com xxxxxx | ||||||
| ``` | ``` | ||||||
|  | |||||||
							
								
								
									
										2
									
								
								example.env
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								example.env
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | |||||||
|  | ZONE=example.co.uk | ||||||
|  | TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | ||||||
							
								
								
									
										152
									
								
								lib/index.js
									
									
									
									
									
								
							
							
						
						
									
										152
									
								
								lib/index.js
									
									
									
									
									
								
							| @ -4,146 +4,120 @@ var request = require('@root/request'); | |||||||
| request = require('util').promisify(request); | request = require('util').promisify(request); | ||||||
| 
 | 
 | ||||||
| var defaults = { | var defaults = { | ||||||
| 	baseUrl: 'https://api.vultr.com/' | 	baseUrl: 'https://api.vultr.com/v1/dns' | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| module.exports.create = function(config) { | module.exports.create = function(config) { | ||||||
| 	var baseUrl = config.baseUrl || defaults.baseUrl; | 	var baseUrl = (config.baseUrl || defaults.baseUrl).replace(/\/$/, ''); | ||||||
| 	var apiKey = config.apiKey; | 	// In all of the other modules the API token is called token,
 | ||||||
|  | 	// but here we support both.
 | ||||||
|  | 	var apiKey = config.token || config.apiKey; | ||||||
|  | 
 | ||||||
|  | 	function api(method, path, form) { | ||||||
|  | 		return request({ | ||||||
|  | 			method: method, | ||||||
|  | 			url: baseUrl + path, | ||||||
|  | 			headers: { | ||||||
|  | 				'API-Key': apiKey | ||||||
|  | 			}, | ||||||
|  | 			json: true, | ||||||
|  | 			form: form | ||||||
|  | 		}); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	return { | 	return { | ||||||
| 		zones: function(data) { | 		zones: function(data) { | ||||||
| 			var url = baseUrl + 'v1/dns/list'; | 			return api('GET', '/list').then(function(resp) { | ||||||
| 			return request({ | 				if (200 !== resp.statusCode) { | ||||||
| 				method: 'GET', |  | ||||||
| 				url: url, |  | ||||||
| 				headers: { |  | ||||||
| 					'API-Key': apiKey |  | ||||||
| 				}, |  | ||||||
| 				json: true |  | ||||||
| 			}).then(function(resp) { |  | ||||||
| 				if (resp.statusCode == 200) { |  | ||||||
| 					return resp.body.map(function(x) { |  | ||||||
| 						return x.domain; |  | ||||||
| 					}); |  | ||||||
| 				} else { |  | ||||||
| 					console.error(resp.statusCode); | 					console.error(resp.statusCode); | ||||||
| 					console.error(resp.body); | 					console.error(resp.body); | ||||||
| 					throw new Error('Could not get list of zones. Check api key, etc'); | 					throw new Error('Could not get list of zones. Check api key, etc'); | ||||||
| 				} | 				} | ||||||
|  | 
 | ||||||
|  | 				return resp.body.map(function(x) { | ||||||
|  | 					return x.domain; | ||||||
|  | 				}); | ||||||
| 			}); | 			}); | ||||||
| 		}, | 		}, | ||||||
| 		set: function(data) { | 		set: function(data) { | ||||||
| 			var ch = data.challenge; | 			var ch = data.challenge; | ||||||
| 			var txt = ch.dnsAuthorization; | 			var txt = ch.dnsAuthorization; | ||||||
| 			// If the domain to be verified is
 | 			// If the domain to be verified is
 | ||||||
| 			var url = baseUrl + 'v1/dns/create_record'; |  | ||||||
| 
 | 
 | ||||||
| 			//console.debug('adding txt', data);
 | 			//console.debug('adding txt', data);
 | ||||||
| 			return request({ | 			return api('POST', '/create_record', { | ||||||
| 				method: 'POST', | 				type: 'TXT', | ||||||
| 				url: url, | 				name: ch.dnsPrefix, | ||||||
| 				headers: { | 				data: '"' + txt + '"', // vultr requires the TXT record wraped in quotes
 | ||||||
| 					'API-Key': apiKey | 				domain: ch.dnsZone, | ||||||
| 				}, | 				ttl: 300 | ||||||
| 				form: { |  | ||||||
| 					type: 'TXT', |  | ||||||
| 					name: ch.dnsPrefix, |  | ||||||
| 					data: '"' + txt + '"', // vultr requires the TXT record wraped in quotes
 |  | ||||||
| 					domain: ch.dnsZone, |  | ||||||
| 					ttl: 300 |  | ||||||
| 				} |  | ||||||
| 			}).then(function(resp) { | 			}).then(function(resp) { | ||||||
| 				if (resp.statusCode == 200) { | 				if (200 !== resp.statusCode) { | ||||||
| 					return true; |  | ||||||
| 				} else { |  | ||||||
| 					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; | ||||||
| 			}); | 			}); | ||||||
| 		}, | 		}, | ||||||
| 		remove: function(data) { | 		remove: function(data) { | ||||||
| 			var ch = data.challenge; | 			var ch = data.challenge; | ||||||
| 			var url = baseUrl + 'v1/dns/records'; |  | ||||||
| 
 | 
 | ||||||
| 			return request({ | 			return api('GET', '/records?domain=' + ch.dnsZone) | ||||||
| 				method: 'GET', |  | ||||||
| 				url: url + '?domain=' + ch.dnsZone, |  | ||||||
| 				json: true, |  | ||||||
| 				headers: { |  | ||||||
| 					'API-Key': apiKey |  | ||||||
| 				} |  | ||||||
| 			}) |  | ||||||
| 				.then(function(resp) { | 				.then(function(resp) { | ||||||
| 					if (resp.statusCode == 200) { | 					if (200 !== resp.statusCode) { | ||||||
| 						resp = resp.body; |  | ||||||
| 						//console.debug(resp);
 |  | ||||||
| 						var entries = resp.filter(function(x) { |  | ||||||
| 							return x.type === 'TXT'; |  | ||||||
| 						}); |  | ||||||
| 
 |  | ||||||
| 						var entry = entries.filter(function(x) { |  | ||||||
| 							// vultr wraps the TXT record in double quotes
 |  | ||||||
| 							return ( |  | ||||||
| 								x.data.substring(1, x.data.length - 1) === ch.dnsAuthorization |  | ||||||
| 							); |  | ||||||
| 						})[0]; |  | ||||||
| 
 |  | ||||||
| 						if (entry) { |  | ||||||
| 							return entry['RECORDID']; |  | ||||||
| 						} else { |  | ||||||
| 							throw new Error( |  | ||||||
| 								"Couldn't remove record. check subdomain, api key, etc" |  | ||||||
| 							); |  | ||||||
| 						} |  | ||||||
| 					} else { |  | ||||||
| 						throw new Error( | 						throw new Error( | ||||||
| 							'record did not set. check subdomain, api key, etc' | 							'record did not set. check subdomain, api key, etc' | ||||||
| 						); | 						); | ||||||
| 					} | 					} | ||||||
|  | 
 | ||||||
|  | 					resp = resp.body; | ||||||
|  | 					//console.debug(resp);
 | ||||||
|  | 					var entries = resp.filter(function(x) { | ||||||
|  | 						return x.type === 'TXT'; | ||||||
|  | 					}); | ||||||
|  | 
 | ||||||
|  | 					var entry = entries.filter(function(x) { | ||||||
|  | 						// vultr wraps the TXT record in double quotes
 | ||||||
|  | 						return ( | ||||||
|  | 							x.data.substring(1, x.data.length - 1) === ch.dnsAuthorization | ||||||
|  | 						); | ||||||
|  | 					})[0]; | ||||||
|  | 
 | ||||||
|  | 					if (entry) { | ||||||
|  | 						return entry.RECORDID; | ||||||
|  | 					} else { | ||||||
|  | 						throw new Error( | ||||||
|  | 							"Couldn't remove record. check subdomain, api key, etc" | ||||||
|  | 						); | ||||||
|  | 					} | ||||||
| 				}) | 				}) | ||||||
| 				.then(function(recordId) { | 				.then(function(recordId) { | ||||||
| 					var url = baseUrl + 'v1/dns/delete_record'; | 					return api('POST', '/delete_record', { | ||||||
| 
 | 						domain: ch.dnsZone, | ||||||
| 					return request({ | 						RECORDID: recordId | ||||||
| 						method: 'POST', |  | ||||||
| 						url: url, |  | ||||||
| 						headers: { |  | ||||||
| 							'API-Key': apiKey |  | ||||||
| 						}, |  | ||||||
| 						form: { |  | ||||||
| 							domain: ch.dnsZone, |  | ||||||
| 							RECORDID: recordId |  | ||||||
| 						} |  | ||||||
| 					}).then(function(resp) { | 					}).then(function(resp) { | ||||||
| 						if (resp.statusCode == 200) { | 						if (200 !== resp.statusCode) { | ||||||
| 							return true; |  | ||||||
| 						} else { |  | ||||||
| 							console.error(resp.statusCode); | 							console.error(resp.statusCode); | ||||||
| 							console.error(resp.body); | 							console.error(resp.body); | ||||||
| 							throw new Error( | 							throw new Error( | ||||||
| 								'record did not remove. check subdomain, api key, etc' | 								'record did not remove. check subdomain, api key, etc' | ||||||
| 							); | 							); | ||||||
| 						} | 						} | ||||||
|  | 
 | ||||||
|  | 						return true; | ||||||
| 					}); | 					}); | ||||||
| 				}); | 				}); | ||||||
| 		}, | 		}, | ||||||
| 		get: function(data) { | 		get: function(data) { | ||||||
| 			var ch = data.challenge; | 			var ch = data.challenge; | ||||||
| 			var url = baseUrl + 'v1/dns/records'; |  | ||||||
| 			//console.debug('getting txt', data);
 | 			//console.debug('getting txt', data);
 | ||||||
| 
 | 
 | ||||||
| 			// Digital ocean provides the api to fetch records by ID. Since we do not have id, we fetch all the records,
 | 			// Digital ocean provides the api to fetch records by ID. Since we do not have id, we fetch all the records,
 | ||||||
| 			// filter the required TXT record
 | 			// filter the required TXT record
 | ||||||
| 
 | 
 | ||||||
| 			return request({ | 			return api('GET', '/records?domain=' + ch.dnsZone).then(function(resp) { | ||||||
| 				method: 'GET', |  | ||||||
| 				url: url + '?domain=' + ch.dnsZone, |  | ||||||
| 				json: true, |  | ||||||
| 				headers: { |  | ||||||
| 					'API-Key': apiKey |  | ||||||
| 				} |  | ||||||
| 			}).then(function(resp) { |  | ||||||
| 				resp = resp.body; | 				resp = resp.body; | ||||||
| 
 | 
 | ||||||
| 				var entries = resp.filter(function(x) { | 				var entries = resp.filter(function(x) { | ||||||
|  | |||||||
							
								
								
									
										8
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										8
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
| 	"name": "acme-dns-01-vultr", | 	"name": "acme-dns-01-vultr", | ||||||
| 	"version": "3.0.0", | 	"version": "3.0.2", | ||||||
| 	"lockfileVersion": 1, | 	"lockfileVersion": 1, | ||||||
| 	"requires": true, | 	"requires": true, | ||||||
| 	"dependencies": { | 	"dependencies": { | ||||||
| @ -23,6 +23,12 @@ | |||||||
| 			"requires": { | 			"requires": { | ||||||
| 				"acme-challenge-test": "^3.2.0" | 				"acme-challenge-test": "^3.2.0" | ||||||
| 			} | 			} | ||||||
|  | 		}, | ||||||
|  | 		"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 | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
| 	"name": "acme-dns-01-vultr", | 	"name": "acme-dns-01-vultr", | ||||||
| 	"version": "3.0.0", | 	"version": "3.0.2", | ||||||
| 	"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": { | ||||||
| @ -24,6 +24,7 @@ | |||||||
| 		"@root/request": "^1.3.11" | 		"@root/request": "^1.3.11" | ||||||
| 	}, | 	}, | ||||||
| 	"devDependencies": { | 	"devDependencies": { | ||||||
| 		"acme-dns-01-test": "^3.2.1" | 		"acme-dns-01-test": "^3.2.1", | ||||||
|  | 		"dotenv": "^8.0.0" | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										10
									
								
								test.js
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										10
									
								
								test.js
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @ -1,13 +1,14 @@ | |||||||
| #!/usr/bin/env node
 | #!/usr/bin/env node
 | ||||||
| 'use strict'; | 'use strict'; | ||||||
| 
 | 
 | ||||||
| // https://git.rootprojects.org/root/acme-dns-01-test.js
 | // See https://git.coolaj86.com/coolaj86/acme-challenge-test.js
 | ||||||
| var tester = require('acme-dns-01-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]; | var zone = process.argv[2] || process.env.ZONE; | ||||||
| var challenger = require('./index.js').create({ | var challenger = require('./index.js').create({ | ||||||
| 	apiKey: process.argv[3] | 	token: process.argv[3] || process.env.TOKEN | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| // The dry-run tests can pass on, literally, 'example.com'
 | // The dry-run tests can pass on, literally, 'example.com'
 | ||||||
| @ -18,7 +19,6 @@ tester | |||||||
| 		console.info('PASS', zone); | 		console.info('PASS', zone); | ||||||
| 	}) | 	}) | ||||||
| 	.catch(function(e) { | 	.catch(function(e) { | ||||||
| 		console.info('FAIL', zone); |  | ||||||
| 		console.error(e.message); | 		console.error(e.message); | ||||||
| 		console.error(e.stack); | 		console.error(e.stack); | ||||||
| 	}); | 	}); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user