Support multi-level subdomains within a hosted zone.

This commit is contained in:
Ryan Kelly 2014-02-12 13:35:17 +11:00
Родитель d6917b3278
Коммит 5d08b3e3f6
1 изменённых файлов: 22 добавлений и 11 удалений

Просмотреть файл

@ -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 = {
@ -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
@ -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);
});
}