| 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
| |||||||||||||||||||||
| 33 | 0 | $self->_clear_self(); | |||||||||||||||||||
| 34 | 0 | ▶ | if (my $resp = $self->get( $self->_mkuri($self->path) )) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | $self->{auth} = $resp->{auth} | ||||||||||||||||||||
| 36 | 0 | ▶ | if $resp->{auth}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 40 | $self->{lease_id} = $resp->{lease_id} | ||||||||||||||||||||
| 41 | 0 | ▶ | if $resp->{lease_id}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | $self->{renewable} = 0 + $resp->{renewable} # convert from JSON::Boolean | ||||||||||||||||||||
| 43 | 0 | ▶ | if $resp->{renewable}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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 || ()
MC/DC0%0/2
$self->path || ()
$self->path
()
Truth table0%0/3
A || B
A= $self->pathB= ()
| |||||||||||||||||||||
| 76 | return $result->{data} | ||||||||||||||||||||
| 77 | 0 | } | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 4 | 1; | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | __END__ | ||||||||||||||||||||