update to list zones
This commit is contained in:
		
							parent
							
								
									1afddd9aae
								
							
						
					
					
						commit
						c7cda58cc1
					
				
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | |||||||
|  | *secret* | ||||||
|  | node_modules | ||||||
							
								
								
									
										55
									
								
								lib/index.js
									
									
									
									
									
								
							
							
						
						
									
										55
									
								
								lib/index.js
									
									
									
									
									
								
							| @ -11,16 +11,34 @@ module.exports.create = function(config) { | |||||||
| 	var baseUrl = config.baseUrl || defaults.baseUrl; | 	var baseUrl = config.baseUrl || defaults.baseUrl; | ||||||
| 	var apiKey = config.apiKey; | 	var apiKey = config.apiKey; | ||||||
| 	return { | 	return { | ||||||
|  | 		zones: function(data) { | ||||||
|  | 			var url = baseUrl + 'v1/dns/list'; | ||||||
|  | 			return request({ | ||||||
|  | 				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.body); | ||||||
|  | 					throw new Error('Could not get list of zones. Check api key, etc'); | ||||||
|  | 				} | ||||||
|  | 			}); | ||||||
|  | 		}, | ||||||
| 		set: function(data) { | 		set: function(data) { | ||||||
| 			var ch = data.challenge; | 			var ch = data.challenge; | ||||||
| 			var domainname = ch.identifier.value; |  | ||||||
| 			var zone = domainname; |  | ||||||
| 			var dnsPrefix = ch.dnsHost.replace(new RegExp('.' + zone + '$'), ''); |  | ||||||
| 			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'; | 			var url = baseUrl + 'v1/dns/create_record'; | ||||||
| 
 | 
 | ||||||
| 			console.log('adding txt', data); | 			//console.debug('adding txt', data);
 | ||||||
| 			return request({ | 			return request({ | ||||||
| 				method: 'POST', | 				method: 'POST', | ||||||
| 				url: url, | 				url: url, | ||||||
| @ -29,32 +47,28 @@ module.exports.create = function(config) { | |||||||
| 				}, | 				}, | ||||||
| 				form: { | 				form: { | ||||||
| 					type: 'TXT', | 					type: 'TXT', | ||||||
| 					name: dnsPrefix, | 					name: ch.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: ch.dnsZone, | ||||||
| 					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.error(resp.statusCode); | ||||||
| 					console.log(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'); | ||||||
| 				} | 				} | ||||||
| 			}); | 			}); | ||||||
| 		}, | 		}, | ||||||
| 		remove: function(data) { | 		remove: function(data) { | ||||||
| 			var ch = data.challenge; | 			var ch = data.challenge; | ||||||
| 			var domainname = data.challenge.altname; |  | ||||||
| 			var zone = domainname; |  | ||||||
| 
 |  | ||||||
| 			var url = baseUrl + 'v1/dns/records'; | 			var url = baseUrl + 'v1/dns/records'; | ||||||
| 
 | 
 | ||||||
| 			return request({ | 			return request({ | ||||||
| 				method: 'GET', | 				method: 'GET', | ||||||
| 				url: url + '?domain=' + config.domain, | 				url: url + '?domain=' + ch.dnsZone, | ||||||
| 				// PROBLEM (fixed): Remember to set json: true (not need to JSON.parse)
 |  | ||||||
| 				json: true, | 				json: true, | ||||||
| 				headers: { | 				headers: { | ||||||
| 					'API-Key': apiKey | 					'API-Key': apiKey | ||||||
| @ -63,7 +77,7 @@ module.exports.create = function(config) { | |||||||
| 				.then(function(resp) { | 				.then(function(resp) { | ||||||
| 					if (resp.statusCode == 200) { | 					if (resp.statusCode == 200) { | ||||||
| 						resp = resp.body; | 						resp = resp.body; | ||||||
| 						console.log(resp); | 						//console.debug(resp);
 | ||||||
| 						var entries = resp.filter(function(x) { | 						var entries = resp.filter(function(x) { | ||||||
| 							return x.type === 'TXT'; | 							return x.type === 'TXT'; | ||||||
| 						}); | 						}); | ||||||
| @ -89,8 +103,6 @@ module.exports.create = function(config) { | |||||||
| 					} | 					} | ||||||
| 				}) | 				}) | ||||||
| 				.then(function(recordId) { | 				.then(function(recordId) { | ||||||
| 					var domainname = data.challenge.altname; |  | ||||||
| 					var zone = domainname; |  | ||||||
| 					var url = baseUrl + 'v1/dns/delete_record'; | 					var url = baseUrl + 'v1/dns/delete_record'; | ||||||
| 
 | 
 | ||||||
| 					return request({ | 					return request({ | ||||||
| @ -100,15 +112,15 @@ module.exports.create = function(config) { | |||||||
| 							'API-Key': apiKey | 							'API-Key': apiKey | ||||||
| 						}, | 						}, | ||||||
| 						form: { | 						form: { | ||||||
| 							domain: config.domain, | 							domain: ch.dnsZone, | ||||||
| 							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.error(resp.statusCode); | ||||||
| 							console.log(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' | ||||||
| 							); | 							); | ||||||
| @ -118,16 +130,15 @@ module.exports.create = function(config) { | |||||||
| 		}, | 		}, | ||||||
| 		get: function(data) { | 		get: function(data) { | ||||||
| 			var ch = data.challenge; | 			var ch = data.challenge; | ||||||
| 			var domainname = data.challenge.altname; |  | ||||||
| 			var url = baseUrl + 'v1/dns/records'; | 			var url = baseUrl + 'v1/dns/records'; | ||||||
| 			console.log('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 request({ | ||||||
| 				method: 'GET', | 				method: 'GET', | ||||||
| 				url: url + '?domain=' + config.domain, | 				url: url + '?domain=' + ch.dnsZone, | ||||||
| 				json: true, | 				json: true, | ||||||
| 				headers: { | 				headers: { | ||||||
| 					'API-Key': apiKey | 					'API-Key': apiKey | ||||||
|  | |||||||
							
								
								
									
										28
									
								
								package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @ -0,0 +1,28 @@ | |||||||
|  | { | ||||||
|  | 	"name": "acme-dns-01-vultr", | ||||||
|  | 	"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==" | ||||||
|  | 		}, | ||||||
|  | 		"acme-challenge-test": { | ||||||
|  | 			"version": "3.2.1", | ||||||
|  | 			"resolved": "https://registry.npmjs.org/acme-challenge-test/-/acme-challenge-test-3.2.1.tgz", | ||||||
|  | 			"integrity": "sha512-8MwL2oWx7vM/SBIeEQfeoRyW0kYCtLFS4FfgIx3lsQmSKhbDo9J88Ud6DejdupRp2T+DlEkWIBVI3qOCVViUaQ==", | ||||||
|  | 			"dev": true | ||||||
|  | 		}, | ||||||
|  | 		"acme-dns-01-test": { | ||||||
|  | 			"version": "3.2.1", | ||||||
|  | 			"resolved": "https://registry.npmjs.org/acme-dns-01-test/-/acme-dns-01-test-3.2.1.tgz", | ||||||
|  | 			"integrity": "sha512-m4UxltZzTNbQTK30iQQ6BQ99oRJA9p69+eg/u/Plxiw10bD+qsmRZR9rsqZuiSc62wfng/upGvXWMQZ/csn3lA==", | ||||||
|  | 			"dev": true, | ||||||
|  | 			"requires": { | ||||||
|  | 				"acme-challenge-test": "^3.2.0" | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @ -24,6 +24,6 @@ | |||||||
| 		"@root/request": "^1.3.11" | 		"@root/request": "^1.3.11" | ||||||
| 	}, | 	}, | ||||||
| 	"devDependencies": { | 	"devDependencies": { | ||||||
| 		"acme-challenge-test": "^3.1.2" | 		"acme-dns-01-test": "^3.2.1" | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										30
									
								
								test.js
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								test.js
									
									
									
									
									
								
							| @ -1,42 +1,24 @@ | |||||||
| #!/usr/bin/env node
 | #!/usr/bin/env node
 | ||||||
| 'use strict'; | 'use strict'; | ||||||
| 
 | 
 | ||||||
| // https://git.coolaj86.com/coolaj86/acme-challenge-test.js
 | // https://git.rootprojects.org/root/acme-dns-01-test.js
 | ||||||
| var tester = require('acme-challenge-test'); | var tester = require('acme-dns-01-test'); | ||||||
| 
 | 
 | ||||||
| // Usage: node ./test.js example.com xxxxxxxxx
 | // Usage: node ./test.js example.com xxxxxxxxx
 | ||||||
| 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 |  | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| // The dry-run tests can pass on, literally, 'example.com'
 | // The dry-run tests can pass on, literally, 'example.com'
 | ||||||
| // but the integration tests require that you have control over the domain
 | // but the integration tests require that you have control over the domain
 | ||||||
| var domain = zone; |  | ||||||
| 
 |  | ||||||
| tester | tester | ||||||
| 	.test('dns-01', domain, challenger) | 	.testZone('dns-01', zone, challenger) | ||||||
| 	.then(function() { | 	.then(function() { | ||||||
| 		console.info('PASS', domain); | 		console.info('PASS', zone); | ||||||
| 		///*
 |  | ||||||
| 		domain = 'foo.' + zone; |  | ||||||
| 
 |  | ||||||
| 		return tester |  | ||||||
| 			.test('dns-01', domain, challenger) |  | ||||||
| 			.then(function() { |  | ||||||
| 				console.info('PASS', domain); |  | ||||||
| 			}) |  | ||||||
| 			.then(function() { |  | ||||||
| 				domain = '*.foo.' + zone; |  | ||||||
| 
 |  | ||||||
| 				return tester.test('dns-01', domain, challenger).then(function() { |  | ||||||
| 					console.info('PASS', domain); |  | ||||||
| 				}); |  | ||||||
| 			}); |  | ||||||
| 		//*/
 |  | ||||||
| 	}) | 	}) | ||||||
| 	.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