blib/lib/WebDyne/Cloudflare/SecretsStore.pm

filter: Statementstmt 94.5% 69 / 73 Branchbran 73.5% 25 / 34 Conditioncond 54.1% 13 / 24 MC/DCmcdc 35.7% 5 / 14 Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 4 totaltotal 77.1% 125 / 162 CC 26 SCAR 25.1
CC
26
Cov
82%
new
22.7
get
9.0
call_host
4.4
CRAP 12.3
« lib/WebDyne/Cloudflare/DurableObject.pm ↑ Summary blib/lib/WebDyne/Cloudflare/D1.pm »
1 package WebDyne::Cloudflare::SecretsStore;
2  
3 2 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Future::AsyncAwait;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use WebDyne::Cloudflare::SecretsStore::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION='0.001';
11 2 our $HOST_CALL;
12  
13 2 ▶use constant EXTENSION_NAME => 'webdyne.cloudflare.secrets_store';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use constant PROTOCOL_VERSION => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 my $json_or=JSON::PP->new()->canonical()->allow_nonref();
17  
18 4 ▶sub new {
Subroutine new: called CC=16 SCAR=31.2
Pod undocumented
19 4 my ($class, %opt)=@_;
20 4 my $scope_hr=$opt{'scope'};
21 4 ▶ die "WebDyne::Cloudflare::SecretsStore requires a PAGI scope hash\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $scope_hr eq "HASH" 0 4 4
22 unless ref($scope_hr) eq 'HASH';
23 my $extension_hr=(ref($scope_hr->{'extensions'}) eq 'HASH')
24 4 ▶ ? $scope_hr->{'extensions'}{EXTENSION_NAME()}
Branch: 1 branch
BranchTrueFalseTotal
ref $scope_hr->{'extensions'} eq 'HASH' ? : 3 1 4
25 : undef;
26 4 ▶ die "PAGI scope has no " . EXTENSION_NAME() . " capability\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $extension_hr eq "HASH" 1 3 4
27 unless ref($extension_hr) eq 'HASH';
28 die "Unsupported SecretsStore capability protocol\n"
29 unless (defined($extension_hr->{'version'})
30 &&!ref($extension_hr->{'version'})
31 3 ▶ &&($extension_hr->{'version'} eq PROTOCOL_VERSION()));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $extension_hr->{"version"} and not ref $extension_hr->{"version"} and $extension_hr->{"version"} eq 1 0 3 3
Condition33%2/6
defined $extension_hr->{"version"} and not ref $extension_hr->{"version"} and $extension_hr->{"version"} eq 1
!ll&&!rl&&r
003
defined $extension_hr->{"version"} and not ref $extension_hr->{"version"}
!ll&&!rl&&r
003
MC/DC0%0/3
defined $extension_hr->{"version"} and not ref $extension_hr->{"version"} and $extension_hr->{"version"} eq 1
defined $extension_hr->{"version"} not ref $extension_hr->{"version"} $extension_hr->{"version"} eq 1
Truth table25%1/4
A and not(B) and C
A= defined $extension_hr->{"version"}B= not ref $extension_hr->{"version"}C= $extension_hr->{"version"} eq 1
ABCresult
0XX0
10X0
1100
1111
32 die "Invalid SecretsStore capability token\n"
33 unless (defined($extension_hr->{'capability'})
34 &&!ref($extension_hr->{'capability'})
35 3 ▶ &&length($extension_hr->{'capability'}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $extension_hr->{"capability"} and not ref $extension_hr->{"capability"} and length $extension_hr->{"capability"} 0 3 3
Condition33%2/6
defined $extension_hr->{"capability"} and not ref $extension_hr->{"capability"} and length $extension_hr->{"capability"}
!ll&&!rl&&r
003
defined $extension_hr->{"capability"} and not ref $extension_hr->{"capability"}
!ll&&!rl&&r
003
MC/DC0%0/3
defined $extension_hr->{"capability"} and not ref $extension_hr->{"capability"} and length $extension_hr->{"capability"}
defined $extension_hr->{"capability"} not ref $extension_hr->{"capability"} length $extension_hr->{"capability"}
Truth table25%1/4
A and not(B) and C
A= defined $extension_hr->{"capability"}B= not ref $extension_hr->{"capability"}C= length $extension_hr->{"capability"}
ABCresult
0XX0
10X0
1100
1111
36  
37 3 ▶ my $binding=(defined($opt{'binding'}) ? $opt{'binding'} : 'SECRET');
Branch: 1 branch
BranchTrueFalseTotal
defined $opt{'binding'} ? : 3 0 3
38 3 ▶ die "Invalid SecretsStore binding name '$binding'\n"
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $binding and $binding =~ /\A[A-Z_][A-Z0-9_]*\z/u 1 2 3
Condition66%2/3
not ref $binding and $binding =~ /\A[A-Z_][A-Z0-9_]*\z/u
!ll&&!rl&&r
012
MC/DC50%1/2
not ref $binding and $binding =~ /\A[A-Z_][A-Z0-9_]*\z/u
not ref $binding $binding =~ /\A[A-Z_][A-Z0-9_]*\z/u
Truth table66%2/3
not(A) and B
A= not ref $bindingB= $binding =~ /\A[A-Z_][A-Z0-9_]*\z/u
ABresult
0X0
100
111
39 unless (!ref($binding)&&($binding=~/\A[A-Z_][A-Z0-9_]*\z/));
40 2 my $bindings_ar=$extension_hr->{'bindings'};
41 2 ▶ die "Invalid SecretsStore capability binding list\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $bindings_ar eq "ARRAY" 0 2 2
42 unless (ref($bindings_ar) eq 'ARRAY');
43 2 ▶ my %binding=map { $_ => 1 } grep { defined($_)&&!ref($_) } @{$bindings_ar};
Condition33%1/3
defined $_ && !ref($_)
!ll&&!rl&&r
002
MC/DC0%0/2
defined $_ && !ref($_)
defined $_ !ref($_)
Truth table33%1/3
A && not(B)
A= defined $_B= !ref($_)
ABresult
0X0
100
111
44 die "SecretsStore binding '$binding' is not available to this request\n"
45 2 ▶ unless $binding{$binding};
Branch: 1 branch
BranchTrueFalseTotal
unless $binding{$binding} 1 1 2
46  
47 my $self=bless({
48 binding => $binding,
49 1 capability => $extension_hr->{'capability'},
50 }, $class);
51 1 return $self;
52 }
53  
54  
55 1 ▶sub binding { return shift()->{'binding'}; }
Subroutine binding: called CC=1 SCAR=0.0
Pod undocumented
56  
57  
58 12 ▶async sub get {
Subroutine get: called CC=9 SCAR=22.0
Pod undocumented
59 12 my ($self, @arg)=@_;
60 12 ▶ die "SecretsStore get accepts no arguments\n" if @arg;
Branch: 1 branch
BranchTrueFalseTotal
if @arg 1 11 12
61 my $wire=$json_or->encode({
62 version => PROTOCOL_VERSION,
63 capability => $self->{'capability'},
64 11 binding => $self->{'binding'},
65 operation => 'get',
66 });
67 11 my $response_wire;
68 11 my $called=eval { $response_wire=call_host($wire); 1 };
69 11 ▶ die WebDyne::Cloudflare::SecretsStore::Error->new(name => 'SECRETS_STORE_HOST_ERROR')
Branch: 1 branch
BranchTrueFalseTotal
unless $called 1 10 11
70 unless $called;
71 10 my $response_hr=eval { $json_or->decode($response_wire) };
72 die WebDyne::Cloudflare::SecretsStore::Error->new(name => 'SECRETS_STORE_PROTOCOL_ERROR')
73 10 ▶ unless ((ref($response_hr) eq 'HASH')&&JSON::PP::is_bool($response_hr->{'ok'}));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $response_hr eq "HASH" and JSON::PP::is_bool($response_hr->{"ok"}) 2 8 10
Condition100%3/3
ref $response_hr eq "HASH" and JSON::PP::is_bool($response_hr->{"ok"})
!ll&&!rl&&r
118
MC/DC100%2/2
ref $response_hr eq "HASH" and JSON::PP::is_bool($response_hr->{"ok"})
ref $response_hr eq "HASH" JSON::PP::is_bool($response_hr->{"ok"})
Truth table100%3/3
A and B
A= ref $response_hr eq "HASH"B= JSON::PP::is_bool($response_hr->{"ok"})
ABresult
0X0
100
111
74 8 ▶ unless ($response_hr->{'ok'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response_hr->{"ok"}) 2 6 8
75 2 ▶ my $error_hr=(ref($response_hr->{'error'}) eq 'HASH') ? $response_hr->{'error'} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $response_hr->{'error'} eq 'HASH' ? : 2 0 2
76 2 die WebDyne::Cloudflare::SecretsStore::Error->new(name => $error_hr->{'name'});
77 }
78 die WebDyne::Cloudflare::SecretsStore::Error->new(name => 'SECRETS_STORE_PROTOCOL_ERROR')
79 6 ▶ unless (defined($response_hr->{'result'})&&!ref($response_hr->{'result'}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $response_hr->{"result"} and not ref $response_hr->{"result"} 2 4 6
Condition100%3/3
defined $response_hr->{"result"} and not ref $response_hr->{"result"}
!ll&&!rl&&r
114
MC/DC100%2/2
defined $response_hr->{"result"} and not ref $response_hr->{"result"}
defined $response_hr->{"result"} not ref $response_hr->{"result"}
Truth table100%3/3
A and not(B)
A= defined $response_hr->{"result"}B= not ref $response_hr->{"result"}
ABresult
0X0
100
111
80 4 return $response_hr->{'result'};
81 2 }
82  
83  
84 11 ▶sub call_host {
Subroutine call_host: called CC=3 SCAR=14.8
Pod undocumented
85 11 my ($wire)=@_;
86 11 ▶ return $HOST_CALL->($wire) if $HOST_CALL;
Branch: 1 branch
BranchTrueFalseTotal
if $WebDyne::Cloudflare::SecretsStore::HOST_CALL 11 0 11
87 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
88 0 my $host_call_cr=*{'WebDyne::Cloudflare::SecretsStore::Host::call'}{'CODE'};
89 0 ▶ die "SecretsStore host adapter is not registered in this runtime\n" unless $host_call_cr;
Branch: 1 branch
BranchTrueFalseTotal
unless $host_call_cr 0 0 0
90 0 return $host_call_cr->($wire);
91 }
92  
93 2 1;
« lib/WebDyne/Cloudflare/DurableObject.pm ↑ Summary blib/lib/WebDyne/Cloudflare/D1.pm »