| 1 | package WWW::Hetzner::Storage::API::StorageBoxes; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Hetzner Storage Boxes API | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 11 | our $VERSION = '0.102'; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use WWW::Hetzner::Storage::StorageBox; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 11 | has client => ( | |||||||||||||||||||||||||||
| 13 | is => 'ro', | ||||||||||||||||||||||||||||
| 14 | required => 1, | ||||||||||||||||||||||||||||
| 15 | weak_ref => 1, | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 11 | with 'WWW::Hetzner::Role::HasActions'; | |||||||||||||||||||||||||||
| 19 | 11 | with 'WWW::Hetzner::Role::Pagination'; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | has '+action_poll_path' => ( | ||||||||||||||||||||||||||||
| 22 | 30 | ▶ | default => sub { '/storage_boxes/actions' }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 11 | ); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 27 | ▶ | sub _wrap { | ||||||||||||||||||||||||||
|
Subroutine
_wrap: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 27 | my ($self, $data, %extra) = @_; | |||||||||||||||||||||||||||
| 27 | 27 | return WWW::Hetzner::Storage::StorageBox->new( | |||||||||||||||||||||||||||
| 28 | client => $self->client, | ||||||||||||||||||||||||||||
| 29 | %$data, | ||||||||||||||||||||||||||||
| 30 | %extra, | ||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 8 | ▶ | sub _wrap_list { | ||||||||||||||||||||||||||
|
Subroutine
_wrap_list: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 35 | 8 | my ($self, $list) = @_; | |||||||||||||||||||||||||||
| 36 | 8 | ▶ | return [ map { $self->_wrap($_) } @{ $list // [] } ]; | ||||||||||||||||||||||||||
|
Condition50%1/2
$list // []
MC/DC0%0/1
$list // []
$list
Truth table50%1/2
A
A= $list
| |||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 8 | ▶ | sub _list_page { | ||||||||||||||||||||||||||
|
Subroutine
_list_page: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 40 | 8 | my ($self, %params) = @_; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 8 | my $result = $self->client->get('/storage_boxes', params => \%params); | |||||||||||||||||||||||||||
| 43 | 8 | ▶ | return ($self->_wrap_list($result->{storage_boxes} // []), $result->{meta}); | ||||||||||||||||||||||||||
|
Condition50%1/2
$result->{"storage_boxes"} // []
MC/DC0%0/1
$result->{"storage_boxes"} // []
$result->{"storage_boxes"}
Truth table50%1/2
A
A= $result->{"storage_boxes"}
| |||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 2 | ▶ | sub list { | ||||||||||||||||||||||||||
|
Subroutine
list: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 2 | my ($self, %params) = @_; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 2 | my ($entities) = $self->_list_page(%params); | |||||||||||||||||||||||||||
| 51 | 2 | return $entities; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 12 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 12 | my ($self, $id) = @_; | |||||||||||||||||||||||||||
| 57 | 12 | ▶ | croak 'Storage Box ID required' unless $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 12 | my $result = $self->client->get("/storage_boxes/$id"); | |||||||||||||||||||||||||||
| 60 | 12 | return $self->_wrap($result->{storage_box}); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 1 | ▶ | sub get_by_name { | ||||||||||||||||||||||||||
|
Subroutine
get_by_name: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 1 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 66 | 1 | ▶ | croak 'Name required' unless $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 1 | my $boxes = $self->list_all(name => $name); | |||||||||||||||||||||||||||
| 69 | 1 | for my $box (@$boxes) { | |||||||||||||||||||||||||||
| 70 | 2 | ▶ | return $box if $box->name eq $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 0 | return; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 6 | ▶ | sub create { | ||||||||||||||||||||||||||
|
Subroutine
create: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 6 | my ($self, %params) = @_; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 6 | for my $field (qw(name location storage_box_type password)) { | |||||||||||||||||||||||||||
| 80 | 18 | ▶ | croak "$field required" unless defined $params{$field} && length $params{$field}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $params{$field} and length $params{$field}
MC/DC50%1/2
defined $params{$field} and length $params{$field}
defined $params{$field}
length $params{$field}
Truth table66%2/3
A and B
A= defined $params{$field}B= length $params{$field}
| |||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | my $body = { | ||||||||||||||||||||||||||||
| 84 | name => $params{name}, | ||||||||||||||||||||||||||||
| 85 | location => $params{location}, | ||||||||||||||||||||||||||||
| 86 | storage_box_type => $params{storage_box_type}, | ||||||||||||||||||||||||||||
| 87 | password => $params{password}, | ||||||||||||||||||||||||||||
| 88 | 2 | }; | |||||||||||||||||||||||||||
| 89 | 2 | for my $field (qw(labels ssh_keys access_settings)) { | |||||||||||||||||||||||||||
| 90 | 6 | ▶ | $body->{$field} = $params{$field} if exists $params{$field}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 2 | my $result = $self->client->post('/storage_boxes', $body); | |||||||||||||||||||||||||||
| 94 | return $self->_wrap( | ||||||||||||||||||||||||||||
| 95 | $result->{storage_box}, | ||||||||||||||||||||||||||||
| 96 | 2 | action => $self->_wrap_action($result->{action}), | |||||||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 5 | ▶ | sub update { | ||||||||||||||||||||||||||
|
Subroutine
update: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 102 | 5 | my ($self, $id, %params) = @_; | |||||||||||||||||||||||||||
| 103 | 5 | ▶ | croak 'Storage Box ID required' unless $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 5 | my $body = {}; | |||||||||||||||||||||||||||
| 106 | 5 | for my $field (qw(name labels)) { | |||||||||||||||||||||||||||
| 107 | 10 | ▶ | $body->{$field} = $params{$field} if exists $params{$field}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 5 | my $result = $self->client->put("/storage_boxes/$id", $body); | |||||||||||||||||||||||||||
| 111 | 5 | return $self->_wrap($result->{storage_box}); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 3 | ▶ | sub delete { | ||||||||||||||||||||||||||
|
Subroutine
delete: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 116 | 3 | my ($self, $id) = @_; | |||||||||||||||||||||||||||
| 117 | 3 | ▶ | croak 'Storage Box ID required' unless $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 3 | my $result = $self->client->delete("/storage_boxes/$id"); | |||||||||||||||||||||||||||
| 120 | 3 | return $self->_wrap_action($result->{action}); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 3 | ▶ | sub folders { | ||||||||||||||||||||||||||
|
Subroutine
folders: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||
| 125 | 3 | my ($self, $id, %params) = @_; | |||||||||||||||||||||||||||
| 126 | 3 | ▶ | croak 'Storage Box ID required' unless $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 3 | my $result = $self->client->get("/storage_boxes/$id/folders", params => \%params); | |||||||||||||||||||||||||||
| 129 | 3 | ▶ | return $result->{folders} // []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$result->{"folders"} // []
MC/DC0%0/1
$result->{"folders"} // []
$result->{"folders"}
Truth table50%1/2
A
A= $result->{"folders"}
| |||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 16 | ▶ | sub _action { | ||||||||||||||||||||||||||
|
Subroutine
_action: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 133 | 16 | my ($self, $id, $name, $body) = @_; | |||||||||||||||||||||||||||
| 134 | 16 | ▶ | croak 'Storage Box ID required' unless $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 16 | my $result = $self->client->post("/storage_boxes/$id/actions/$name", $body); | |||||||||||||||||||||||||||
| 137 | 16 | return $self->_wrap_action($result->{action}); | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 3 | ▶ | sub change_protection { | ||||||||||||||||||||||||||
|
Subroutine
change_protection: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 142 | 3 | my ($self, $id, %params) = @_; | |||||||||||||||||||||||||||
| 143 | 3 | my $body = {}; | |||||||||||||||||||||||||||
| 144 | 3 | ▶ | $body->{delete} = $params{delete} if exists $params{delete}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 3 | return $self->_action($id, 'change_protection', $body); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 3 | ▶ | sub change_type { | ||||||||||||||||||||||||||
|
Subroutine
change_type: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 150 | 3 | my ($self, $id, %params) = @_; | |||||||||||||||||||||||||||
| 151 | 3 | ▶ | croak 'storage_box_type required' unless $params{storage_box_type}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | return $self->_action($id, 'change_type', { | ||||||||||||||||||||||||||||
| 153 | storage_box_type => $params{storage_box_type}, | ||||||||||||||||||||||||||||
| 154 | 3 | }); | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 2 | ▶ | sub reset_password { | ||||||||||||||||||||||||||
|
Subroutine
reset_password: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 159 | 2 | my ($self, $id, %params) = @_; | |||||||||||||||||||||||||||
| 160 | 2 | ▶ | croak 'password required' unless $params{password}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 2 | return $self->_action($id, 'reset_password', { password => $params{password} }); | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 2 | ▶ | sub update_access_settings { | ||||||||||||||||||||||||||
|
Subroutine
update_access_settings: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 166 | 2 | my ($self, $id, %params) = @_; | |||||||||||||||||||||||||||
| 167 | 2 | my $body = {}; | |||||||||||||||||||||||||||
| 168 | 2 | for my $field (qw(reachable_externally samba_enabled ssh_enabled webdav_enabled zfs_enabled)) { | |||||||||||||||||||||||||||
| 169 | 10 | ▶ | $body->{$field} = $params{$field} if exists $params{$field}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | 2 | return $self->_action($id, 'update_access_settings', $body); | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 2 | ▶ | sub rollback_snapshot { | ||||||||||||||||||||||||||
|
Subroutine
rollback_snapshot: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 176 | 2 | my ($self, $id, %params) = @_; | |||||||||||||||||||||||||||
| 177 | 2 | ▶ | croak 'snapshot required' unless $params{snapshot}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | 2 | return $self->_action($id, 'rollback_snapshot', { snapshot => $params{snapshot} }); | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 2 | ▶ | sub enable_snapshot_plan { | ||||||||||||||||||||||||||
|
Subroutine
enable_snapshot_plan: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||
| 183 | 2 | my ($self, $id, %params) = @_; | |||||||||||||||||||||||||||
| 184 | 2 | for my $field (qw(max_snapshots minute hour)) { | |||||||||||||||||||||||||||
| 185 | 6 | ▶ | croak "$field required" unless exists $params{$field}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | my $body = { | ||||||||||||||||||||||||||||
| 189 | max_snapshots => $params{max_snapshots}, | ||||||||||||||||||||||||||||
| 190 | minute => $params{minute}, | ||||||||||||||||||||||||||||
| 191 | hour => $params{hour}, | ||||||||||||||||||||||||||||
| 192 | 2 | }; | |||||||||||||||||||||||||||
| 193 | 2 | for my $field (qw(day_of_week day_of_month)) { | |||||||||||||||||||||||||||
| 194 | 4 | ▶ | $body->{$field} = $params{$field} if exists $params{$field}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | 2 | return $self->_action($id, 'enable_snapshot_plan', $body); | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 2 | ▶ | sub disable_snapshot_plan { | ||||||||||||||||||||||||||
|
Subroutine
disable_snapshot_plan: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 201 | 2 | my ($self, $id) = @_; | |||||||||||||||||||||||||||
| 202 | 2 | return $self->_action($id, 'disable_snapshot_plan', {}); | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 11 | 1; | |||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | __END__ | ||||||||||||||||||||||||||||