Make the verifyDnsConfig() api return the valid credentials

This commit is contained in:
Johannes Zellner
2017-01-10 11:32:44 +01:00
parent badbb89c92
commit babfb5efbb
7 changed files with 46 additions and 16 deletions
+11 -3
View File
@@ -218,11 +218,19 @@ function verifyDnsConfig(dnsConfig, domain, ip, callback) {
assert.strictEqual(typeof ip, 'string');
assert.strictEqual(typeof callback, 'function');
var credentials = {
provider: dnsConfig.provider,
accessKeyId: dnsConfig.accessKeyId,
secretAccessKey: dnsConfig.secretAccessKey,
region: dnsConfig.region || 'us-east-1',
endpoint: dnsConfig.endpoint || null
};
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(error || new Error('Unable to get nameservers'));
getHostedZone(dnsConfig, domain, function (error, zone) {
getHostedZone(credentials, domain, function (error, zone) {
if (error) return callback(error);
if (!_.isEqual(zone.DelegationSet.NameServers.sort(), nameservers.sort())) {
@@ -230,12 +238,12 @@ function verifyDnsConfig(dnsConfig, domain, ip, callback) {
return callback(new SubdomainError(SubdomainError.BAD_FIELD, 'Domain nameservers are not set to Route53'));
}
upsert(dnsConfig, domain, 'my', 'A', [ ip ], function (error, changeId) {
upsert(credentials, domain, 'my', 'A', [ ip ], function (error, changeId) {
if (error) return callback(new SubdomainError(SubdomainError.INTERNAL_ERROR, error));
debug('verifyDnsConfig: A record added with change id %s', changeId);
callback();
callback(null, credentials);
});
});
});