Compare commits
	
		
			No commits in common. "138e2ecfaeb7cf40940386a9956870d05e8f5793" and "b54e8236cb0d45f59307b0c44ef5a325da1bf20e" have entirely different histories.
		
	
	
		
			138e2ecfae
			...
			b54e8236cb
		
	
		
							
								
								
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							| @ -1,2 +1 @@ | ||||
| AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/) | ||||
| Hitesh Walia <hiteshwar.walia@gmail.com> | ||||
| @ -100,7 +100,6 @@ node ./test.js example.com johndoe xxxxxx | ||||
| # Authors | ||||
| 
 | ||||
| -   AJ ONeal | ||||
| -   Hitesh Walia | ||||
| 
 | ||||
| See AUTHORS for contact info. | ||||
| 
 | ||||
| @ -108,6 +107,5 @@ See AUTHORS for contact info. | ||||
| 
 | ||||
| [acme-dns-01-dnsimple.js](https://git.coolaj86.com/coolaj86/acme-dns-01-dnsimple.js) | MPL-2.0 | [Terms of Use](https://therootcompany.com/legal/#terms) | [Privacy Policy](https://therootcompany.com/legal/#privacy) | ||||
| 
 | ||||
| Copyright 2019 Hitesh Walia | ||||
| Copyright 2019 AJ ONeal | ||||
| Copyright 2019 The Root Group LLC | ||||
|  | ||||
							
								
								
									
										127
									
								
								lib/index.js
									
									
									
									
									
								
							
							
						
						
									
										127
									
								
								lib/index.js
									
									
									
									
									
								
							| @ -1,140 +1,33 @@ | ||||
| 'use strict'; | ||||
| 
 | ||||
| var request; | ||||
| var defaults = { | ||||
| 	baseUrl: 'https://api.dnsimple.com/v2/' | ||||
| }; | ||||
| var defaults = {}; | ||||
| 
 | ||||
| module.exports.create = function(config) { | ||||
| 	var baseUrl = (config.baseUrl || defaults.baseUrl).replace(/\/$/, ''); | ||||
| 	var token = config.token; | ||||
| 	var account = config.account; | ||||
| 
 | ||||
| 	function api(method, path, form) { | ||||
| 		var req = { | ||||
| 			method: method, | ||||
| 			url: baseUrl + path, | ||||
| 			headers: { | ||||
| 				Authorization: 'Bearer ' + token, | ||||
| 				'Content-Type': 'application/json' | ||||
| 			}, | ||||
| 			json: true, | ||||
| 			form: form | ||||
| 		}; | ||||
| 		return request(req).then(function(resp) { | ||||
| 			if (2 !== Math.floor(resp.statusCode / 100)) { | ||||
| 				console.error(resp.statusCode, req.url); | ||||
| 				console.error(); | ||||
| 				console.error('Request:'); | ||||
| 				console.error(req); | ||||
| 				console.error(); | ||||
| 				console.error('Response:'); | ||||
| 				console.error(resp.body); | ||||
| 				console.error(); | ||||
| 				throw new Error( | ||||
| 					'Error response. Check token, baseUrl, domains, etc.' | ||||
| 				); | ||||
| 			} | ||||
| 			return resp; | ||||
| 		}); | ||||
| 	} | ||||
| 
 | ||||
| 	return { | ||||
| 		init: function(opts) { | ||||
| 			request = opts.request; | ||||
| 			return null; | ||||
| 		}, | ||||
| 		zones: function(data) { | ||||
| 			// console.info('List Zones', data);
 | ||||
| 
 | ||||
| 			return api('GET', '/' + account + '/zones').then(function(resp) { | ||||
| 				return resp['body']['data'].map(function(elem) { | ||||
| 					//console.log('DEBUG >>> elem.name: ' + elem.name);
 | ||||
| 					return elem.name; | ||||
| 				}); | ||||
| 			}); | ||||
| 			//console.info('List Zones', data);
 | ||||
| 			throw Error('listing zones not implemented'); | ||||
| 		}, | ||||
| 		set: function(data) { | ||||
| 			// console.info('Add TXT', data);
 | ||||
| 			var ch = data.challenge; | ||||
| 
 | ||||
| 			if (!ch.dnsZone) { | ||||
| 				throw new Error('No matching zone for ' + ch.dnsHost); | ||||
| 			} | ||||
| 			var txt = ch.dnsAuthorization; | ||||
| 
 | ||||
| 			return api( | ||||
| 				'POST', | ||||
| 				'/' + account + '/zones/' + ch.dnsZone + '/records', | ||||
| 				{ | ||||
| 					name: ch.dnsPrefix, | ||||
| 					type: 'TXT', | ||||
| 					content: txt | ||||
| 				} | ||||
| 			).then(function(resp) { | ||||
| 				if (resp.statusCode === 201) { | ||||
| 					return true; | ||||
| 				} | ||||
| 				throw new Error( | ||||
| 					'record did not set. check subdomain, api key, etc' | ||||
| 				); | ||||
| 			}); | ||||
| 		}, | ||||
| 		get: function(data) { | ||||
| 			// console.info('List TXT', data);
 | ||||
| 			var ch = data.challenge; | ||||
| 
 | ||||
| 			// TODO use :name_like
 | ||||
| 			// https://developer.dnsimple.com/v2/zones/records/
 | ||||
| 			return api( | ||||
| 				'GET', | ||||
| 				'/' + account + '/zones/' + data.challenge.dnsZone + '/records' | ||||
| 			).then(function(resp) { | ||||
| 				var record = resp.body.data.filter(function(record) { | ||||
| 					return ( | ||||
| 						ch.dnsPrefix === record.name && | ||||
| 						ch.dnsAuthorization === record.content | ||||
| 					); | ||||
| 				})[0]; | ||||
| 
 | ||||
| 				if (record) { | ||||
| 					return { dnsAuthorization: record.content }; | ||||
| 				} | ||||
| 
 | ||||
| 				return null; | ||||
| 			}); | ||||
| 			// console.info('Add TXT', data);
 | ||||
| 			throw Error('setting TXT not implemented'); | ||||
| 		}, | ||||
| 		remove: function(data) { | ||||
| 			// console.info('Remove TXT', data);
 | ||||
| 			var ch = data.challenge; | ||||
| 
 | ||||
| 			return api( | ||||
| 				'GET', | ||||
| 				'/' + account + '/zones/' + data.challenge.dnsZone + '/records' | ||||
| 			).then(function(resp) { | ||||
| 				var record = resp.body.data.filter(function(record) { | ||||
| 					return ( | ||||
| 						ch.dnsPrefix === record.name && | ||||
| 						ch.dnsAuthorization === record.content | ||||
| 					); | ||||
| 				})[0]; | ||||
| 
 | ||||
| 				if (!record) { | ||||
| 					throw new Error('Txt Record not found for removal'); | ||||
| 				} | ||||
| 				return api( | ||||
| 					'DELETE', | ||||
| 					'/' + | ||||
| 						account + | ||||
| 						'/zones/' + | ||||
| 						ch.dnsZone + | ||||
| 						'/records/' + | ||||
| 						record.id | ||||
| 				).then(function(resp) { | ||||
| 					// console.info('DEBUG >>> resp: ', JSON.stringify(resp, null, 2));
 | ||||
| 					return true; | ||||
| 				}); | ||||
| 			}); | ||||
| 			throw Error('removing TXT not implemented'); | ||||
| 		}, | ||||
| 		get: function(data) { | ||||
| 			// console.info('List TXT', data);
 | ||||
| 			throw Error('listing TXTs not implemented'); | ||||
| 		} | ||||
| 	}; | ||||
| }; | ||||
|  | ||||
| @ -1,6 +1,6 @@ | ||||
| { | ||||
| 	"name": "acme-dns-01-dnsimple", | ||||
| 	"version": "3.0.0", | ||||
| 	"version": "0.0.1", | ||||
| 	"description": "DNSimple + Let's Encrypt for Node.js - ACME dns-01 challenges w/ ACME.js and Greenlock.js", | ||||
| 	"main": "index.js", | ||||
| 	"files": [ | ||||
| @ -12,7 +12,7 @@ | ||||
| 	}, | ||||
| 	"repository": { | ||||
| 		"type": "git", | ||||
| 		"url": "https://git.rootprojects.org/root/acme-dns-01-dnsimple.js.git" | ||||
| 		"url": "https://git.coolaj86.com/coolaj86/acme-dns-01-dnsimple.js.git" | ||||
| 	}, | ||||
| 	"keywords": [ | ||||
| 		"dnsimple", | ||||
| @ -22,10 +22,7 @@ | ||||
| 		"acme", | ||||
| 		"greenlock" | ||||
| 	], | ||||
| 	"author": "Hitesh Walia <hiteshwar.walia@gmail.com", | ||||
| 	"contributors": [ | ||||
| 		"AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)" | ||||
| 	], | ||||
| 	"author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)", | ||||
| 	"license": "MPL-2.0", | ||||
| 	"devDependencies": { | ||||
| 		"acme-challenge-test": "^3.3.2", | ||||
|  | ||||
							
								
								
									
										6
									
								
								test.js
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								test.js
									
									
									
									
									
								
							| @ -5,11 +5,11 @@ | ||||
| var tester = require('acme-challenge-test'); | ||||
| require('dotenv').config(); | ||||
| 
 | ||||
| // Usage: node ./test.js example.com token account
 | ||||
| // Usage: node ./test.js example.com username xxxxxxxxx
 | ||||
| var zone = process.argv[2] || process.env.ZONE; | ||||
| var challenger = require('./index.js').create({ | ||||
| 	token: process.argv[3] || process.env.TOKEN, | ||||
| 	account: process.argv[4] || process.env.ACCOUNT | ||||
| 	username: process.argv[3] || process.env.USERNAME, | ||||
| 	password: process.argv[4] || process.env.PASSWORD | ||||
| }); | ||||
| 
 | ||||
| // The dry-run tests can pass on, literally, 'example.com'
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user