Merge pull request #671 from rhansen/vars

Clean up service variable definitions
This commit is contained in:
Richard Hansen 2024-05-19 02:45:17 -04:00 committed by GitHub
commit 545d5e10d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -655,21 +655,6 @@ my %variables = (
'static' => setv(T_BOOL, 0, 1, 0, undef), 'static' => setv(T_BOOL, 0, 1, 0, undef),
'wildcard' => setv(T_BOOL, 0, 1, 0, undef), 'wildcard' => setv(T_BOOL, 0, 1, 0, undef),
}, },
'keysystems-common-defaults' => {
'server' => setv(T_FQDNP, 1, 0, 'dynamicdns.key-systems.net', undef),
'login' => setv(T_LOGIN, 0, 0, 0, 'unused', undef),
},
'dnsexit2-common-defaults' => {
'ssl' => setv(T_BOOL, 0, 0, 1, undef),
'server' => setv(T_FQDNP, 1, 0, 'api.dnsexit.com', undef),
'path' => setv(T_STRING, 0, 0, '/dns/', undef),
'ttl' => setv(T_NUMBER, 1, 0, 5, 0),
'zone' => setv(T_STRING, 0, 0, undef, undef)
},
'regfishde-common-defaults' => {
'server' => setv(T_FQDNP, 1, 0, 'dyndns.regfish.de', undef),
'login' => setv(T_LOGIN, 0, 0, 0, 'unused', undef),
},
); );
my %services = ( my %services = (
'1984' => { '1984' => {
@ -678,7 +663,7 @@ my %services = (
'examples' => \&nic_1984_examples, 'examples' => \&nic_1984_examples,
'variables' => { 'variables' => {
%{$variables{'service-common-defaults'}}, %{$variables{'service-common-defaults'}},
'login' => setv(T_LOGIN, 0, 0, 'unused', undef), 'login' => undef,
'server' => setv(T_FQDNP, 1, 0, 'api.1984.is', undef), 'server' => setv(T_FQDNP, 1, 0, 'api.1984.is', undef),
}, },
}, },
@ -715,12 +700,9 @@ my %services = (
'examples' => \&nic_cloudns_examples, 'examples' => \&nic_cloudns_examples,
'variables' => { 'variables' => {
%{$variables{'service-common-defaults'}}, %{$variables{'service-common-defaults'}},
'login' => undef,
'password' => undef,
'dynurl' => setv(T_STRING, 1, 0, undef, undef), 'dynurl' => setv(T_STRING, 1, 0, undef, undef),
# nic_updateable() assumes that every service uses a username and password but that is
# not true for CloudNS. Silence warnings by redefining the username and password
# variables as non-required with a non-empty default.
'login' => setv(T_STRING, 0, 0, 'unused', undef),
'password' => setv(T_STRING, 0, 0, 'unused', undef),
}, },
}, },
'digitalocean' => { 'digitalocean' => {
@ -729,9 +711,9 @@ my %services = (
'examples' => \&nic_digitalocean_examples, 'examples' => \&nic_digitalocean_examples,
'variables' => { 'variables' => {
%{$variables{'service-common-defaults'}}, %{$variables{'service-common-defaults'}},
'login' => undef,
'server' => setv(T_FQDNP, 1, 0, 'api.digitalocean.com', undef), 'server' => setv(T_FQDNP, 1, 0, 'api.digitalocean.com', undef),
'zone' => setv(T_FQDN, 1, 0, '', undef), 'zone' => setv(T_FQDN, 1, 0, '', undef),
'login' => setv(T_LOGIN, 0, 0, 'unused', undef),
}, },
}, },
'dinahosting' => { 'dinahosting' => {
@ -771,7 +753,6 @@ my %services = (
'variables' => { 'variables' => {
%{$variables{'service-common-defaults'}}, %{$variables{'service-common-defaults'}},
'server' => setv(T_FQDNP, 1, 0, 'www.dslreports.com', undef), 'server' => setv(T_FQDNP, 1, 0, 'www.dslreports.com', undef),
'host' => setv(T_NUMBER, 1, 1, 0, undef),
}, },
}, },
'domeneshop' => { 'domeneshop' => {
@ -789,7 +770,7 @@ my %services = (
'examples' => \&nic_duckdns_examples, 'examples' => \&nic_duckdns_examples,
'variables' => { 'variables' => {
%{$variables{'service-common-defaults'}}, %{$variables{'service-common-defaults'}},
'login' => setv(T_LOGIN, 0, 0, 'unused', undef), 'login' => undef,
'server' => setv(T_FQDNP, 1, 0, 'www.duckdns.org', undef), 'server' => setv(T_FQDNP, 1, 0, 'www.duckdns.org', undef),
}, },
}, },
@ -843,7 +824,7 @@ my %services = (
'examples' => \&nic_freemyip_examples, 'examples' => \&nic_freemyip_examples,
'variables' => { 'variables' => {
%{$variables{'service-common-defaults'}}, %{$variables{'service-common-defaults'}},
'login' => setv(T_LOGIN, 0, 0, 'unused', undef), 'login' => undef,
'server' => setv(T_FQDNP, 1, 0, 'freemyip.com', undef), 'server' => setv(T_FQDNP, 1, 0, 'freemyip.com', undef),
}, },
}, },
@ -853,14 +834,13 @@ my %services = (
'examples' => \&nic_gandi_examples, 'examples' => \&nic_gandi_examples,
'variables' => { 'variables' => {
%{$variables{'service-common-defaults'}}, %{$variables{'service-common-defaults'}},
'login' => undef,
'min-interval' => setv(T_DELAY, 0, 0, 0, interval('5m')), 'min-interval' => setv(T_DELAY, 0, 0, 0, interval('5m')),
'server' => setv(T_FQDNP, 1, 0, 'api.gandi.net', undef), 'server' => setv(T_FQDNP, 1, 0, 'api.gandi.net', undef),
'script' => setv(T_STRING, 1, 1, '/v5', undef), 'script' => setv(T_STRING, 1, 1, '/v5', undef),
'use-personal-access-token' => setv(T_BOOL, 0, 0, 0, undef), 'use-personal-access-token' => setv(T_BOOL, 0, 0, 0, undef),
'ttl' => setv(T_DELAY, 0, 0, undef, interval('5m')), 'ttl' => setv(T_DELAY, 0, 0, undef, interval('5m')),
'zone' => setv(T_FQDN, 1, 0, undef, undef), 'zone' => setv(T_FQDN, 1, 0, undef, undef),
# Unused variables.
'login' => setv(T_STRING, 0, 0, 'unused', undef),
} }
}, },
'godaddy' => { 'godaddy' => {
@ -936,9 +916,9 @@ my %services = (
'examples' => \&nic_njalla_examples, 'examples' => \&nic_njalla_examples,
'variables' => { 'variables' => {
%{$variables{'service-common-defaults'}}, %{$variables{'service-common-defaults'}},
'login' => setv(T_STRING, 0, 0, 'unused', undef), 'login' => undef,
'server' => setv(T_FQDNP, 1, 0, 'njal.la', undef), 'server' => setv(T_FQDNP, 1, 0, 'njal.la', undef),
'quietreply' => setv(T_BOOL, 0, 1, 0, undef) 'quietreply' => setv(T_BOOL, 0, 1, 0, undef),
}, },
}, },
'noip' => { 'noip' => {
@ -947,22 +927,9 @@ my %services = (
'examples' => \&nic_noip_examples, 'examples' => \&nic_noip_examples,
'variables' => { 'variables' => {
%{$variables{'service-common-defaults'}}, %{$variables{'service-common-defaults'}},
'atime' => setv(T_NUMBER, 0, 1, 0, undef),
'custom' => setv(T_BOOL, 0, 1, 0, undef), 'custom' => setv(T_BOOL, 0, 1, 0, undef),
'host' => setv(T_STRING, 1, 1, '', undef),
'ip' => setv(T_IP, 0, 1, undef, undef),
'login' => setv(T_LOGIN, 1, 0, '', undef),
'max-interval' => setv(T_DELAY, 0, 0, interval('25d'), 0),
'min-error-interval' => setv(T_DELAY, 0, 0, interval('5m'), 0),
'min-interval' => setv(T_DELAY, 0, 0, interval('30s'), 0),
'mtime' => setv(T_NUMBER, 0, 1, 0, undef),
'password' => setv(T_PASSWD, 1, 0, '', undef),
'server' => setv(T_FQDNP, 1, 0, 'dynupdate.no-ip.com', undef), 'server' => setv(T_FQDNP, 1, 0, 'dynupdate.no-ip.com', undef),
'static' => setv(T_BOOL, 0, 1, 0, undef), 'static' => setv(T_BOOL, 0, 1, 0, undef),
'status' => setv(T_ANY, 0, 1, '', undef),
'warned-min-error-interval' => setv(T_ANY, 0, 1, 0, undef),
'warned-min-interval' => setv(T_ANY, 0, 1, 0, undef),
'wtime' => setv(T_DELAY, 0, 1, 0, interval('30s')),
}, },
}, },
'nsupdate' => { 'nsupdate' => {
@ -983,8 +950,6 @@ my %services = (
'examples' => \&nic_ovh_examples, 'examples' => \&nic_ovh_examples,
'variables' => { 'variables' => {
%{$variables{'service-common-defaults'}}, %{$variables{'service-common-defaults'}},
'login' => setv(T_LOGIN, 1, 0, '', undef),
'password' => setv(T_PASSWD, 1, 0, '', undef),
'script' => setv(T_STRING, 1, 1, '/nic/update', undef), 'script' => setv(T_STRING, 1, 1, '/nic/update', undef),
'server' => setv(T_FQDNP, 1, 0, 'www.ovh.com', undef), 'server' => setv(T_FQDNP, 1, 0, 'www.ovh.com', undef),
}, },
@ -994,15 +959,13 @@ my %services = (
'update' => \&nic_porkbun_update, 'update' => \&nic_porkbun_update,
'examples' => \&nic_porkbun_examples, 'examples' => \&nic_porkbun_examples,
'variables' => { 'variables' => {
%{$variables{'service-common-defaults'}},
'login' => undef,
'password' => undef,
'apikey' => setv(T_PASSWD, 1, 0, '', undef), 'apikey' => setv(T_PASSWD, 1, 0, '', undef),
'secretapikey' => setv(T_PASSWD, 1, 0, '', undef), 'secretapikey' => setv(T_PASSWD, 1, 0, '', undef),
'root-domain' => setv(T_OFQDN, 0, 0, '', undef), 'root-domain' => setv(T_OFQDN, 0, 0, '', undef),
'on-root-domain' => setv(T_BOOL, 0, 0, 0, undef), 'on-root-domain' => setv(T_BOOL, 0, 0, 0, undef),
'login' => setv(T_LOGIN, 0, 0, 'unused', undef),
'password' => setv(T_PASSWD, 0, 0, 'unused', undef),
'use' => setv(T_USE, 0, 0, 'disabled', undef),
'usev4' => setv(T_USEV4, 0, 0, 'disabled', undef),
'usev6' => setv(T_USEV6, 0, 0, 'disabled', undef),
}, },
}, },
'sitelutions' => { 'sitelutions' => {
@ -1020,25 +983,14 @@ my %services = (
'update' => \&nic_woima_update, 'update' => \&nic_woima_update,
'examples' => \&nic_woima_examples, 'examples' => \&nic_woima_examples,
'variables' => { 'variables' => {
'atime' => setv(T_NUMBER, 0, 1, 0, undef), %{$variables{'service-common-defaults'}},
'backupmx' => setv(T_BOOL, 0, 1, 0, undef), 'backupmx' => setv(T_BOOL, 0, 1, 0, undef),
'custom' => setv(T_BOOL, 0, 1, 0, undef), 'custom' => setv(T_BOOL, 0, 1, 0, undef),
'ip' => setv(T_IP, 0, 1, undef, undef),
'login' => setv(T_LOGIN, 1, 0, '', undef),
'max-interval' => setv(T_DELAY, 0, 0, interval('25d'), 0),
'min-error-interval' => setv(T_DELAY, 0, 0, interval('5m'), 0),
'min-interval' => setv(T_DELAY, 0, 0, interval('30s'), 0),
'mtime' => setv(T_NUMBER, 0, 1, 0, undef),
'mx' => setv(T_OFQDN, 0, 1, '', undef), 'mx' => setv(T_OFQDN, 0, 1, '', undef),
'password' => setv(T_PASSWD, 1, 0, '', undef),
'script' => setv(T_STRING, 1, 1, '/nic/update', undef), 'script' => setv(T_STRING, 1, 1, '/nic/update', undef),
'server' => setv(T_FQDNP, 1, 0, 'dyn.woima.fi', undef), 'server' => setv(T_FQDNP, 1, 0, 'dyn.woima.fi', undef),
'static' => setv(T_BOOL, 0, 1, 0, undef), 'static' => setv(T_BOOL, 0, 1, 0, undef),
'status' => setv(T_ANY, 0, 1, '', undef),
'warned-min-error-interval' => setv(T_ANY, 0, 1, 0, undef),
'warned-min-interval' => setv(T_ANY, 0, 1, 0, undef),
'wildcard' => setv(T_BOOL, 0, 1, 0, undef), 'wildcard' => setv(T_BOOL, 0, 1, 0, undef),
'wtime' => setv(T_DELAY, 0, 1, 0, interval('30s')),
}, },
}, },
'yandex' => { 'yandex' => {
@ -1066,10 +1018,11 @@ my %services = (
'updateable' => undef, 'updateable' => undef,
'update' => \&nic_keysystems_update, 'update' => \&nic_keysystems_update,
'examples' => \&nic_keysystems_examples, 'examples' => \&nic_keysystems_examples,
'variables' => merge( 'variables' => {
$variables{'keysystems-common-defaults'}, %{$variables{'service-common-defaults'}},
$variables{'service-common-defaults'}, 'login' => undef,
), 'server' => setv(T_FQDNP, 1, 0, 'dynamicdns.key-systems.net', undef),
},
}, },
'dnsexit2' => { 'dnsexit2' => {
'updateable' => undef, 'updateable' => undef,
@ -1077,21 +1030,23 @@ my %services = (
'examples' => \&nic_dnsexit2_examples, 'examples' => \&nic_dnsexit2_examples,
'variables' => { 'variables' => {
%{$variables{'service-common-defaults'}}, %{$variables{'service-common-defaults'}},
%{$variables{'dnsexit2-common-defaults'}}, 'login' => undef,
# nic_updateable() assumes that every service uses a username/login but that is 'ssl' => setv(T_BOOL, 0, 0, 1, undef),
# not true for the DNSExit API. Silence warnings by redefining the username variable 'server' => setv(T_FQDNP, 1, 0, 'api.dnsexit.com', undef),
# as non-required with value unused. 'path' => setv(T_STRING, 0, 0, '/dns/', undef),
'login' => setv(T_STRING, 0, 0, 'unused', undef), 'ttl' => setv(T_NUMBER, 1, 0, 5, 0),
'zone' => setv(T_STRING, 0, 0, undef, undef),
}, },
}, },
'regfishde' => { 'regfishde' => {
'updateable' => undef, 'updateable' => undef,
'update' => \&nic_regfishde_update, 'update' => \&nic_regfishde_update,
'examples' => \&nic_regfishde_examples, 'examples' => \&nic_regfishde_examples,
'variables' => merge( 'variables' => {
$variables{'regfishde-common-defaults'}, %{$variables{'service-common-defaults'}},
$variables{'service-common-defaults'}, 'login' => undef,
), 'server' => setv(T_FQDNP, 1, 0, 'dyndns.regfish.de', undef),
},
}, },
'enom' => { 'enom' => {
'updateable' => undef, 'updateable' => undef,
@ -1112,6 +1067,11 @@ my %services = (
}, },
}, },
); );
# Delete undefined variables to make it easier to cancel previously defined variables.
for my $svc (values(%services)) {
my $vars = $svc->{variables};
delete(@$vars{grep(!defined($vars->{$_}), keys(%$vars))});
}
$variables{'merged'} = { $variables{'merged'} = {
map({ %{$services{$_}{'variables'}} } keys(%services)), map({ %{$services{$_}{'variables'}} } keys(%services)),
%{$variables{'dyndns-common-defaults'}}, %{$variables{'dyndns-common-defaults'}},
@ -1832,7 +1792,7 @@ sub _read_config {
my ($host, $login, $password) = @args; my ($host, $login, $password) = @args;
## add in any globals.. ## add in any globals..
%locals = %{merge(\%locals, \%globals)}; %locals = (%globals, %locals);
## override login and password if specified the old way. ## override login and password if specified the old way.
$locals{'login'} = $login if defined $login; $locals{'login'} = $login if defined $login;
@ -1842,7 +1802,7 @@ sub _read_config {
foreach my $h (split_by_comma($host)) { foreach my $h (split_by_comma($host)) {
if ($config{$h}) { if ($config{$h}) {
## host already defined, merging configs ## host already defined, merging configs
$config{$h} = { %{merge($config{$h}, \%locals)} }; $config{$h} = {%locals, %{$config{$h}}};
} else { } else {
## save a copy of the current globals ## save a copy of the current globals
$config{$h} = { %locals }; $config{$h} = { %locals };
@ -1932,11 +1892,11 @@ sub init_config {
## merge options into host definitions or globals ## merge options into host definitions or globals
if (@hosts) { if (@hosts) {
foreach my $h (@hosts) { foreach my $h (@hosts) {
$config{$h} = merge(\%options, $config{$h}); $config{$h} = {%{$config{$h}}, %options};
} }
$opt{'host'} = join(',', @hosts); $opt{'host'} = join(',', @hosts);
} else { } else {
%globals = %{merge(\%options, \%globals)}; %globals = (%globals, %options);
} }
} }
@ -2369,7 +2329,6 @@ sub sendmail {
} }
###################################################################### ######################################################################
## split_by_comma ## split_by_comma
## merge
## default ## default
## minimum ## minimum
## opt ## opt
@ -2380,15 +2339,6 @@ sub split_by_comma {
return split /\s*[, ]\s*/, $string if defined $string; return split /\s*[, ]\s*/, $string if defined $string;
return (); return ();
} }
sub merge {
my %merged = ();
foreach my $h (@_) {
foreach my $k (keys %$h) {
$merged{$k} = $h->{$k} unless exists $merged{$k};
}
}
return \%merged;
}
sub default { sub default {
my $v = shift; my $v = shift;
return $variables{'merged'}{$v}{'default'}; return $variables{'merged'}{$v}{'default'};