Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #119 from mozilla/rfk/multi-level-subdomains
Browse files Browse the repository at this point in the history
Support multi-level subdomains within a hosted zone.
  • Loading branch information
chilts committed Mar 17, 2014
2 parents 436dbd6 + 5d08b3e commit 8831969
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions lib/dns.js
Expand Up @@ -11,12 +11,7 @@ exports.updateRecord = function (hostname, ip, cb) {
cb('No hostname/ip address provided');
});
}

// split hostname into two (e.g. blah.example.org -> blah and example.org)
var domain = hostname.split('.').slice(1).join('.');

// firstly, get the zoneInfo
aws.niceRoute53.zoneInfo(domain, function(err, zoneInfo) {
findZoneInfo(hostname, function(err, zoneInfo) {
if (err) return cb(err);

var args = {
Expand Down Expand Up @@ -78,11 +73,7 @@ exports.findByIP = function (ip, cb) {

exports.deleteRecord = function (hostname, cb) {
if (!hostname) throw new Error('No hostname provided');

// split hostname into two (e.g. blah.example.org -> blah and example.org)
var domain = hostname.split('.').slice(1).join('.');

aws.niceRoute53.zoneInfo(domain, function(err, zoneInfo) {
findZoneInfo(hostname, function(err, zoneInfo) {
if (err) return cb(err);

// Note: we're always deleting A records here
Expand Down Expand Up @@ -137,3 +128,23 @@ exports.inUse = function(hostname, cb) {
);
});
};


function findZoneInfo(hostname, cb) {
// Find zone info for the given hostname.
// This recusrively searches all suffixes of the hostname
// until it finds one with a hosted zone.
if (!hostname) {
return cb('could not find hosted zone');
}
var domain = hostname.split('.').slice(1).join('.');
aws.niceRoute53.zoneInfo(domain, function(err, zoneInfo) {
if (!err) {
return cb(null, zoneInfo);
}
if (err.code && err.code === 'DomainNotFound') {
return findZoneInfo(domain, cb);
}
return cb(err);
});
}

0 comments on commit 8831969

Please sign in to comment.