Vault/Secret/Kvv2.pm

filter: Statementstmt 35.4% 17 / 48 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 22.2% 2 / 9 Podpod 66.6% 2 / 3 totaltotal 25.9% 21 / 81 CC 11 SCAR 31.9
CC
11
Cov
25%
BUILD
56.0
_clear_self
12.0
_save
6.0
CRAP 24.2
« Vault/Secret/Generic.pm ↑ Summary Vault/Base.pm »
1 #!perl
2 # vim: softtabstop=4 tabstop=4 shiftwidth=4 ft=perl expandtab smarttab
3 # ABSTRACT: Perl API for HashiCorp's Vault (Secret)
4  
5 # See also https://github.com/hashicorp/vault-ruby
6 # And https://github.com/ianunruh/hvac
7 # And https://www.vaultproject.io/api/index.html
8  
9 package WebService::HashiCorp::Vault::Secret::Kvv2;
10  
11 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 our $VERSION = '0.04'; # VERSION
13 4 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 extends 'WebService::HashiCorp::Vault::Base';
16  
17 4 has '+mount' => ( is => 'ro', default => 'secret' );
18 4 has 'path' => ( is => 'ro' );
19 4 has 'auth' => ( is => 'ro' );
20 4 has '_metadata' => ( is => 'ro' );
21 has 'data' => ( is => 'rw',
22 0 ▶ trigger => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 0 my $self = shift;
24 0 $self->_save(@_);
25 0 $self->BUILD()
26 4 });
27 4 has 'lease_duration' => ( is => 'ro' );
28 4 has 'lease_id' => ( is => 'ro' );
29 4 has 'renewable' => ( is => 'ro' );
30  
31 0 ▶sub BUILD {
Subroutine BUILD: not called CC=7 SCAR=40.3
Pod undocumented
32 0 my $self = shift;
33 0 ▶ return unless $self->path;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->path 0 0 0
34 0 $self->_clear_self();
35 0 ▶ if (my $resp = $self->get( $self->_mkuri('data',$self->path) )) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $resp = $self->get($self->_mkuri("data", $self->path))) 0 0 0
36 $self->{auth} = $resp->{auth}
37 0 ▶ if $resp->{auth};
Branch: 1 branch
BranchTrueFalseTotal
if $resp->{"auth"} 0 0 0
38 0 $self->{data} = $resp->{data}->{data}; # avoid triggering the trigger
39 0 $self->{_metadata} = $resp->{data}->{metadata}; # avoid triggering the trigger
40 $self->{lease_duration} = $resp->{lease_duration}
41 0 ▶ if $resp->{lease_duration};
Branch: 1 branch
BranchTrueFalseTotal
if $resp->{"lease_duration"} 0 0 0
42 $self->{lease_id} = $resp->{lease_id}
43 0 ▶ if $resp->{lease_id};
Branch: 1 branch
BranchTrueFalseTotal
if $resp->{"lease_id"} 0 0 0
44 $self->{renewable} = 0 + $resp->{renewable} # convert from JSON::Boolean
45 0 ▶ if $resp->{renewable};
Branch: 1 branch
BranchTrueFalseTotal
if $resp->{"renewable"} 0 0 0
46 }
47 }
48  
49 0 ▶sub _mkuri {
Subroutine _mkuri: not called CC=1 SCAR=6.9
50 0 my $self = shift;
51 0 my @paths = @_;
52 0 return join '/',
53 $self->base_url,
54 $self->version,
55 $self->mount,
56 @paths
57 }
58  
59 0 ▶sub _clear_self {
Subroutine _clear_self: not called CC=3 SCAR=24.8
60 0 my $self = shift;
61 0 for my $k (qw/ auth data lease_duration lease_id renewable /) {
62 0 ▶ delete $self->{$k} if $self->{$k}
Branch: 1 branch
BranchTrueFalseTotal
if $self->{$k} 0 0 0
63 }
64 0 return 1
65 }
66  
67  
68 0 ▶sub delete {
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
69 0 my $self = shift;
70 0 my $result = $self->SUPER::delete( $self->_mkuri('data', $self->path) );
71 0 $self->_clear_self();
72 0 return $result
73 }
74  
75 0 ▶sub _save {
Subroutine _save: not called CC=2 SCAR=17.9
76 0 my $self = shift;
77 0 my $data = shift;
78 0 ▶ die sprintf( "Secret data must be hashref, not a %s\n", ref $data )
Branch: 1 branch
BranchTrueFalseTotal
if ref $data ne "HASH" 0 0 0
79 if ref $data ne 'HASH';
80 0 return $self->post( $self->_mkuri('data', $self->path), { data => $data } );
81 }
82  
83  
84 0 ▶sub list {
Subroutine list: not called CC=2 SCAR=17.9
Pod documented
85 0 my $self = shift;
86 0 ▶ my $result = $self->SUPER::list( $self->_mkuri('metadata', $self->path || ()) );
Condition0%0/3
$self->path || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->path || ()
$self->path ()
Truth table0%0/3
A || B
A= $self->pathB= ()
ABresult
1X1
011
000
87 return $result->{data}
88 0 }
89  
90  
91 4 1;
92  
93 __END__
« Vault/Secret/Generic.pm ↑ Summary Vault/Base.pm »