lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/Create.pm

filter: Statementstmt 83.9% 47 / 56 Branchbran 45.0% 9 / 20 Conditioncond 20.0% 2 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 64.9% 63 / 97 CC 16 SCAR 35.2
CC
16
Cov
67%
execute
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 33.8
« lib/WWW/Hetzner/CLI/Cmd/Firewall/Cmd/Describe.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/LoadBalancer/Cmd/Describe.pm »
1 package WWW::Hetzner::CLI::Cmd::StorageBox::Cmd::Create;
2 # ABSTRACT: Create a Storage Box
3  
4 1 our $VERSION = '0.102';
5  
6 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use MooX::Cmd;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use MooX::Options usage_string => 'USAGE: hcloud.pl storage-box create --name <name> --type <type> --location <location> --password <password> [options]';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use JSON::MaybeXS qw(encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 with 'WWW::Hetzner::CLI::Role::WaitsForAction';
11  
12  
13 1 option name => ( is => 'ro', format => 's', required => 1, doc => 'Storage Box name' );
14 1 option type => ( is => 'ro', format => 's', required => 1, doc => 'Storage Box type ID or name' );
15 1 option location => ( is => 'ro', format => 's', required => 1, doc => 'Location ID or name' );
16 1 option password => ( is => 'ro', format => 's', required => 1, doc => 'Storage Box password' );
17 1 option label => ( is => 'ro', format => 's@', autosplit => ',', doc => 'Label key=value (repeatable)' );
18 1 option ssh_key => ( is => 'ro', format => 's@', autosplit => ',', doc => 'OpenSSH public key (repeatable)' );
19 1 option reachable_externally => ( is => 'ro', doc => 'Allow access outside Hetzner networks' );
20 1 option enable_samba => ( is => 'ro', doc => 'Enable Samba' );
21 1 option enable_ssh => ( is => 'ro', doc => 'Enable SSH' );
22 1 option enable_webdav => ( is => 'ro', doc => 'Enable WebDAV' );
23 1 option enable_zfs => ( is => 'ro', doc => 'Show the ZFS Snapshot folder' );
24  
25 1 ▶sub execute {
Subroutine execute: called CC=16 SCAR=37.4
Pod undocumented
26 1 my ($self, $args, $chain) = @_;
27 1 my $main = $chain->[0];
28 1 my %params = (
29 name => $self->name,
30 storage_box_type => $self->type,
31 location => $self->location,
32 password => $self->password,
33 );
34  
35 1 ▶ if ($self->label) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->label) 0 1 1
36 0 my %labels;
37 0 for my $label (@{$self->label}) {
38 0 my ($key, $value) = split /=/, $label, 2;
39 0 ▶ die "Label must be key=value\n" unless defined $key && length $key && defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key and length $key and defined $value 0 0 0
Condition0%0/6
defined $key and length $key and defined $value
!ll&&!rl&&r
000
defined $key and length $key
!ll&&!rl&&r
000
MC/DC0%0/3
defined $key and length $key and defined $value
defined $key length $key defined $value
Truth table0%0/4
A and B and C
A= defined $keyB= length $keyC= defined $value
ABCresult
0XX0
10X0
1100
1111
40 0 $labels{$key} = $value;
41 }
42 0 $params{labels} = \%labels;
43 }
44 1 ▶ $params{ssh_keys} = $self->ssh_key if $self->ssh_key;
Branch: 1 branch
BranchTrueFalseTotal
if $self->ssh_key 0 1 1
45  
46 1 my %access;
47 1 ▶ $access{reachable_externally} = $self->reachable_externally if defined $self->reachable_externally;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->reachable_externally 0 1 1
48 1 ▶ $access{samba_enabled} = $self->enable_samba if defined $self->enable_samba;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->enable_samba 0 1 1
49 1 ▶ $access{ssh_enabled} = $self->enable_ssh if defined $self->enable_ssh;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->enable_ssh 0 1 1
50 1 ▶ $access{webdav_enabled} = $self->enable_webdav if defined $self->enable_webdav;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->enable_webdav 0 1 1
51 1 ▶ $access{zfs_enabled} = $self->enable_zfs if defined $self->enable_zfs;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->enable_zfs 0 1 1
52 1 ▶ $params{access_settings} = \%access if %access;
Branch: 1 branch
BranchTrueFalseTotal
if %access 0 1 1
53  
54 1 print "Creating Storage Box '", $self->name, "'...\n";
55 1 my $box = $main->storage->storage_boxes->create(%params);
56 1 $self->handle_action($box->action);
57  
58 1 ▶ if ($main->output eq 'json') {
Branch: 1 branch
BranchTrueFalseTotal
if ($main->output eq "json") 0 1 1
59 0 print encode_json($box->data), "\n";
60 0 return;
61 }
62 1 print "Storage Box created:\n";
63 1 printf " ID: %s\n", $box->id;
64 1 printf " Name: %s\n", $box->name;
65 1 ▶ printf " Status: %s\n", $box->status // '-';
Condition50%1/2
$box->status // "-"
l!l
10
MC/DC0%0/1
$box->status // "-"
$box->status
Truth table50%1/2
A
A= $box->status
Aresult
11
00
66 1 ▶ printf " Username: %s\n", $box->username // '-';
Condition50%1/2
$box->username // "-"
l!l
10
MC/DC0%0/1
$box->username // "-"
$box->username
Truth table50%1/2
A
A= $box->username
Aresult
11
00
67 }
68  
69 1 1;
70  
71 __END__
« lib/WWW/Hetzner/CLI/Cmd/Firewall/Cmd/Describe.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/LoadBalancer/Cmd/Describe.pm »