Fixed GET and REMOVE functions
This commit is contained in:
		
							parent
							
								
									4072ae0565
								
							
						
					
					
						commit
						4dfaa01fed
					
				
							
								
								
									
										23
									
								
								lib/index.js
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								lib/index.js
									
									
									
									
									
								
							@ -39,7 +39,7 @@ module.exports.create = function(config) {
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
					throw new Error('Domain not found for: ' + identifier);
 | 
			
		||||
				})
 | 
			
		||||
				});
 | 
			
		||||
		},
 | 
			
		||||
		getTXTRecord: function(data) {
 | 
			
		||||
			// data:{dnsPrefix:"_88-acme-challenge-0e.foo",zone:"example.com",txt:"_cdZWaclIbkP1qYpMkZIURTK--ydQIK6d9axFmftWz0"}
 | 
			
		||||
@ -60,7 +60,6 @@ module.exports.create = function(config) {
 | 
			
		||||
				}
 | 
			
		||||
			}).then(function(resp) {
 | 
			
		||||
				resp = resp.body;
 | 
			
		||||
 | 
			
		||||
				var entries =
 | 
			
		||||
					resp &&
 | 
			
		||||
					resp.domain_records &&
 | 
			
		||||
@ -88,7 +87,7 @@ module.exports.create = function(config) {
 | 
			
		||||
				var txt = ch.dnsAuthorization;
 | 
			
		||||
				var url = baseUrl + '/v2/domains/' + zone + '/records';
 | 
			
		||||
 | 
			
		||||
				console.info('Adding TXT', data);
 | 
			
		||||
				// console.info('Adding TXT', data);
 | 
			
		||||
				return request({
 | 
			
		||||
					method: 'POST',
 | 
			
		||||
					url: url,
 | 
			
		||||
@ -115,18 +114,18 @@ module.exports.create = function(config) {
 | 
			
		||||
		remove: function(data) {
 | 
			
		||||
			var ch = data.challenge;
 | 
			
		||||
			var domainRecord = ch.identifier.value;
 | 
			
		||||
		
 | 
			
		||||
 | 
			
		||||
			// Digital ocean provides the api to remove records by ID. So we first get the recordId and use it to remove the domain record
 | 
			
		||||
			return helpers.getDomain(domainRecord).then(function(zone) {
 | 
			
		||||
				var dnsPrefix = ch.dnsHost.replace(new RegExp('.' + zone + '$'), '');
 | 
			
		||||
 | 
			
		||||
				console.info('Removing TXT', data);
 | 
			
		||||
				// console.info('Removing TXT', data);
 | 
			
		||||
				var payload = {
 | 
			
		||||
					dnsPrefix: dnsPrefix,
 | 
			
		||||
					zone: zone,
 | 
			
		||||
					txt: ch.dnsAuthorization
 | 
			
		||||
				};
 | 
			
		||||
				
 | 
			
		||||
 | 
			
		||||
				return helpers.getTXTRecord(payload).then(function(txtRecord) {
 | 
			
		||||
					if (txtRecord) {
 | 
			
		||||
						var url =
 | 
			
		||||
@ -141,7 +140,6 @@ module.exports.create = function(config) {
 | 
			
		||||
							}
 | 
			
		||||
						}).then(function(resp) {
 | 
			
		||||
							resp = resp.body;
 | 
			
		||||
							console.log(resp);
 | 
			
		||||
							return true;
 | 
			
		||||
						});
 | 
			
		||||
					} else {
 | 
			
		||||
@ -152,21 +150,20 @@ module.exports.create = function(config) {
 | 
			
		||||
		},
 | 
			
		||||
		get: function(data) {
 | 
			
		||||
			var ch = data.challenge;
 | 
			
		||||
			var domainRecord = data.challenge.altname;
 | 
			
		||||
			console.log('DATA:xx', data);
 | 
			
		||||
			var domainRecord = ch.identifier.value;
 | 
			
		||||
 | 
			
		||||
			return helpers.getDomain(domainRecord).then(function(zone) {
 | 
			
		||||
				var dnsPrefix = ch.dnsHost.replace(new RegExp('.' + zone + '$'), '');
 | 
			
		||||
				var dnsPrefix = domainRecord.replace(new RegExp('.' + zone + '$'), '');
 | 
			
		||||
 | 
			
		||||
				console.info('Fetching TXT', data);
 | 
			
		||||
				// console.info('Fetching TXT', data);
 | 
			
		||||
				var payload = {
 | 
			
		||||
					dnsPrefix: dnsPrefix,
 | 
			
		||||
					zone: zone,
 | 
			
		||||
					txt: data.dnsAuthorization
 | 
			
		||||
					txt: ch.dnsAuthorization
 | 
			
		||||
				};
 | 
			
		||||
				return helpers.getTXTRecord(payload).then(function(txtRecord) {
 | 
			
		||||
					if (txtRecord) {
 | 
			
		||||
						return { dnsAuthorization: entry.data };
 | 
			
		||||
						return { dnsAuthorization: txtRecord.data };
 | 
			
		||||
					} else {
 | 
			
		||||
						return null;
 | 
			
		||||
					}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user