mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
Add D_EXTEND (#885) (thanks to @ad8-bdl!)
* fix get-zones code block indentation * extend D_EXTEND to handle subdomains * fix targets: make absolute incl. subdomain where necessary * clarify subdomain target test (not IP && not fqdn) * Add parse_tests for D and D_EXTEND * _getDomainObject: examine all domains * human readable form * consistent test IP addresses * Improve docs and formatting * propagate subdomain to canonicalisation * en-US spelling * rm extraneous console.log * ignore subdomain for CF_REDIRECT * clarify D_EXTEND doc re. CF_REDIRECT * rm extraneous linebreak * _getDomainObject: examine all domains * human readable form * consistent test IP addresses * propagate subdomain to canonicalisation * en-US spelling * rm extraneous console.log * ignore subdomain for CF_REDIRECT * clarify D_EXTEND doc re. CF_REDIRECT * rm extraneous linebreak * GANDI_V5: Use github.com/go-gandi/go-gandi, not github.com/tiramiseb/go-gandi (#883) * DOCUMENTATION: Fix error in CNAME.md (#877) The current example `CNAME("def", "test.subdomain"), // def.example.com -> test.subdomain.example.com` is invalid (correctly raises a validation error, "ERROR: in CNAME def.example.com: target (test.subdomain) must end with a (.)") * typos, fmt; example syntax fixes and real output * formatting; re-add lost comment * RecordConfig subdomain should be nullable * providers/cscglobal/api.go: Fix fmt string * More tests and docs * go generate Co-authored-by: Ben L <47653825+ad8-bdl@users.noreply.github.com>
This commit is contained in:
@ -53,6 +53,7 @@ function NewDnsProvider(name, type, meta) {
|
||||
function newDomain(name, registrar) {
|
||||
return {
|
||||
name: name,
|
||||
subdomain: '',
|
||||
registrar: registrar,
|
||||
meta: {},
|
||||
records: [],
|
||||
@ -102,12 +103,13 @@ function D(name, registrar) {
|
||||
conf.domain_names.push(name);
|
||||
}
|
||||
|
||||
// DU(name): Update an already added DNS Domain with D().
|
||||
// D_EXTEND(name): Update a DNS Domain already added with D(), or subdomain thereof
|
||||
function D_EXTEND(name) {
|
||||
var domain = _getDomainObject(name);
|
||||
if (domain == null) {
|
||||
throw name + ' was not declared yet and therefore cannot be updated. Use D() before.';
|
||||
}
|
||||
domain.obj.subdomain = name.substr(0, name.length-domain.obj.name.length - 1);
|
||||
for (var i = 0; i < defaultArgs.length; i++) {
|
||||
processDargs(defaultArgs[i], domain.obj);
|
||||
}
|
||||
@ -119,13 +121,19 @@ function D_EXTEND(name) {
|
||||
}
|
||||
|
||||
// _getDomainObject(name): This is a small helper function to get the domain JS object returned.
|
||||
// returns the domain object defined for the given name or subdomain thereof
|
||||
function _getDomainObject(name) {
|
||||
domain = null;
|
||||
domain_len = 0;
|
||||
for(var i = 0; i < conf.domains.length; i++) {
|
||||
if (conf.domains[i]['name'] == name) {
|
||||
return {'id': i, 'obj': conf.domains[i]};
|
||||
if (name.substr(-conf.domains[i]['name'].length) == conf.domains[i]['name']) {
|
||||
if (conf.domains[i]['name'].length > domain_len) {
|
||||
domain_len = conf.domains[i]['name'].length;
|
||||
domain = {'id': i, 'obj': conf.domains[i]};
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return domain;
|
||||
}
|
||||
|
||||
// DEFAULTS provides a set of default arguments to apply to all future domains.
|
||||
@ -660,6 +668,17 @@ function recordBuilder(type, opts) {
|
||||
opts.applyModifier(record, modifiers);
|
||||
opts.transform(record, parsedArgs, modifiers);
|
||||
|
||||
// Handle D_EXTEND() with subdomains.
|
||||
if (d.subdomain && record.type != 'CF_REDIRECT' &&
|
||||
record.type != 'CF_TEMP_REDIRECT') {
|
||||
record.subdomain = d.subdomain;
|
||||
if (record.name == '@') {
|
||||
record.name = d.subdomain;
|
||||
} else {
|
||||
record.name += '.' + d.subdomain;
|
||||
}
|
||||
}
|
||||
|
||||
d.records.push(record);
|
||||
return record;
|
||||
};
|
||||
|
Reference in New Issue
Block a user