dnsexit2: Delete unnecessary comments

Comments should only be used if the code is doing something
subtle/tricky/non-obvious/unusual, otherwise they're distracting and
might get out of sync with the code (in which case it becomes
difficult to tell if it's the comment or the code that's wrong).  If
the code is difficult to understand without comments but is doing
something ordinary, then the code needs to be modified to improve
readability.
This commit is contained in:
Richard Hansen 2024-05-29 17:51:00 -04:00
parent 61d34a9157
commit 18007dda8a

View file

@ -4194,29 +4194,20 @@ sub nic_dnsexit2_update {
ttl => $config{$h}{'ttl'}, ttl => $config{$h}{'ttl'},
}; };
}; };
# Set the URL of the API endpoint
my $url = "https://$config{$h}{'server'}$config{$h}{'path'}"; my $url = "https://$config{$h}{'server'}$config{$h}{'path'}";
# Set additional headers
my $header = "Content-Type: application/json\nAccept: application/json"; my $header = "Content-Type: application/json\nAccept: application/json";
# Set the zone if empty
if (not defined $config{$h}{'zone'}) { if (not defined $config{$h}{'zone'}) {
debug("Zone not defined, setting to default hostname: %s", $h); debug("Zone not defined, setting to default hostname: %s", $h);
$config{$h}{'zone'} = $h $config{$h}{'zone'} = $h
} else { } else {
debug("Zone is: %s", $config{$h}{'zone'}); debug("Zone is: %s", $config{$h}{'zone'});
} }
# Build total JSON payload
my @payload_values = values %total_payload; my @payload_values = values %total_payload;
my $data = encode_json({ my $data = encode_json({
apikey => $config{$h}{'password'}, apikey => $config{$h}{'password'},
domain => $config{$h}{'zone'}, domain => $config{$h}{'zone'},
update => \@payload_values update => \@payload_values
}); });
# Make the call
my $reply = geturl( my $reply = geturl(
proxy => opt('proxy'), proxy => opt('proxy'),
url => $url, url => $url,
@ -4224,20 +4215,13 @@ sub nic_dnsexit2_update {
method => 'POST', method => 'POST',
data => $data data => $data
); );
# No reply, declare as failed
unless ($reply && header_ok($h, $reply)) { unless ($reply && header_ok($h, $reply)) {
failed("updating %s: Could not connect to %s%s.", $h, $config{$h}{'server'}, $config{$h}{'path'}); failed("updating %s: Could not connect to %s%s.", $h, $config{$h}{'server'}, $config{$h}{'path'});
last; last;
}; };
# Reply found
debug("%s", $reply); debug("%s", $reply);
# Extract the HTTP response code
(my $http_status) = ($reply =~ m%^s*HTTP/.*\s+(\d+)%i); (my $http_status) = ($reply =~ m%^s*HTTP/.*\s+(\d+)%i);
debug("HTTP response code: %s", $http_status); debug("HTTP response code: %s", $http_status);
# If not 200, bail
if ($http_status ne '200') { if ($http_status ne '200') {
failed("Failed to update Host\n%s", $h); failed("Failed to update Host\n%s", $h);
failed("HTTP response code\n%s", $http_status); failed("HTTP response code\n%s", $http_status);
@ -4254,11 +4238,7 @@ sub nic_dnsexit2_update {
} else { } else {
warning("Unexpected: no HTTP headers stripped!"); warning("Unexpected: no HTTP headers stripped!");
} }
# Decode the remaining reply, it should be JSON.
my $response = decode_json($reply); my $response = decode_json($reply);
# It should at least have a 'code' and 'message'.
if (!defined($response->{'code'}) || !defined($response->{'message'})) { if (!defined($response->{'code'}) || !defined($response->{'message'})) {
failed("Did not receive expected \"code\" and \"message\" keys in server response."); failed("Did not receive expected \"code\" and \"message\" keys in server response.");
failed("Response:"); failed("Response:");
@ -4285,8 +4265,6 @@ sub nic_dnsexit2_update {
defined($response->{'details'}) ? $response->{'details'}[0] : "no details received"); defined($response->{'details'}) ? $response->{'details'}[0] : "no details received");
$config{$h}{'status-ipv4'} = $status if $ipv4; $config{$h}{'status-ipv4'} = $status if $ipv4;
$config{$h}{'status-ipv6'} = $status if $ipv6; $config{$h}{'status-ipv6'} = $status if $ipv6;
# Handle statuses
if ($status ne 'good') { if ($status ne 'good') {
if ($status eq 'warning') { if ($status eq 'warning') {
warning("%s", $message); warning("%s", $message);