Pass url through to create and update

This commit is contained in:
Matthew Slowe 2023-09-02 14:52:53 +01:00
parent a7031753d2
commit f1617977a9

View File

@ -209,13 +209,13 @@ sub check_and_update_record($$$$$) {
# Update the record # Update the record
$record->{ttl} = $in->[0]->{defaults}->{ttl}->{$zone}; $record->{ttl} = $in->[0]->{defaults}->{ttl}->{$zone};
_debug("Will update ", $url, $record, to_json($record)); _debug("Will update ", $url, $record, to_json($record));
push(@to_update, $record); push(@to_update, [$url,$record]);
} }
} else { } else {
# Create new record # Create new record
my $new = format_record($zone, $type, $host, $value); my $new = format_record($zone, $type, $host, $value);
_notice("Will create new record: %s %s %s", $host, $type, $value); _notice("Will create new record: %s %s %s", $host, $type, $value);
push(@to_create, $new); push(@to_create, [$url,$new]);
} }
} }
@ -297,10 +297,10 @@ unless($DRY_RUN) {
# Create # Create
foreach my $record (@to_create) { foreach my $record (@to_create) {
my $res = $ua->post( my $res = $ua->post(
$url, $record[0],
"Content-Type" => "application/json", "Content-Type" => "application/json",
Content => to_json({ Content => to_json({
records => [ $record ] records => [ $record[1] ]
}) })
); );
warn "Failed to create $url: " . $res->status_line . "\n" . $res->content unless $res->is_success; warn "Failed to create $url: " . $res->status_line . "\n" . $res->content unless $res->is_success;
@ -309,9 +309,9 @@ unless($DRY_RUN) {
# Update # Update
foreach my $record (@to_update) { foreach my $record (@to_update) {
my $res = $ua->put( my $res = $ua->put(
$url, $record[0],
"Content-Type" => "application/json", "Content-Type" => "application/json",
"Content" => to_json({ records => [ $record ] }), "Content" => to_json({ records => [ $record[1] ] }),
); );
warn "Failed to update $url: " . $res->status_line unless $res->is_success; warn "Failed to update $url: " . $res->status_line unless $res->is_success;
} }