Move *_env
processing to parse_assignment
This makes the behavior transparent to the rest of ddclient, which will make it possible for a future commit to simplify option processing.
This commit is contained in:
parent
19848852a4
commit
4c7634855b
2 changed files with 17 additions and 15 deletions
24
ddclient.in
24
ddclient.in
|
@ -1652,6 +1652,15 @@ sub parse_assignment {
|
||||||
}
|
}
|
||||||
$rest = substr($rest,1);
|
$rest = substr($rest,1);
|
||||||
}
|
}
|
||||||
|
if ($name =~ qr/^(.*)_env$/) {
|
||||||
|
$name = $1;
|
||||||
|
debug("Loading value for $name from environment variable $value");
|
||||||
|
if (!exists($ENV{$value})) {
|
||||||
|
warning("Environment variable '$value' not set for keyword '$name' (ignored)");
|
||||||
|
return parse_assignment($rest);
|
||||||
|
}
|
||||||
|
$value = $ENV{$value};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
warning("assignment to '%s' ended with the escape character (\\)", $name) if $escape;
|
warning("assignment to '%s' ended with the escape character (\\)", $name) if $escape;
|
||||||
warning("assignment to '%s' ended with an unterminated quote (%s)", $name, $quote) if $quote;
|
warning("assignment to '%s' ended with an unterminated quote (%s)", $name, $quote) if $quote;
|
||||||
|
@ -1786,21 +1795,6 @@ sub _read_config {
|
||||||
|
|
||||||
## verify that keywords are valid...and check the value
|
## verify that keywords are valid...and check the value
|
||||||
for my $k (keys %locals) {
|
for my $k (keys %locals) {
|
||||||
# Handle '_env' keyword suffix
|
|
||||||
if ($k =~ /(.*)_env$/) {
|
|
||||||
debug("Loading value for $1 from environment variable $locals{$k}.");
|
|
||||||
if (!exists($ENV{$locals{$k}})) {
|
|
||||||
warning("Environment variable '$locals{$k}' not set for keyword '$k' (ignored)");
|
|
||||||
delete $locals{$k};
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
# Set the value to the value of the environment variable
|
|
||||||
$locals{$1} = $ENV{$locals{$k}};
|
|
||||||
# Remove the '_env' suffix from the key
|
|
||||||
# TODO: Shouldn't the *_env entry be deleted from %locals?
|
|
||||||
$k = $1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$locals{$k} = $passwords{$k} if defined $passwords{$k};
|
$locals{$k} = $passwords{$k} if defined $passwords{$k};
|
||||||
if (!exists $variables{'merged'}{$k}) {
|
if (!exists $variables{'merged'}{$k}) {
|
||||||
warning("unrecognized keyword '%s' (ignored)", $k);
|
warning("unrecognized keyword '%s' (ignored)", $k);
|
||||||
|
|
|
@ -44,8 +44,16 @@ my @test_cases = (
|
||||||
tc('unquoted escaped backslash', "a=\\\\", { a => "\\" }, ""),
|
tc('unquoted escaped backslash', "a=\\\\", { a => "\\" }, ""),
|
||||||
tc('squoted escaped squote', "a='\\''", { a => "'" }, ""),
|
tc('squoted escaped squote', "a='\\''", { a => "'" }, ""),
|
||||||
tc('dquoted escaped dquote', "a=\"\\\"\"", { a => '"' }, ""),
|
tc('dquoted escaped dquote', "a=\"\\\"\"", { a => '"' }, ""),
|
||||||
|
tc('env: empty', "a_env=", {}, ""),
|
||||||
|
tc('env: unset', "a_env=UNSET", {}, ""),
|
||||||
|
tc('env: set', "a_env=TEST", { a => 'val' }, ""),
|
||||||
|
tc('env: single quoted', "a_env='TEST'", { a => 'val' }, ""),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
delete($ENV{''});
|
||||||
|
delete($ENV{UNSET});
|
||||||
|
$ENV{TEST} = 'val';
|
||||||
|
|
||||||
for my $tc (@test_cases) {
|
for my $tc (@test_cases) {
|
||||||
my ($got_rest, %got_vars) = ddclient::parse_assignments($tc->{input});
|
my ($got_rest, %got_vars) = ddclient::parse_assignments($tc->{input});
|
||||||
subtest $tc->{name} => sub {
|
subtest $tc->{name} => sub {
|
||||||
|
|
Loading…
Reference in a new issue