1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

New features: DU() and getConfiguredDomains() to assist modifying domains (#800)

* Added DU() and getConfiguredDomains()

* Added docs for both new functions

* Added a space between option and its value

* Renamed "DU" to "D_EXTEND", adjusted docs

* Fixed: Changed old DU() calls to D_EXTEND()
This commit is contained in:
Patrik Kernstock
2020-08-04 14:43:02 +01:00
committed by GitHub
parent f21c8fc400
commit d2d210a5af
5 changed files with 235 additions and 105 deletions

View File

@ -25,6 +25,12 @@ function initialize() {
defaultArgs = [];
}
// Returns an array of domains which were registered so far during runtime
// Own function for compatibility reasons or if some day special processing would be required.
function getConfiguredDomains() {
return conf.domain_names;
}
function NewRegistrar(name, type, meta) {
if (type) {
type == 'MANUAL';
@ -94,6 +100,32 @@ function D(name, registrar) {
conf.domain_names.push(name);
}
// DU(name): Update an already added DNS Domain with D().
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.';
}
for (var i = 0; i < defaultArgs.length; i++) {
processDargs(defaultArgs[i], domain.obj);
}
for (var i = 1; i < arguments.length; i++) {
var m = arguments[i];
processDargs(m, domain.obj);
}
conf.domains[domain.id] = domain.obj; // let's overwrite the object.
}
// _getDomainObject(name): This is a small helper function to get the domain JS object returned.
function _getDomainObject(name) {
for(var i = 0; i < conf.domains.length; i++) {
if (conf.domains[i]['name'] == name) {
return {'id': i, 'obj': conf.domains[i]};
}
}
return null;
}
// DEFAULTS provides a set of default arguments to apply to all future domains.
// Each call to DEFAULTS will clear any previous values set.
function DEFAULTS() {