Keep coding style consistent
This commit is contained in:
@@ -1,16 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
// -------------------------------------------
|
||||
// This file just describes the interface
|
||||
//
|
||||
// New backends can start from here
|
||||
// -------------------------------------------
|
||||
|
||||
exports = module.exports = {
|
||||
upsert: upsert,
|
||||
get: get,
|
||||
del: del,
|
||||
// waitForDns: require('./waitfordns.js'),
|
||||
waitForDns: require('./waitfordns.js'),
|
||||
verifyDnsConfig: verifyDnsConfig
|
||||
};
|
||||
|
||||
@@ -24,7 +18,7 @@ var assert = require('assert'),
|
||||
|
||||
util = require('util');
|
||||
|
||||
// we are using lated v4 stable API https://api.cloudflare.com/#getting-started-endpoints
|
||||
// we are using latest v4 stable API https://api.cloudflare.com/#getting-started-endpoints
|
||||
var CLOUDFLARE_ENDPOINT = "https://api.cloudflare.com/client/v4";
|
||||
|
||||
// Get the zone details by zoneName
|
||||
@@ -33,9 +27,10 @@ function getZoneByName(dnsConfig, zoneName, callback) {
|
||||
assert.strictEqual(typeof dnsConfig, 'object');
|
||||
assert.strictEqual(typeof zoneName, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
superagent.get(CLOUDFLARE_ENDPOINT + '/zones?name=' + zoneName + '&status=active')
|
||||
.set('X-Auth-Key',dnsConfig.token)
|
||||
.set('X-Auth-Email',dnsConfig.email)
|
||||
.set('X-Auth-Key', dnsConfig.token)
|
||||
.set('X-Auth-Email', dnsConfig.email)
|
||||
.timeout(30 * 1000)
|
||||
.end(function (error, result) {
|
||||
if (error && !error.response) return callback(error);
|
||||
@@ -43,12 +38,9 @@ function getZoneByName(dnsConfig, zoneName, callback) {
|
||||
if (result.statusCode === 403 || result.statusCode === 401) return callback(new SubdomainError(SubdomainError.ACCESS_DENIED, util.format('%s %j', result.statusCode, result.body)));
|
||||
if (result.statusCode !== 200) return callback(new SubdomainError(SubdomainError.EXTERNAL_ERROR, util.format('%s %j', result.statusCode, result.body)));
|
||||
if (result.body.success !== true) return callback(new SubdomainError(SubdomainError.EXTERNAL_ERROR, util.format('%s %j', result.statusCode, result.body)));
|
||||
if (!result.body.result.length) return callback(new SubdomainError(SubdomainError.NOT_FOUND, util.format('%s %j', result.statusCode, result.body)));
|
||||
|
||||
if(result.body.result.length) {
|
||||
return callback(null, result.body.result[0]);
|
||||
}
|
||||
|
||||
return callback(new SubdomainError(SubdomainError.NOT_FOUND, util.format('%s %j', result.statusCode, result.body)));
|
||||
callback(null, result.body.result[0]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -58,6 +50,7 @@ function getDNSRecordsByZoneName(dnsConfig, zoneName, subdomain, type, callback)
|
||||
assert.strictEqual(typeof subdomain, 'string');
|
||||
assert.strictEqual(typeof type, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
var fqdn = subdomain === '' ? zoneName : subdomain + '.' + zoneName;
|
||||
|
||||
getZoneByName(dnsConfig, zoneName, function(error, result){
|
||||
@@ -74,9 +67,7 @@ function getDNSRecordsByZoneName(dnsConfig, zoneName, subdomain, type, callback)
|
||||
if (result.statusCode === 403 || result.statusCode === 401) return callback(new SubdomainError(SubdomainError.ACCESS_DENIED, util.format('%s %j', result.statusCode, result.body)));
|
||||
if (result.statusCode !== 200) return callback(new SubdomainError(SubdomainError.EXTERNAL_ERROR, util.format('%s %j', result.statusCode, result.body)));
|
||||
if (result.body.success !== true) return callback(new SubdomainError(SubdomainError.EXTERNAL_ERROR, util.format('%s %j', result.statusCode, result.body)));
|
||||
if (result.body.result.length <= 0) {
|
||||
return callback(new SubdomainError(SubdomainError.EXTERNAL_ERROR, util.format('%s %s', result.statusCode, 'No Dns record found')));
|
||||
}
|
||||
if (result.body.result.length <= 0) return callback(new SubdomainError(SubdomainError.EXTERNAL_ERROR, util.format('%s %s', result.statusCode, 'No Dns record found')));
|
||||
|
||||
var tmp = result.body.result.filter(function (record) {
|
||||
return (record.type === type && record.name === fqdn);
|
||||
@@ -98,7 +89,6 @@ function upsert(dnsConfig, zoneName, subdomain, type, values, callback) {
|
||||
|
||||
var fqdn = subdomain === '' ? zoneName : subdomain + '.' + zoneName;
|
||||
|
||||
|
||||
debug('upsert: %s for zone %s of type %s with values %j', subdomain, zoneName, type, values);
|
||||
|
||||
// Result: backend specific change id, to be passed into getChangeStatus()
|
||||
@@ -130,7 +120,7 @@ function upsert(dnsConfig, zoneName, subdomain, type, values, callback) {
|
||||
if (result.statusCode !== 201) return callback(new SubdomainError(SubdomainError.EXTERNAL_ERROR, util.format('%s %j', result.statusCode, result.body)));
|
||||
if (result.body.success !== true) return callback(new SubdomainError(SubdomainError.EXTERNAL_ERROR, util.format('%s %j', result.statusCode, result.body)));
|
||||
|
||||
return callback(null);
|
||||
callback(null);
|
||||
});
|
||||
} else {
|
||||
superagent.put(CLOUDFLARE_ENDPOINT + '/zones/'+ zoneId + '/dns_records/' + dnsRecords[i].id)
|
||||
@@ -148,7 +138,7 @@ function upsert(dnsConfig, zoneName, subdomain, type, values, callback) {
|
||||
if (result.statusCode !== 200) return callback(new SubdomainError(SubdomainError.EXTERNAL_ERROR, util.format('%s %j', result.statusCode, result.body)));
|
||||
if (result.body.success !== true) return callback(new SubdomainError(SubdomainError.EXTERNAL_ERROR, util.format('%s %j', result.statusCode, result.body)));
|
||||
|
||||
return callback(null);
|
||||
callback(null);
|
||||
});
|
||||
}
|
||||
}, function (error) {
|
||||
@@ -174,7 +164,7 @@ function get(dnsConfig, zoneName, subdomain, type, callback) {
|
||||
var tmp = result.map(function (record) { return record.content; });
|
||||
debug('get: %j', tmp);
|
||||
|
||||
return callback(null, tmp);
|
||||
callback(null, tmp);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -210,16 +200,13 @@ function del(dnsConfig, zoneName, subdomain, type, values, callback) {
|
||||
|
||||
debug('del: done');
|
||||
|
||||
return callback(null);
|
||||
callback(null);
|
||||
});
|
||||
|
||||
},
|
||||
function (error) {
|
||||
}, function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
callback(null, 'unused');
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -245,13 +232,14 @@ function verifyDnsConfig(dnsConfig, domain, ip, callback) {
|
||||
dns.resolveNs(domain, function (error, nameservers) {
|
||||
if (error && error.code === 'ENOTFOUND') return callback(new SubdomainError(SubdomainError.BAD_FIELD, 'Unable to resolve nameservers for this domain'));
|
||||
if (error || !nameservers) return callback(new SubdomainError(SubdomainError.BAD_FIELD, error ? error.message : 'Unable to get nameservers'));
|
||||
getZoneByName(dnsConfig, domain, function(error, result) {
|
||||
|
||||
getZoneByName(dnsConfig, domain, function(error, result) {
|
||||
if (error) return callback(error);
|
||||
if (!_.isEqual(result.name_servers.sort(), nameservers.sort())) {
|
||||
debug('verifyDnsConfig: %j and %j do not match', nameservers, result.name_servers);
|
||||
return callback(new SubdomainError(SubdomainError.BAD_FIELD, 'Domain nameservers are not set to Route53'));
|
||||
}
|
||||
|
||||
upsert(credentials, domain, 'my', 'A', [ ip ], function (error, changeId) {
|
||||
if (error) return callback(error);
|
||||
|
||||
@@ -259,7 +247,6 @@ function verifyDnsConfig(dnsConfig, domain, ip, callback) {
|
||||
|
||||
callback(null, credentials);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user