| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | : undef; | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 4 | ▶ | die "PAGI scope has no " . EXTENSION_NAME() . " capability\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
defined $extension_hr->{"version"} and not ref $extension_hr->{"version"} and $extension_hr->{"version"} eq 1
defined $extension_hr->{"version"} and not ref $extension_hr->{"version"}
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
defined $extension_hr->{"capability"} and not ref $extension_hr->{"capability"} and length $extension_hr->{"capability"}
defined $extension_hr->{"capability"} and not ref $extension_hr->{"capability"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | ▶ | my $binding=(defined($opt{'binding'}) ? $opt{'binding'} : 'SECRET'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | ▶ | die "Invalid SecretsStore binding name '$binding'\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not ref $binding and $binding =~ /\A[A-Z_][A-Z0-9_]*\z/u
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | unless (ref($bindings_ar) eq 'ARRAY'); | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | ▶ | my %binding=map { $_ => 1 } grep { defined($_)&&!ref($_) } @{$bindings_ar}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $_ && !ref($_)
MC/DC0%0/2
defined $_ && !ref($_)
defined $_
!ref($_)
Truth table33%1/3
A && not(B)
A= defined $_B= !ref($_)
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | die "SecretsStore binding '$binding' is not available to this request\n" | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | unless $binding{$binding}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
ref $response_hr eq "HASH" and JSON::PP::is_bool($response_hr->{"ok"})
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"})
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 8 | ▶ | unless ($response_hr->{'ok'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | ▶ | my $error_hr=(ref($response_hr->{'error'}) eq 'HASH') ? $response_hr->{'error'} : {}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $response_hr->{"result"} and not ref $response_hr->{"result"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | return $host_call_cr->($wire); | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||