WWW-Hetzner

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

Revision history for WWW-Hetzner

0.102     2026-10-21 18:48:51Z
    - The distribution declares LWP::Protocol::https, without it every
      https target fails
    - Fix: transport failures (connection refused, DNS, TLS, timeout) now
      croak with LWP's reason instead of a bare "Hetzner API error: 500";
      non-JSON error bodies (e.g. a proxy's HTML 502) contribute their status
      and text to the error message
    - Fix: the debug log no longer prints password, private_key and
      user_data values of request bodies
    - New: WWW::Hetzner::Cloud::Costs, $cloud->costs(label_selector => ...,
      price => 'gross'|'net') sums the hourly and monthly cost per resource
      and in total for servers (plus the server backup surcharge when
      backup_window is set), volumes, primary IPs, floating IPs and load
      balancers, priced per location from /pricing. Gross by default; the
      result carries price and vat_rate. Where /pricing has no hourly price
      (volumes, floating IPs) hourly is derived as monthly/624 and flagged
      hourly_derived. Resources without a price warn and stay out of the
      totals

lib/WWW/Hetzner/Cloud/API/Certificates.pm  view on Meta::CPAN

    croak "name required" unless $params{name};
    croak "type required (uploaded or managed)" unless $params{type};

    my $body = {
        name => $params{name},
        type => $params{type},
    };

    # For uploaded certificates
    $body->{certificate} = $params{certificate} if $params{certificate};
    $body->{private_key} = $params{private_key} if $params{private_key};

    # For managed certificates
    $body->{domain_names} = $params{domain_names} if $params{domain_names};

    $body->{labels} = $params{labels} if $params{labels};

    my $result = $self->client->post('/certificates', $body);
    return $self->_wrap(
        $result->{certificate},
        action       => $self->_wrap_action($result->{action}),

lib/WWW/Hetzner/Cloud/API/Certificates.pm  view on Meta::CPAN

        name         => 'my-cert',
        type         => 'managed',
        domain_names => ['example.com', 'www.example.com'],
    );

    # Create uploaded certificate
    my $cert = $cloud->certificates->create(
        name        => 'my-cert',
        type        => 'uploaded',
        certificate => $pem_cert,
        private_key => $pem_key,
    );

    # Delete
    $cloud->certificates->delete($cert->id);

=head1 DESCRIPTION

This module provides the API for managing Hetzner Cloud certificates.
All methods return L<WWW::Hetzner::Cloud::Certificate> objects.

lib/WWW/Hetzner/Cloud/API/Certificates.pm  view on Meta::CPAN

        type         => 'managed',      # required
        domain_names => ['example.com'],# required for managed
        labels       => { ... },        # optional
    );

    # Uploaded certificate
    my $cert = $cloud->certificates->create(
        name        => 'my-cert',       # required
        type        => 'uploaded',      # required
        certificate => $pem_cert,       # required for uploaded
        private_key => $pem_key,        # required for uploaded
        labels      => { ... },         # optional
    );

Creates certificate. Returns L<WWW::Hetzner::Cloud::Certificate> object.

=head2 update

    $cloud->certificates->update($id, name => 'new-name', labels => { ... });

Updates certificate. Returns L<WWW::Hetzner::Cloud::Certificate> object.

lib/WWW/Hetzner/Role/HTTP.pm  view on Meta::CPAN


    if ($opts{body}) {
        $req_args{content} = $self->_encode_body($opts{body});
        $log->debugf("Body: %s", $self->_encode_body($self->_mask_body($opts{body})));
    }

    return WWW::Hetzner::HTTPRequest->new(%req_args);
}


my @SECRET_KEYS = qw(password private_key user_data);

sub _mask_body {
    my ($self, $body) = @_;
    return $body unless ref $body eq 'HASH';
    my %copy = %$body;
    for my $key (@SECRET_KEYS) {
        $copy{$key} = '********' if defined $copy{$key};
    }
    return \%copy;
}

lib/WWW/Hetzner/Role/HTTP.pm  view on Meta::CPAN

C<application/x-www-form-urlencoded> instead.

A client with a different body format overrides L</_content_type> and
L</_encode_body>.

HTTP transport is delegated to a pluggable L<WWW::Hetzner::Role::IO> backend
(default: L<WWW::Hetzner::LWPIO>), making it possible to use async HTTP
clients.

Uses L<Log::Any> for logging HTTP requests and responses. The debug log of a
request body masks the top-level keys C<password>, C<private_key> and
C<user_data>; the request itself is sent unchanged.

Non-2xx responses croak with C<Hetzner API error: ...>: the API's error
message if the body carries one, otherwise the status code followed by the
(tag-stripped, truncated) body text.

=head1 REQUIRED ATTRIBUTES

Classes consuming this role must provide:

t/logging.t  view on Meta::CPAN


    ok(@errors >= 1, 'has error messages');
    like($errors[0]->{message}, qr/Invalid token/, 'error contains API message');
};

subtest 'debug body log masks secrets' => sub {
    my $log_ = Log::Any->get_logger(category => 'WWW::Hetzner::Role::HTTP');
    $log_->clear;
    my $cloud = mock_cloud('POST /servers' => { server => {} });
    my $req = $cloud->_build_request('POST', '/servers', body => {
        name => 'web', user_data => 'secret-ud', password => 'hunter2', private_key => 'KEY',
    });
    my ($body) = grep { $_->{message} =~ /^Body:/ } @{ $log_->msgs };
    ok($body, 'body logged');
    unlike($body->{message}, qr/secret-ud|hunter2|KEY/, 'secrets masked in log');
    like($body->{message}, qr/web/, 'other fields kept');
    like($req->content, qr/hunter2/, 'request itself unchanged');
};

done_testing;



( run in 1.078 second using v1.01-cache-2.11-cpan-8379b9b8ec2 )