Vault/Secret/Cubbyhole.pm

filter: Statementstmt 37.2% 16 / 43 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 25.0% 2 / 8 Podpod 66.6% 2 / 3 totaltotal 26.6% 20 / 75 CC 11 SCAR 32.4
CC
11
Cov
26%
BUILD
56.0
_clear_self
12.0
_save
6.0
CRAP 25.4
↑ Summary Vault/Secret/Generic.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::Cubbyhole;
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 => 'cubbyhole' );
18 4 has 'path' => ( is => 'ro' );
19 4 has 'auth' => ( is => 'ro' );
20 has 'data' => ( is => 'rw',
21 0 ▶ trigger => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 0 my $self = shift;
23 0 $self->_save(@_);
24 0 $self->BUILD()
25 4 });
26 4 has 'lease_duration' => ( is => 'ro' );
27 4 has 'lease_id' => ( is => 'ro' );
28 4 has 'renewable' => ( is => 'ro' );
29  
30 0 ▶sub BUILD {
Subroutine BUILD: not called CC=7 SCAR=40.3
Pod undocumented
31 0 my $self = shift;
32 0 ▶ return unless $self->path;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->path 0 0 0
33 0 $self->_clear_self();
34 0 ▶ if (my $resp = $self->get( $self->_mkuri($self->path) )) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $resp = $self->get($self->_mkuri($self->path))) 0 0 0
35 $self->{auth} = $resp->{auth}
36 0 ▶ if $resp->{auth};
Branch: 1 branch
BranchTrueFalseTotal
if $resp->{"auth"} 0 0 0
37 0 $self->{data} = $resp->{data}; # avoid tiggerng the trigger
38 $self->{lease_duration} = $resp->{lease_duration}
39 0 ▶ if $resp->{lease_duration};
Branch: 1 branch
BranchTrueFalseTotal
if $resp->{"lease_duration"} 0 0 0
40 $self->{lease_id} = $resp->{lease_id}
41 0 ▶ if $resp->{lease_id};
Branch: 1 branch
BranchTrueFalseTotal
if $resp->{"lease_id"} 0 0 0
42 $self->{renewable} = 0 + $resp->{renewable} # convert from JSON::Boolean
43 0 ▶ if $resp->{renewable};
Branch: 1 branch
BranchTrueFalseTotal
if $resp->{"renewable"} 0 0 0
44 }
45 }
46  
47  
48 0 ▶sub _clear_self {
Subroutine _clear_self: not called CC=3 SCAR=24.8
49 0 my $self = shift;
50 0 for my $k (qw/ auth data lease_duration lease_id renewable /) {
51 0 ▶ delete $self->{$k} if $self->{$k}
Branch: 1 branch
BranchTrueFalseTotal
if $self->{$k} 0 0 0
52 }
53 0 return 1
54 }
55  
56  
57 0 ▶sub delete {
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
58 0 my $self = shift;
59 0 my $result = $self->SUPER::delete( $self->_mkuri($self->path) );
60 0 $self->_clear_self();
61 0 return $result
62 }
63  
64 0 ▶sub _save {
Subroutine _save: not called CC=2 SCAR=17.9
65 0 my $self = shift;
66 0 my $data = shift;
67 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
68 if ref $data ne 'HASH';
69 0 return $self->post( $self->_mkuri($self->path), $data );
70 }
71  
72  
73 0 ▶sub list {
Subroutine list: not called CC=2 SCAR=17.9
Pod documented
74 0 my $self = shift;
75 0 ▶ my $result = $self->SUPER::list( $self->_mkuri($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
76 return $result->{data}
77 0 }
78  
79  
80 4 1;
81  
82 __END__
↑ Summary Vault/Secret/Generic.pm »