hetzner: Remove unnecessary host groupings

Each host is already updated individually so there's no point in
grouping the hosts.
This commit is contained in:
Richard Hansen 2024-07-12 19:33:49 -04:00
parent 5ae0fd3024
commit 216c9c6010

View file

@ -6253,31 +6253,25 @@ EoEXAMPLE
######################################################################
sub nic_hetzner_update {
debug("\nnic_hetzner_update -------------------");
my %groups = group_hosts_by(\@_, [qw(ssh login password server wildcard mx backupmx zone wantipv4 wantipv6)]);
for my $sig (keys %groups) {
my @hosts = @{$groups{$sig}};
my $hosts = join(',', @hosts);
my $key = $hosts[0];
my $headers = "Auth-API-Token: $config{$key}{'password'}\n";
for my $domain (@_) {
my $headers = "Auth-API-Token: $config{$domain}{'password'}\n";
$headers .= "Content-Type: application/json";
for my $domain (@hosts) {
(my $hostname = $domain) =~ s/\.$config{$key}{zone}$//;
(my $hostname = $domain) =~ s/\.$config{$domain}{zone}$//;
my $ipv4 = delete $config{$domain}{'wantipv4'};
my $ipv6 = delete $config{$domain}{'wantipv6'};
info("getting Hetzner Zone ID for %s", $domain);
# Get zone ID
my $url = "https://$config{$key}{'server'}/zones?name=" . $config{$key}{'zone'};
my $url = "https://$config{$domain}{'server'}/zones?name=" . $config{$domain}{'zone'};
my $reply = geturl(proxy => opt('proxy'),
url => $url,
headers => $headers
);
unless ($reply && header_ok($domain, $reply)) {
failed("updating %s: Could not connect to %s.", $domain, $config{$key}{'server'});
failed("updating %s: Could not connect to %s.", $domain, $config{$domain}{'server'});
next;
}
@ -6290,9 +6284,9 @@ sub nic_hetzner_update {
}
# Pull the ID out of the json, messy
my ($zone_id) = map {$_->{name} eq $config{$key}{'zone'} ? $_->{id} : ()} @{$response->{zones}};
my ($zone_id) = map {$_->{name} eq $config{$domain}{'zone'} ? $_->{id} : ()} @{$response->{zones}};
unless ($zone_id) {
failed("updating %s: No zone ID found.", $config{$key}{'zone'});
failed("updating %s: No zone ID found.", $config{$domain}{'zone'});
next;
}
info("Zone ID is %s", $zone_id);
@ -6307,13 +6301,13 @@ sub nic_hetzner_update {
$config{$domain}{"status-ipv$ipv"} = 'failed';
# Get DNS 'A' or 'AAAA' record ID
$url = "https://$config{$key}{'server'}/records?zone_id=$zone_id";
$url = "https://$config{$domain}{'server'}/records?zone_id=$zone_id";
$reply = geturl(proxy => opt('proxy'),
url => $url,
headers => $headers
);
unless ($reply && header_ok($domain, $reply)) {
failed("updating %s: Could not connect to %s.", $domain, $config{$key}{'server'});
failed("updating %s: Could not connect to %s.", $domain, $config{$domain}{'server'});
next;
}
# Strip header
@ -6331,11 +6325,11 @@ sub nic_hetzner_update {
if ($dns_rec_id)
{
debug("updating %s: DNS '$type' record ID: $dns_rec_id", $domain);
$url = "https://$config{$key}{'server'}/records/$dns_rec_id";
$url = "https://$config{$domain}{'server'}/records/$dns_rec_id";
$http_method = "PUT";
} else {
debug("creating %s: DNS '$type'", $domain);
$url = "https://$config{$key}{'server'}/records";
$url = "https://$config{$domain}{'server'}/records";
$http_method = "POST";
}
my $data = "{\"zone_id\":\"$zone_id\", \"name\": \"$hostname\", \"value\": \"$ip\", \"type\": \"$type\", \"ttl\": $config{$domain}{'ttl'}}";
@ -6364,7 +6358,6 @@ sub nic_hetzner_update {
}
}
}
}
######################################################################
## nic_yandex_examples