From 49e3dba1f2442b67b7c4e012ac2814f75ffaad20 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Fri, 7 Oct 2016 13:14:27 -0700 Subject: [PATCH] Add DNS wildcard backend It assumes that the user setup the wildcard DNS entry manually. --- src/dns/wildcard.js | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/dns/wildcard.js diff --git a/src/dns/wildcard.js b/src/dns/wildcard.js new file mode 100644 index 000000000..5affb83de --- /dev/null +++ b/src/dns/wildcard.js @@ -0,0 +1,62 @@ +'use strict'; + +exports = module.exports = { + upsert: upsert, + get: get, + del: del, + getChangeStatus: getChangeStatus +}; + +var assert = require('assert'), + debug = require('debug')('box:dns/wildcard'), + SubdomainError = require('../subdomains.js').SubdomainError, + sysinfo = require('..sysinfo.js'), + util = require('util'); + +function upsert(dnsConfig, zoneName, subdomain, type, values, callback) { + assert.strictEqual(typeof dnsConfig, 'object'); + assert.strictEqual(typeof zoneName, 'string'); + assert.strictEqual(typeof subdomain, 'string'); + assert.strictEqual(typeof type, 'string'); + assert(util.isArray(values)); + assert.strictEqual(typeof callback, 'function'); + + debug('upsert: %s for zone %s of type %s with values %j', subdomain, zoneName, type, values); + + return callback(); +} + +function get(dnsConfig, zoneName, subdomain, type, callback) { + assert.strictEqual(typeof dnsConfig, 'object'); + assert.strictEqual(typeof zoneName, 'string'); + assert.strictEqual(typeof subdomain, 'string'); + assert.strictEqual(typeof type, 'string'); + assert.strictEqual(typeof callback, 'function'); + + if (type !== 'A') return callback(null, [ ]); + + sysinfo.getIp(function (error, ip) { + if (error) return callback(new SubdomainError(SubdomainError.INTERNAL_ERROR, error.message)); + + return callback(null, [ ip ]); + }); +} + +function del(dnsConfig, zoneName, subdomain, type, values, callback) { + assert.strictEqual(typeof dnsConfig, 'object'); + assert.strictEqual(typeof zoneName, 'string'); + assert.strictEqual(typeof subdomain, 'string'); + assert.strictEqual(typeof type, 'string'); + assert(util.isArray(values)); + assert.strictEqual(typeof callback, 'function'); + + return callback(); +} + +function getChangeStatus(dnsConfig, changeId, callback) { + assert.strictEqual(typeof dnsConfig, 'object'); + assert.strictEqual(typeof changeId, 'string'); + assert.strictEqual(typeof callback, 'function'); + + callback(null, 'INSYNC'); +}