| 1 | package WWW::Hetzner::Storage::API::Subaccounts; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Hetzner Storage Box Subaccounts 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::Subaccount; | ||||||||||||||||||||||||||
|
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 | has storage_box_id => ( | |||||||||||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||||||||||
| 20 | required => 1, | ||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 11 | with 'WWW::Hetzner::Role::HasActions'; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | has '+action_poll_path' => ( | ||||||||||||||||||||||||||||
| 26 | 17 | ▶ | default => sub { '/storage_boxes/actions' }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 11 | ); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 21 | ▶ | sub _base_path { | ||||||||||||||||||||||||||
|
Subroutine
_base_path: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 21 | my ($self) = @_; | |||||||||||||||||||||||||||
| 31 | 21 | return '/storage_boxes/' . $self->storage_box_id . '/subaccounts'; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 12 | ▶ | sub _wrap { | ||||||||||||||||||||||||||
|
Subroutine
_wrap: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 12 | my ($self, $data, %extra) = @_; | |||||||||||||||||||||||||||
| 36 | 12 | return WWW::Hetzner::Storage::Subaccount->new( | |||||||||||||||||||||||||||
| 37 | client => $self->client, | ||||||||||||||||||||||||||||
| 38 | storage_box_id => $self->storage_box_id, | ||||||||||||||||||||||||||||
| 39 | %$data, | ||||||||||||||||||||||||||||
| 40 | %extra, | ||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 4 | ▶ | sub _wrap_list { | ||||||||||||||||||||||||||
|
Subroutine
_wrap_list: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 45 | 4 | my ($self, $list) = @_; | |||||||||||||||||||||||||||
| 46 | 4 | ▶ | return [ map { $self->_wrap($_) } @{ $list // [] } ]; | ||||||||||||||||||||||||||
|
Condition50%1/2
$list // []
MC/DC0%0/1
$list // []
$list
Truth table50%1/2
A
A= $list
| |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 4 | ▶ | sub list { | ||||||||||||||||||||||||||
|
Subroutine
list: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 4 | my ($self, %params) = @_; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 4 | my $result = $self->client->get($self->_base_path, params => \%params); | |||||||||||||||||||||||||||
| 54 | 4 | ▶ | return $self->_wrap_list($result->{subaccounts} // []); | ||||||||||||||||||||||||||
|
Condition50%1/2
$result->{"subaccounts"} // []
MC/DC0%0/1
$result->{"subaccounts"} // []
$result->{"subaccounts"}
Truth table50%1/2
A
A= $result->{"subaccounts"}
| |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 3 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 3 | my ($self, $id) = @_; | |||||||||||||||||||||||||||
| 60 | 3 | ▶ | croak 'Subaccount ID required' unless $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 3 | my $result = $self->client->get($self->_base_path . "/$id"); | |||||||||||||||||||||||||||
| 63 | 3 | return $self->_wrap($result->{subaccount}); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 4 | ▶ | sub create { | ||||||||||||||||||||||||||
|
Subroutine
create: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | 4 | my ($self, %params) = @_; | |||||||||||||||||||||||||||
| 69 | 4 | for my $field (qw(home_directory password)) { | |||||||||||||||||||||||||||
| 70 | 7 | ▶ | 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}
| |||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | my $body = { | ||||||||||||||||||||||||||||
| 74 | home_directory => $params{home_directory}, | ||||||||||||||||||||||||||||
| 75 | password => $params{password}, | ||||||||||||||||||||||||||||
| 76 | 2 | }; | |||||||||||||||||||||||||||
| 77 | 2 | for my $field (qw(access_settings description labels name)) { | |||||||||||||||||||||||||||
| 78 | 8 | ▶ | $body->{$field} = $params{$field} if exists $params{$field}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 2 | my $result = $self->client->post($self->_base_path, $body); | |||||||||||||||||||||||||||
| 82 | return $self->_wrap( | ||||||||||||||||||||||||||||
| 83 | $result->{subaccount}, | ||||||||||||||||||||||||||||
| 84 | 2 | action => $self->_wrap_action($result->{action}), | |||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 3 | ▶ | sub update { | ||||||||||||||||||||||||||
|
Subroutine
update: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 90 | 3 | my ($self, $id, %params) = @_; | |||||||||||||||||||||||||||
| 91 | 3 | ▶ | croak 'Subaccount ID required' unless $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 3 | my $body = {}; | |||||||||||||||||||||||||||
| 94 | 3 | for my $field (qw(name description labels)) { | |||||||||||||||||||||||||||
| 95 | 9 | ▶ | $body->{$field} = $params{$field} if exists $params{$field}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 3 | my $result = $self->client->put($self->_base_path . "/$id", $body); | |||||||||||||||||||||||||||
| 99 | 3 | return $self->_wrap($result->{subaccount}); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 3 | ▶ | sub delete { | ||||||||||||||||||||||||||
|
Subroutine
delete: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 104 | 3 | my ($self, $id) = @_; | |||||||||||||||||||||||||||
| 105 | 3 | ▶ | croak 'Subaccount ID required' unless $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 3 | my $result = $self->client->delete($self->_base_path . "/$id"); | |||||||||||||||||||||||||||
| 108 | 3 | return $self->_wrap_action($result->{action}); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 6 | ▶ | sub _action { | ||||||||||||||||||||||||||
|
Subroutine
_action: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 112 | 6 | my ($self, $id, $name, $body) = @_; | |||||||||||||||||||||||||||
| 113 | 6 | ▶ | croak 'Subaccount ID required' unless $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 6 | my $path = $self->_base_path . "/$id/actions/$name"; | |||||||||||||||||||||||||||
| 116 | 6 | my $result = $self->client->post($path, $body); | |||||||||||||||||||||||||||
| 117 | 6 | return $self->_wrap_action($result->{action}); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 2 | ▶ | sub change_home_directory { | ||||||||||||||||||||||||||
|
Subroutine
change_home_directory: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||
| 122 | 2 | my ($self, $id, %params) = @_; | |||||||||||||||||||||||||||
| 123 | 2 | ▶ | croak 'home_directory required' unless defined $params{home_directory} && length $params{home_directory}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $params{"home_directory"} and length $params{"home_directory"}
MC/DC0%0/2
defined $params{"home_directory"} and length $params{"home_directory"}
defined $params{"home_directory"}
length $params{"home_directory"}
Truth table33%1/3
A and B
A= defined $params{"home_directory"}B= length $params{"home_directory"}
| |||||||||||||||||||||||||||||
| 124 | return $self->_action($id, 'change_home_directory', { | ||||||||||||||||||||||||||||
| 125 | home_directory => $params{home_directory}, | ||||||||||||||||||||||||||||
| 126 | 2 | }); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 2 | ▶ | sub reset_subaccount_password { | ||||||||||||||||||||||||||
|
Subroutine
reset_subaccount_password: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||
| 131 | 2 | my ($self, $id, %params) = @_; | |||||||||||||||||||||||||||
| 132 | 2 | ▶ | croak 'password required' unless defined $params{password} && length $params{password}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $params{"password"} and length $params{"password"}
MC/DC0%0/2
defined $params{"password"} and length $params{"password"}
defined $params{"password"}
length $params{"password"}
Truth table33%1/3
A and B
A= defined $params{"password"}B= length $params{"password"}
| |||||||||||||||||||||||||||||
| 133 | return $self->_action($id, 'reset_subaccount_password', { | ||||||||||||||||||||||||||||
| 134 | password => $params{password}, | ||||||||||||||||||||||||||||
| 135 | 2 | }); | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 2 | ▶ | sub update_access_settings { | ||||||||||||||||||||||||||
|
Subroutine
update_access_settings: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 140 | 2 | my ($self, $id, %params) = @_; | |||||||||||||||||||||||||||
| 141 | 2 | my $body = {}; | |||||||||||||||||||||||||||
| 142 | 2 | for my $field (qw(reachable_externally readonly samba_enabled ssh_enabled webdav_enabled)) { | |||||||||||||||||||||||||||
| 143 | 10 | ▶ | $body->{$field} = $params{$field} if exists $params{$field}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | 2 | return $self->_action($id, 'update_access_settings', $body); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 11 | 1; | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | __END__ | ||||||||||||||||||||||||||||