« blib/lib/Amazon/Credentials/Provider/Container.pm
↑ Summary
blib/lib/Amazon/Credentials/Role/File.pm »
| 1 | package Amazon::Credentials::Provider::Process; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 10 | ▶ | use 5.010; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 10 | ▶ | use parent qw(Amazon::Credentials::Provider); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 10 | __PACKAGE__->follow_best_practice; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 10 | __PACKAGE__->mk_accessors( | |||||||||||||||||||
| 13 | qw( | ||||||||||||||||||||
| 14 | process | ||||||||||||||||||||
| 15 | profile | ||||||||||||||||||||
| 16 | ) | ||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 10 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | 10 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | 10 | ▶ | use JSON; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | 10 | ▶ | use Role::Tiny::With; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 10 | with 'Amazon::Credentials::Role::File'; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | ######################################################################## | ||||||||||||||||||||
| 27 | 10 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||
| 28 | ######################################################################## | ||||||||||||||||||||
| 29 | 10 | my ( $class, @args ) = @_; | |||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 0 | ▶ | my $options = ref $args[0] ? { %{ $args[0] } } : {@args}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 10 | ▶ | my $profile = $options->{profile} || 'default'; | ||||||||||||||||||
|
Condition50%1/2
$options->{'profile'} || 'default'
MC/DC0%0/1
$options->{'profile'} || 'default'
$options->{'profile'}
Truth table50%1/2
A
A= $options->{'profile'}
| |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 10 | my $config = $class->_get_profile($profile); | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | return | ||||||||||||||||||||
| 38 | 10 | ▶ | if !$config; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 9 | my $process = $config->{credential_process}; | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | return | ||||||||||||||||||||
| 43 | 9 | ▶ | if !$process; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 8 | my $credentials = $class->_run_process($process); | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | my $self = $class->SUPER::new( | ||||||||||||||||||||
| 48 | aws_access_key_id => $credentials->{AccessKeyId}, | ||||||||||||||||||||
| 49 | aws_secret_access_key => $credentials->{SecretAccessKey}, | ||||||||||||||||||||
| 50 | expiration => $credentials->{Expiration}, | ||||||||||||||||||||
| 51 | region => $credentials->{Region} || $config->{region}, | ||||||||||||||||||||
| 52 | source => 'process', | ||||||||||||||||||||
| 53 | token => $credentials->{SessionToken}, | ||||||||||||||||||||
| 54 | 6 | ▶ | ); | ||||||||||||||||||
|
Condition100%3/3
$credentials->{'Region'} || $config->{'region'}
MC/DC100%2/2
$credentials->{'Region'} || $config->{'region'}
$credentials->{'Region'}
$config->{'region'}
Truth table100%3/3
A || B
A= $credentials->{'Region'}B= $config->{'region'}
| |||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 6 | $self->set_process($process); | |||||||||||||||||||
| 57 | 6 | $self->set_profile($profile); | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 6 | return $self; | |||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | ######################################################################## | ||||||||||||||||||||
| 63 | 9 | ▶ | sub _run_process { | ||||||||||||||||||
|
Subroutine
_run_process: called CC=7 SCAR=19.6
| |||||||||||||||||||||
| 64 | ######################################################################## | ||||||||||||||||||||
| 65 | 9 | my ( $self, $process ) = @_; | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 9 | my $credentials = eval { | |||||||||||||||||||
| 68 | 9 | ▶ | open my $fh, q{-|}, $process | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 69 | or croak "could not open pipe to $process\n$OS_ERROR"; | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 8 | local $RS = undef; | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 8 | my $credentials_str = <$fh>; | |||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 8 | ▶ | close $fh | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | or croak "could not close filehandle on $process\n"; | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 8 | return decode_json($credentials_str); | |||||||||||||||||||
| 79 | }; | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 9 | ▶ | croak "could not get credentials from process\n$EVAL_ERROR" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 82 | if $EVAL_ERROR; | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 8 | ▶ | croak 'credential process returned no credentials' | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 85 | if !ref $credentials; | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | croak 'credential process returned no AccessKeyId' | ||||||||||||||||||||
| 88 | 8 | ▶ | if !$credentials->{AccessKeyId}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | croak 'credential process returned no SecretAccessKey' | ||||||||||||||||||||
| 91 | 8 | ▶ | if !$credentials->{SecretAccessKey}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 7 | return $credentials; | |||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | ######################################################################## | ||||||||||||||||||||
| 97 | 1 | ▶ | sub is_refreshable { | ||||||||||||||||||
|
Subroutine
is_refreshable: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 98 | ######################################################################## | ||||||||||||||||||||
| 99 | 1 | return 1; | |||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | ######################################################################## | ||||||||||||||||||||
| 103 | 1 | ▶ | sub refresh_credentials { | ||||||||||||||||||
|
Subroutine
refresh_credentials: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 104 | ######################################################################## | ||||||||||||||||||||
| 105 | 1 | my ($self) = @_; | |||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | 1 | my $credentials = $self->_run_process( $self->get_process ); | |||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 1 | $self->set_aws_access_key_id( $credentials->{AccessKeyId} ); | |||||||||||||||||||
| 110 | 1 | $self->set_aws_secret_access_key( $credentials->{SecretAccessKey} ); | |||||||||||||||||||
| 111 | 1 | $self->set_token( $credentials->{SessionToken} ); | |||||||||||||||||||
| 112 | 1 | $self->set_expiration( $credentials->{Expiration} ); | |||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 1 | ▶ | if ( $credentials->{Region} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 115 | 0 | $self->set_region( $credentials->{Region} ); | |||||||||||||||||||
| 116 | } | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 1 | $self->set_last_refreshed(time); | |||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 1 | return $self; | |||||||||||||||||||
| 121 | } | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 10 | 1; | |||||||||||||||||||