« blib/lib/Amazon/Credentials/Provider/WebIdentity.pm
↑ Summary
blib/lib/Amazon/Credentials/Provider/AssumeRole.pm »
| 1 | package Amazon::Credentials; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # - module for finding and providing AWS credentials | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 14 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 14 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 14 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 14 | ▶ | use parent qw( Exporter Class::Accessor::Fast ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 14 | __PACKAGE__->follow_best_practice; | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 14 | __PACKAGE__->mk_accessors( | |||||||||||||||||||||||||||||||||||||||||
| 15 | qw( | ||||||||||||||||||||||||||||||||||||||||||
| 16 | cache | ||||||||||||||||||||||||||||||||||||||||||
| 17 | debug | ||||||||||||||||||||||||||||||||||||||||||
| 18 | error | ||||||||||||||||||||||||||||||||||||||||||
| 19 | print_error | ||||||||||||||||||||||||||||||||||||||||||
| 20 | raise_error | ||||||||||||||||||||||||||||||||||||||||||
| 21 | imdsv2 | ||||||||||||||||||||||||||||||||||||||||||
| 22 | logger | ||||||||||||||||||||||||||||||||||||||||||
| 23 | order | ||||||||||||||||||||||||||||||||||||||||||
| 24 | plugins | ||||||||||||||||||||||||||||||||||||||||||
| 25 | profile | ||||||||||||||||||||||||||||||||||||||||||
| 26 | provider | ||||||||||||||||||||||||||||||||||||||||||
| 27 | region | ||||||||||||||||||||||||||||||||||||||||||
| 28 | source | ||||||||||||||||||||||||||||||||||||||||||
| 29 | timeout | ||||||||||||||||||||||||||||||||||||||||||
| 30 | user_agent | ||||||||||||||||||||||||||||||||||||||||||
| 31 | sso_account_id | ||||||||||||||||||||||||||||||||||||||||||
| 32 | sso_region | ||||||||||||||||||||||||||||||||||||||||||
| 33 | sso_role_name | ||||||||||||||||||||||||||||||||||||||||||
| 34 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 14 | ▶ | use Amazon::Credentials::HTTP::UserAgent; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 14 | ▶ | use Amazon::Credentials::HTTP::Response; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 14 | ▶ | use Amazon::Credentials::Utils qw(choose); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 14 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 14 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 14 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 14 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 14 | ▶ | use List::Util qw(any); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 14 | ▶ | use Scalar::Util qw(reftype blessed); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 14 | ▶ | use Time::Local qw(timegm_modern); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 14 | ▶ | use constant { ## no critic (ProhibitConstantPragma, Capitalization) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 14 | DEFAULT_TIMEOUT => 3, | |||||||||||||||||||||||||||||||||||||||||
| 51 | DEFAULT_WINDOW_INTERVAL => 5, | ||||||||||||||||||||||||||||||||||||||||||
| 52 | SECONDS_IN_MINUTE => 60, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | ISO8601_FORMAT => q{%Y-%m-%dT%H:%M:%S%z}, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | EMPTY => q{}, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | LOG_FORMAT => qq{ %s [%s] %s\n }, | ||||||||||||||||||||||||||||||||||||||||||
| 56 | SUCCESS => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | FALSE => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | TRUE => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 14 | }; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 14 | our $VERSION = '2.0.1'; ## no critic (RequireInterpolation) | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 14 | my %PROVIDERS; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 14 | my %PROVIDER_ALIASES = ( | |||||||||||||||||||||||||||||||||||||||||
| 66 | profile => 'file', | ||||||||||||||||||||||||||||||||||||||||||
| 67 | instance_role => 'role', | ||||||||||||||||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 14 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||
| 71 | get_role_credentials | ||||||||||||||||||||||||||||||||||||||||||
| 72 | normalize_arn | ||||||||||||||||||||||||||||||||||||||||||
| 73 | set_sso_credentials | ||||||||||||||||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | # we only log at debug level, create a default logger | ||||||||||||||||||||||||||||||||||||||||||
| 77 | { | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 14 | ▶ | no strict 'refs'; ## no critic (ProhibitNoStrict) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 14 | ▶ | *{'Amazon::Credentials::Logger::debug'} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 24 | my ( $self, @message ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 24 | ▶ | return if !$self->{debug}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | my $timestamp = scalar localtime; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | foreach my $message (@message) { | |||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | ▶ | if ( ref $message eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | $message = $message->(); | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | my $message = sprintf LOG_FORMAT, $timestamp, $PROCESS_ID, @message; | |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | print {*STDERR} $message; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 14 | }; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 14 | ▶ | caller or __PACKAGE__->main(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 25 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=25.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 25 | my ( $class, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 25 | ▶ | my $options = ref $args[0] ? $args[0] : {@args}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 25 | my $self = $class->SUPER::new($options); | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 25 | $self->_set_defaults; | |||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 25 | $self->_init_logger; | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 25 | $self->_init_credentials($options); | |||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | return $self | ||||||||||||||||||||||||||||||||||||||||||
| 116 | if $options->{aws_access_key_id} | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 25 | ▶ | && $options->{aws_secret_access_key}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$options->{"aws_access_key_id"} and $options->{"aws_secret_access_key"}
MC/DC50%1/2
$options->{"aws_access_key_id"} and $options->{"aws_secret_access_key"}
$options->{"aws_access_key_id"}
$options->{"aws_secret_access_key"}
Truth table66%2/3
A and B
A= $options->{"aws_access_key_id"}B= $options->{"aws_secret_access_key"}
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 21 | ▶ | if ( $self->get_sso_role_name && $self->get_sso_account_id ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->get_sso_role_name and $self->get_sso_account_id
MC/DC50%1/2
$self->get_sso_role_name and $self->get_sso_account_id
$self->get_sso_role_name
$self->get_sso_account_id
Truth table66%2/3
A and B
A= $self->get_sso_role_nameB= $self->get_sso_account_id
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | require Amazon::Credentials::Provider::SSO; | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | my $provider = Amazon::Credentials::Provider::SSO->new( | |||||||||||||||||||||||||||||||||||||||||
| 124 | sso_role_name => $self->get_sso_role_name, | ||||||||||||||||||||||||||||||||||||||||||
| 125 | sso_account_id => $self->get_sso_account_id, | ||||||||||||||||||||||||||||||||||||||||||
| 126 | sso_region => $self->get_sso_region, | ||||||||||||||||||||||||||||||||||||||||||
| 127 | region => $self->get_region, | ||||||||||||||||||||||||||||||||||||||||||
| 128 | user_agent => $self->get_user_agent, | ||||||||||||||||||||||||||||||||||||||||||
| 129 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | ▶ | croak 'could not resolve SSO credentials' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | if !$provider; | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | $self->set_provider($provider); | |||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | $self->set_credentials( $provider->credentials ); | |||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | ▶ | $self->set_region( $provider->get_region ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | if defined $provider->get_region; | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | ▶ | $self->set_source( $provider->get_source ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | if defined $provider->get_source; | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 20 | $self->_init_plugins; | |||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 20 | my $result = eval { | |||||||||||||||||||||||||||||||||||||||||
| 149 | 20 | $self->_resolve_credentials; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 11 | return TRUE; | |||||||||||||||||||||||||||||||||||||||||
| 151 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 20 | ▶ | if ( !$result ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 9 | my $error = $EVAL_ERROR; | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 9 | $self->set_error($error); | |||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 9 | ▶ | croak $error | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | if $self->get_raise_error; | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 3 | ▶ | carp $error | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | if $self->get_print_error; | ||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 14 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 100 | ▶ | sub register_provider { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register_provider: called CC=7 SCAR=19.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 100 | my ( $class, $provider_class ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 100 | ▶ | croak 'provider class is required' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | if !$provider_class; | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 100 | ▶ | croak "invalid provider class '$provider_class'" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | if $provider_class !~ /\A[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*\z/xsm; | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 100 | my $module = $provider_class; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 100 | $module =~ s{::}{/}gxsm; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 100 | $module .= '.pm'; | |||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 100 | ▶ | eval { require $module; 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | or croak "could not load provider $provider_class: $EVAL_ERROR"; | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 100 | my ($name) = $provider_class =~ /([^:]+)\z/xsm; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 100 | $name = _to_snake_case($name); | |||||||||||||||||||||||||||||||||||||||||
| 188 | 100 | ▶ | $name = $PROVIDER_ALIASES{$name} // $name; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$PROVIDER_ALIASES{$name} // $name
MC/DC0%0/2
$PROVIDER_ALIASES{$name} // $name
$PROVIDER_ALIASES{$name}
$name
Truth table66%2/3
A // B
A= $PROVIDER_ALIASES{$name}B= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 100 | ▶ | if ( exists $PROVIDERS{$name} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | croak "provider '$name' is already registered by $PROVIDERS{$name}" | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 60 | ▶ | if $PROVIDERS{$name} ne $provider_class; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 60 | return $class; | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 40 | $PROVIDERS{$name} = $provider_class; | |||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 40 | return $class; | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 23 | ▶ | sub _plugin_order { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_plugin_order: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 23 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 23 | my @DEFAULT_ORDER = qw( | |||||||||||||||||||||||||||||||||||||||||
| 208 | env | ||||||||||||||||||||||||||||||||||||||||||
| 209 | container | ||||||||||||||||||||||||||||||||||||||||||
| 210 | role | ||||||||||||||||||||||||||||||||||||||||||
| 211 | web_identity | ||||||||||||||||||||||||||||||||||||||||||
| 212 | file | ||||||||||||||||||||||||||||||||||||||||||
| 213 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 23 | ▶ | my $order = choose { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 23 | ▶ | return $self->get_order | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | if defined $self->get_order; | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 10 | ▶ | return $self->get_plugins | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | if defined $self->get_plugins; | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 6 | ▶ | return ['file'] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | if defined $self->get_profile; | ||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | return \@DEFAULT_ORDER; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 23 | }; | |||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 23 | ▶ | $order = [$order] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | if !ref $order; | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 23 | ▶ | croak 'order must be an array reference' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | if reftype($order) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 22 | my @order; | |||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 22 | foreach my $name ( @{$order} ) { | |||||||||||||||||||||||||||||||||||||||||
| 237 | 23 | $name = $self->_normalize_plugin_name($name); | |||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | croak "unknown credentials plugin '$name'" | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 23 | ▶ | if !exists $PROVIDERS{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 22 | push @order, $name; | |||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 21 | ▶ | if ( defined $self->get_plugins ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 5 | my %enabled = map { $_ => TRUE } @{ $self->get_plugins }; | |||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 5 | foreach my $name (@order) { | |||||||||||||||||||||||||||||||||||||||||
| 249 | croak "credentials plugin '$name' is not enabled" | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 5 | ▶ | if !$enabled{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 20 | return \@order; | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 20 | ▶ | sub _resolve_credentials { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_credentials: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 20 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 20 | my $order = $self->_plugin_order; | |||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 17 | my %options = ( | |||||||||||||||||||||||||||||||||||||||||
| 265 | debug => $self->get_debug, | ||||||||||||||||||||||||||||||||||||||||||
| 266 | logger => $self->get_logger, | ||||||||||||||||||||||||||||||||||||||||||
| 267 | profile => $self->get_profile, | ||||||||||||||||||||||||||||||||||||||||||
| 268 | region => $self->get_region, | ||||||||||||||||||||||||||||||||||||||||||
| 269 | timeout => $self->get_timeout, | ||||||||||||||||||||||||||||||||||||||||||
| 270 | user_agent => $self->get_user_agent, | ||||||||||||||||||||||||||||||||||||||||||
| 271 | imdsv2 => $self->get_imdsv2, | ||||||||||||||||||||||||||||||||||||||||||
| 272 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 17 | foreach my $name ( @{$order} ) { | |||||||||||||||||||||||||||||||||||||||||
| 275 | 17 | my $class = $PROVIDERS{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | 17 | ▶ | croak | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | sprintf( "credentials plugin '%s' is not registered; available plugins: %s", $name, join q{, }, sort keys %PROVIDERS, ) | ||||||||||||||||||||||||||||||||||||||||||
| 279 | if !$class; | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 17 | ▶ | croak "credentials plugin '$name' is not registered" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | if !$class; | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 17 | my $plugin = $class->new( \%options ); | |||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | next | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 17 | ▶ | if !$plugin; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 16 | ▶ | my $provider = $name eq 'file' ? $plugin->resolve( $self->get_profile ) : $plugin; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | next | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 15 | ▶ | if !$provider; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 11 | $self->set_provider($provider); | |||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 11 | my $credentials = $provider->credentials; | |||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 11 | $self->set_credentials($credentials); | |||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 11 | ▶ | if ( defined $credentials->{region} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 6 | $self->set_region( $credentials->{region} ); | |||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | $self->set_source( $credentials->{source} ) | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 11 | ▶ | if defined $credentials->{source}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 11 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 5 | croak 'no credentials available'; | |||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 3 | ▶ | sub is_token_expired { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_token_expired: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 3 | my ( $self, $window_interval ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | 3 | ▶ | $window_interval //= DEFAULT_WINDOW_INTERVAL; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$window_interval //= 5
MC/DC0%0/1
$window_interval //= 5
$window_interval
Truth table50%1/2
A
A= $window_interval
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | 3 | my $expiration = $self->get_expiration; | |||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 3 | ▶ | return FALSE | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | if !defined $expiration; | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | 3 | my $expiration_time = _iso8601_to_time($expiration); | |||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 3 | $expiration_time -= $window_interval * SECONDS_IN_MINUTE; | |||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 3 | ▶ | return $expiration_time < time | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | ? TRUE | ||||||||||||||||||||||||||||||||||||||||||
| 331 | : FALSE; | ||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 335 | 3 | ▶ | sub set_expiration { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_expiration: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 3 | my ( $self, $expiration ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | 3 | my $provider = $self->get_provider; | |||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | return | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 3 | ▶ | if !$provider; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 3 | $provider->set_expiration($expiration); | |||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||
| 348 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 349 | 3 | ▶ | sub _iso8601_to_time { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_iso8601_to_time: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 3 | my $iso8601 = shift; | |||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | 3 | $iso8601 =~ s/^(.*)Z$/$1\+00:00/xsm; | |||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 3 | require POSIX::strptime; | |||||||||||||||||||||||||||||||||||||||||
| 356 | 3 | POSIX::strptime->import('strptime'); | |||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | 3 | require Time::Local; | |||||||||||||||||||||||||||||||||||||||||
| 359 | 3 | Time::Local->import('timegm'); | |||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 3 | my $gmtime = eval { | |||||||||||||||||||||||||||||||||||||||||
| 362 | 3 | local $ENV{TZ} = 'GMT'; | |||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | 3 | timegm( strptime( $iso8601, ISO8601_FORMAT ) ); | |||||||||||||||||||||||||||||||||||||||||
| 365 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | 3 | return $gmtime; | |||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 1 | ▶ | sub refresh_token { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
refresh_token: called CC=3 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | 1 | my $provider = $self->get_provider; | |||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | 1 | ▶ | croak 'credentials are not refreshable' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$provider and $provider->is_refreshable
MC/DC0%0/2
$provider and $provider->is_refreshable
$provider
$provider->is_refreshable
Truth table33%1/3
A and B
A= $providerB= $provider->is_refreshable
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | if !$provider || !$provider->is_refreshable; | ||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | 1 | $provider->refresh_credentials; | |||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | 1 | $self->set_credentials( $provider->credentials ); | |||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 3 | ▶ | sub get_expiration { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_expiration: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 390 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 3 | my $provider = $self->get_provider; | |||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | return | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 3 | ▶ | if !$provider; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | 3 | return $provider->get_expiration; | |||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 401 | 20 | ▶ | sub _init_plugins { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init_plugins: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 403 | 20 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 20 | foreach my $class ( | |||||||||||||||||||||||||||||||||||||||||
| 406 | qw( | ||||||||||||||||||||||||||||||||||||||||||
| 407 | Amazon::Credentials::Provider::Env | ||||||||||||||||||||||||||||||||||||||||||
| 408 | Amazon::Credentials::Provider::Container | ||||||||||||||||||||||||||||||||||||||||||
| 409 | Amazon::Credentials::Provider::InstanceRole | ||||||||||||||||||||||||||||||||||||||||||
| 410 | Amazon::Credentials::Provider::WebIdentity | ||||||||||||||||||||||||||||||||||||||||||
| 411 | Amazon::Credentials::Resolver::Profile | ||||||||||||||||||||||||||||||||||||||||||
| 412 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 413 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 414 | 100 | $self->register_provider($class); | |||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | 20 | my $plugins = $self->get_plugins; | |||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 20 | ▶ | return $self | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | if !defined $plugins; | ||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | 3 | ▶ | croak 'plugins must be an array reference' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | if reftype($plugins) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | 3 | my @plugins; | |||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 3 | foreach my $name ( @{$plugins} ) { | |||||||||||||||||||||||||||||||||||||||||
| 428 | 3 | $name = $self->_normalize_plugin_name($name); | |||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | croak "unknown credentials plugin '$name'" | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 3 | ▶ | if !exists $PROVIDERS{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 3 | push @plugins, $name; | |||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | 3 | $self->set_plugins( \@plugins ); | |||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 442 | 26 | ▶ | sub _normalize_plugin_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_normalize_plugin_name: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 444 | 26 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | 26 | ▶ | return $PROVIDER_ALIASES{$name} // $name; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$PROVIDER_ALIASES{$name} // $name
MC/DC0%0/2
$PROVIDER_ALIASES{$name} // $name
$PROVIDER_ALIASES{$name}
$name
Truth table33%1/3
A // B
A= $PROVIDER_ALIASES{$name}B= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 450 | 100 | ▶ | sub _to_snake_case { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_to_snake_case: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 452 | 100 | my ($str) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||
| 454 | 100 | ▶ | return q{} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | if !defined $str; | ||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | 100 | $str =~ s/([[:upper:]]+)([[:upper:]][[:lower:]])/$1_$2/xsmg; | |||||||||||||||||||||||||||||||||||||||||
| 458 | 100 | $str =~ s/([[:lower:]\d])([[:upper:]])/$1_$2/xsmg; | |||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 100 | return lc $str; | |||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | # New method replaces _init_encryption, set_aws_access_key_id, | ||||||||||||||||||||||||||||||||||||||||||
| 464 | # set_aws_secret_access_key, set_token, and all of _crypt/_fetch_passkey etc. | ||||||||||||||||||||||||||||||||||||||||||
| 465 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 466 | 25 | ▶ | sub _init_credentials { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init_credentials: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 468 | 25 | my ( $self, $options ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 469 | 25 | ▶ | $options //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$options //= {}
MC/DC0%0/1
$options //= {}
$options
Truth table50%1/2
A
A= $options
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | 25 | my ( $key_id, $secret, $token ) = @{$options}{qw( aws_access_key_id aws_secret_access_key token )}; | |||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | $self->{_access_key_id} = sub {$key_id}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | 25 | ▶ | $self->{_secret_access_key} = sub {$secret}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | $self->{_session_token} = sub {$token}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | 25 | return; | |||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | 11 | ▶ | sub get_aws_access_key_id { return $_[0]->_get_credential('_access_key_id') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_aws_access_key_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | 7 | ▶ | sub get_aws_secret_access_key { return $_[0]->_get_credential('_secret_access_key') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_aws_secret_access_key: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | 5 | ▶ | sub get_token { return $_[0]->_get_credential('_session_token') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_token: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 485 | 23 | ▶ | sub _get_credential { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_credential: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 487 | 23 | my ( $self, $slot ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | 23 | my $value = $self->{$slot}->(); | |||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | 23 | ▶ | return $value | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | if $self->get_cache; | ||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | ▶ | $self->{$slot} = sub {undef}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 500 | 13 | ▶ | sub set_aws_access_key_id { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_aws_access_key_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 501 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 502 | 13 | my ( $self, $val ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | 13 | ▶ | $self->{_access_key_id} = sub {$val}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | 13 | return; | |||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 510 | 13 | ▶ | sub set_aws_secret_access_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_aws_secret_access_key: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 511 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 512 | 13 | my ( $self, $val ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||
| 514 | 13 | ▶ | $self->{_secret_access_key} = sub {$val}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||
| 516 | 13 | return; | |||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 520 | 13 | ▶ | sub set_token { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_token: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 522 | 13 | my ( $self, $val ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | 13 | ▶ | $self->{_session_token} = sub {$val}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 525 | 13 | return; | |||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 529 | 24 | ▶ | sub set_default_logger { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_default_logger: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 530 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 531 | 24 | my ( $self, $debug ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | 24 | ▶ | $debug = $debug // $self->get_debug; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$debug // $self->get_debug
MC/DC0%0/2
$debug // $self->get_debug
$debug
$self->get_debug
Truth table33%1/3
A // B
A= $debugB= $self->get_debug
| |||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | 24 | my $logger = bless { debug => $debug }, 'Amazon::Credentials::Logger'; | |||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||
| 537 | 24 | $self->set_logger($logger); | |||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | 24 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | ▶ | sub reset_credentials { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset_credentials: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 544 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | $self->_init_credentials; | |||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||
| 552 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 553 | 13 | ▶ | sub set_credentials { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_credentials: called CC=5 SCAR=17.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 554 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 555 | 13 | my ( $self, $creds ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | 13 | ▶ | $creds //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$creds //= {}
MC/DC0%0/1
$creds //= {}
$creds
Truth table50%1/2
A
A= $creds
| |||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | croak 'no credentials available' | ||||||||||||||||||||||||||||||||||||||||||
| 560 | 13 | ▶ | if !$creds->{aws_secret_access_key} || !$creds->{aws_access_key_id}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$creds->{"aws_secret_access_key"} and $creds->{"aws_access_key_id"}
MC/DC0%0/2
$creds->{"aws_secret_access_key"} and $creds->{"aws_access_key_id"}
$creds->{"aws_secret_access_key"}
$creds->{"aws_access_key_id"}
Truth table33%1/3
A and B
A= $creds->{"aws_secret_access_key"}B= $creds->{"aws_access_key_id"}
| |||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||
| 562 | 13 | $self->set_aws_secret_access_key( $creds->{aws_secret_access_key} ); | |||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||
| 564 | 13 | $self->set_aws_access_key_id( $creds->{aws_access_key_id} ); | |||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||
| 566 | 13 | ▶ | $self->set_token( $creds->{token} || $creds->{aws_session_token} ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$creds->{'token'} || $creds->{'aws_session_token'}
MC/DC50%1/2
$creds->{'token'} || $creds->{'aws_session_token'}
$creds->{'token'}
$creds->{'aws_session_token'}
Truth table66%2/3
A || B
A= $creds->{'token'}B= $creds->{'aws_session_token'}
| |||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||
| 568 | 13 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||
| 571 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | ▶ | sub normalize_arn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_arn: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 573 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | ▶ | my $arn = ( @_ == 2 ) ? $_[1] : $_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | ▶ | if ( $arn =~ m{arn:aws:sts::(\d+):assumed-role/([^/]+)/}xsm ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | return "arn:aws:iam::$1:role/$2"; | |||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | return $arn; | |||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||
| 583 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 584 | 4 | ▶ | sub credential_keys { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
credential_keys: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 585 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 586 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||
| 588 | 4 | my %credential_keys = ( | |||||||||||||||||||||||||||||||||||||||||
| 589 | AWS_ACCESS_KEY_ID => $self->get_aws_access_key_id, | ||||||||||||||||||||||||||||||||||||||||||
| 590 | AWS_SECRET_ACCESS_KEY => $self->get_aws_secret_access_key, | ||||||||||||||||||||||||||||||||||||||||||
| 591 | AWS_SESSION_TOKEN => $self->get_token, | ||||||||||||||||||||||||||||||||||||||||||
| 592 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||
| 594 | 4 | ▶ | if ( !defined $credential_keys{AWS_SESSION_TOKEN} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 595 | 3 | delete $credential_keys{AWS_SESSION_TOKEN}; | |||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||
| 598 | 4 | return \%credential_keys; | |||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||
| 601 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 602 | 1 | ▶ | sub as_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 603 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 604 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||
| 606 | 1 | return JSON->new->pretty->encode( $self->credential_keys ); | |||||||||||||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 610 | 1 | ▶ | sub format_credentials { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_credentials: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 611 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 612 | 1 | my ( $self, $format ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||
| 614 | 1 | ▶ | $format = $format || "%s %s\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$format || "%s %s\n"
MC/DC0%0/1
$format || "%s %s\n"
$format
Truth table50%1/2
A
A= $format
| |||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||
| 616 | 1 | my $credential_keys = $self->credential_keys; | |||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||
| 618 | 2 | ▶ | return join EMPTY, map { sprintf $format, $_, $credential_keys->{$_} // EMPTY } | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$credential_keys->{$_} // ""
MC/DC0%0/1
$credential_keys->{$_} // ""
$credential_keys->{$_}
Truth table50%1/2
A
A= $credential_keys->{$_}
| |||||||||||||||||||||||||||||||||||||||||||
| 619 | 1 | keys %{$credential_keys}; | |||||||||||||||||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||
| 622 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | ▶ | sub set_aws_session_token { goto &set_token; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_aws_session_token: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | sub get_aws_session_token { goto &get_token; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_aws_session_token: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 625 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||
| 627 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | ▶ | sub set_sso_credentials { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_sso_credentials: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 629 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | my ( $role_name, $account_id, $region ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | ▶ | croak "usage: Amazon::Credentials::set_sso_credentials(role-name, account-id)\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 633 | if ref $role_name; | ||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | my $credentials = get_role_credentials( | |||||||||||||||||||||||||||||||||||||||||
| 636 | role_name => $role_name, | ||||||||||||||||||||||||||||||||||||||||||
| 637 | account_id => $account_id, | ||||||||||||||||||||||||||||||||||||||||||
| 638 | region => $region, | ||||||||||||||||||||||||||||||||||||||||||
| 639 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | ▶ | if ($credentials) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | $ENV{AWS_ACCESS_KEY_ID} = $credentials->{accessKeyId}; | |||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | $ENV{AWS_SECRET_ACCESS_KEY} = $credentials->{secretAccessKey}; | |||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | $ENV{AWS_SESSION_TOKEN} = $credentials->{sessionToken}; | |||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | return $credentials; | |||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||
| 652 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | ▶ | sub get_role_credentials { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_role_credentials: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 654 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | require Amazon::Credentials::Provider::SSO; | |||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | return Amazon::Credentials::Provider::SSO->get_role_credentials(@_); | |||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||
| 660 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 661 | 25 | ▶ | sub _init_logger { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init_logger: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 662 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 663 | 25 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||
| 665 | 25 | ▶ | if ( !$self->get_logger || !ref $self->get_logger ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->get_logger and ref $self->get_logger
MC/DC50%1/2
$self->get_logger and ref $self->get_logger
$self->get_logger
ref $self->get_logger
Truth table66%2/3
A and B
A= $self->get_loggerB= ref $self->get_logger
| |||||||||||||||||||||||||||||||||||||||||||
| 666 | 24 | $self->set_default_logger; | |||||||||||||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||
| 669 | 25 | ▶ | $self->get_logger->debug( sub { return sprintf 'using %s logger', ref $self->get_logger } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||
| 671 | 25 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||
| 674 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 675 | 25 | ▶ | sub _set_defaults { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_defaults: called CC=8 SCAR=22.6
| |||||||||||||||||||||||||||||||||||||||||||
| 676 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 677 | 25 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||
| 679 | 25 | ▶ | $self->set_debug( $self->get_debug // FALSE ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->get_debug // 0
MC/DC100%1/1
$self->get_debug // 0
$self->get_debug
Truth table100%2/2
A
A= $self->get_debug
| |||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||
| 681 | 25 | ▶ | $self->set_cache( defined $self->get_cache ? $self->get_cache : TRUE ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||
| 683 | 25 | ▶ | my $timeout = $self->get_timeout // DEFAULT_TIMEOUT; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->get_timeout // 3
MC/DC0%0/1
$self->get_timeout // 3
$self->get_timeout
Truth table50%1/2
A
A= $self->get_timeout
| |||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||
| 685 | 25 | ▶ | if ( !$self->get_user_agent ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 686 | 24 | $self->set_user_agent( Amazon::Credentials::HTTP::UserAgent->new( timeout => $timeout ) ); | |||||||||||||||||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||
| 689 | 25 | ▶ | if ( !$self->get_profile ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 690 | 17 | $self->set_profile( $ENV{AWS_PROFILE} ); | |||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||
| 693 | $self->set_raise_error( | ||||||||||||||||||||||||||||||||||||||||||
| 694 | 25 | ▶ | defined $self->get_raise_error | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 695 | ? $self->get_raise_error | ||||||||||||||||||||||||||||||||||||||||||
| 696 | : TRUE | ||||||||||||||||||||||||||||||||||||||||||
| 697 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||
| 699 | 25 | ▶ | $self->set_print_error( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 700 | defined $self->get_print_error | ||||||||||||||||||||||||||||||||||||||||||
| 701 | ? $self->get_print_error | ||||||||||||||||||||||||||||||||||||||||||
| 702 | : TRUE | ||||||||||||||||||||||||||||||||||||||||||
| 703 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||
| 705 | 25 | ▶ | my $imdsv2 = choose { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=25.5
| |||||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||
| 707 | 25 | ▶ | return 'preferred' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 708 | if !defined $self->get_imdsv2; | ||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||
| 710 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 => 'disabled', | ||||||||||||||||||||||||||||||||||||||||||
| 712 | 1 => 'required', | ||||||||||||||||||||||||||||||||||||||||||
| 713 | 0 | ▶ | }->{ $self->get_imdsv2 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 714 | if $self->get_imdsv2 =~ /^[01]$/xsm; | ||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||
| 716 | return $self->get_imdsv2 | ||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | ▶ | if any { $_ eq $self->get_imdsv2 } qw(required preferred disabled); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | croak sprintf "invalid imdsv2 mode '%s'", $self->get_imdsv2; | |||||||||||||||||||||||||||||||||||||||||
| 720 | 25 | }; | |||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||
| 722 | 25 | $self->set_imdsv2($imdsv2); | |||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||
| 724 | 25 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||
| 727 | ####################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | ▶ | sub help { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
help: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 729 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 730 | 0 | my ($options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | ▶ | if ( !$options->{version} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | print {*STDOUT} <<'END_OF_USAGE'; | |||||||||||||||||||||||||||||||||||||||||
| 735 | amazon-credentials options | ||||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||
| 737 | Formats credentials found in env, config, SSO, role | ||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||
| 739 | Options | ||||||||||||||||||||||||||||||||||||||||||
| 740 | ------- | ||||||||||||||||||||||||||||||||||||||||||
| 741 | --account, -a use with --role, specify AWS account id | ||||||||||||||||||||||||||||||||||||||||||
| 742 | --container, -c get credentials from container IAM role | ||||||||||||||||||||||||||||||||||||||||||
| 743 | --ec2, -E get credentials from EC2 IAM role | ||||||||||||||||||||||||||||||||||||||||||
| 744 | --env -e get credentials from environment variables | ||||||||||||||||||||||||||||||||||||||||||
| 745 | --help, -h this | ||||||||||||||||||||||||||||||||||||||||||
| 746 | --profile, -p get credentials from profile in credentials configuration | ||||||||||||||||||||||||||||||||||||||||||
| 747 | --role, -r get credentials from SSO role | ||||||||||||||||||||||||||||||||||||||||||
| 748 | --token, -t MFA token for MFA enabled profiles | ||||||||||||||||||||||||||||||||||||||||||
| 749 | --version, -v version | ||||||||||||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||||||||||
| 751 | $ amazon-credentials --profile=test | ||||||||||||||||||||||||||||||||||||||||||
| 752 | export AWS_ACCESS_KEY_ID=AKI***************** | ||||||||||||||||||||||||||||||||||||||||||
| 753 | export AWS_SECRET_ACCESS_KEY=**************************************** | ||||||||||||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||||||||||||
| 755 | $ aws sso login | ||||||||||||||||||||||||||||||||||||||||||
| 756 | $ amazon-credentials --role my-sso-role --account 01234567890 | ||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||
| 758 | END_OF_USAGE | ||||||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||
| 761 | 0 | print {*STDOUT} "v$VERSION\n"; | |||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | exit SUCCESS; | |||||||||||||||||||||||||||||||||||||||||
| 764 | } | ||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||
| 766 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 767 | 1 | ▶ | sub export_credentials { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
export_credentials: called CC=5 SCAR=16.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 768 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 769 | 1 | my ($credentials) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||||||||||||
| 771 | 1 | ▶ | $credentials //= \%ENV; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$credentials //= \%ENV
MC/DC0%0/1
$credentials //= \%ENV
$credentials
Truth table50%1/2
A
A= $credentials
| |||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||
| 773 | # Accept either the AWS_* environment-variable shape (e.g. %ENV, or a | ||||||||||||||||||||||||||||||||||||||||||
| 774 | # credentials object) or the camelCase 'roleCredentials' shape returned | ||||||||||||||||||||||||||||||||||||||||||
| 775 | # by the SSO GetRoleCredentials call (accessKeyId/secretAccessKey/ | ||||||||||||||||||||||||||||||||||||||||||
| 776 | # sessionToken). set_sso_credentials() returns the latter, so map each | ||||||||||||||||||||||||||||||||||||||||||
| 777 | # export name to whichever key is present. | ||||||||||||||||||||||||||||||||||||||||||
| 778 | 1 | my %sso_key_for = ( | |||||||||||||||||||||||||||||||||||||||||
| 779 | AWS_ACCESS_KEY_ID => 'accessKeyId', | ||||||||||||||||||||||||||||||||||||||||||
| 780 | AWS_SECRET_ACCESS_KEY => 'secretAccessKey', | ||||||||||||||||||||||||||||||||||||||||||
| 781 | AWS_SESSION_TOKEN => 'sessionToken', | ||||||||||||||||||||||||||||||||||||||||||
| 782 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||
| 784 | 1 | my @lines; | |||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||
| 786 | 1 | foreach my $env_key (qw(AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN)) { | |||||||||||||||||||||||||||||||||||||||||
| 787 | 3 | ▶ | my $value = $credentials->{$env_key} // $credentials->{ $sso_key_for{$env_key} }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$credentials->{$env_key} // $$credentials{$sso_key_for{$env_key}}
MC/DC0%0/2
$credentials->{$env_key} // $$credentials{$sso_key_for{$env_key}}
$credentials->{$env_key}
$$credentials{$sso_key_for{$env_key}}
Truth table33%1/3
A // B
A= $credentials->{$env_key}B= $$credentials{$sso_key_for{$env_key}}
| |||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||
| 789 | next | ||||||||||||||||||||||||||||||||||||||||||
| 790 | 3 | ▶ | if !defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||||||||
| 792 | 3 | push @lines, sprintf "export %s=%s\n", $env_key, $value; | |||||||||||||||||||||||||||||||||||||||||
| 793 | } | ||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||
| 795 | 1 | return join EMPTY, @lines; | |||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||
| 798 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 799 | 0 | ▶ | sub main { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
main: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 800 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 801 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||||||||
| 803 | 0 | require Getopt::Long; | |||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | Getopt::Long->import(qw(:config no_ignore_case)); | |||||||||||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||||||||||||
| 807 | 0 | my %options; | |||||||||||||||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||||||||||||||||
| 809 | 0 | my @option_specs = qw( | |||||||||||||||||||||||||||||||||||||||||
| 810 | account|a=s | ||||||||||||||||||||||||||||||||||||||||||
| 811 | container|c | ||||||||||||||||||||||||||||||||||||||||||
| 812 | ec2|E | ||||||||||||||||||||||||||||||||||||||||||
| 813 | env|e | ||||||||||||||||||||||||||||||||||||||||||
| 814 | help|h | ||||||||||||||||||||||||||||||||||||||||||
| 815 | profile|p=s | ||||||||||||||||||||||||||||||||||||||||||
| 816 | role|r=s | ||||||||||||||||||||||||||||||||||||||||||
| 817 | token|t=s | ||||||||||||||||||||||||||||||||||||||||||
| 818 | version|v | ||||||||||||||||||||||||||||||||||||||||||
| 819 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||
| 821 | 0 | ▶ | if ( !GetOptions( \%options, @option_specs ) || $options{help} || $options{version} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not GetOptions(\%options, @option_specs) or $options{"help"} or $options{"version"}
not GetOptions(\%options, @option_specs) or $options{"help"}
MC/DC0%0/3
not GetOptions(\%options, @option_specs) or $options{"help"} or $options{"version"}
not GetOptions(\%options, @option_specs)
$options{"help"}
$options{"version"}
Truth table0%0/4
not(A) or B or C
A= not GetOptions(\%options, @option_specs)B= $options{"help"}C= $options{"version"}
| |||||||||||||||||||||||||||||||||||||||||||
| 822 | 0 | help( \%options ); | |||||||||||||||||||||||||||||||||||||||||
| 823 | } | ||||||||||||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||||||||||||
| 825 | local $ENV{AMAZON_CREDENTIALS_MFA_TOKEN} = $options{token} | ||||||||||||||||||||||||||||||||||||||||||
| 826 | 0 | ▶ | if $options{token}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||||||||||||
| 828 | 0 | ▶ | my $creds = $self->new( profile => $options{profile} // EMPTY, ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$options{"profile"} // ""
MC/DC0%0/1
$options{"profile"} // ""
$options{"profile"}
Truth table0%0/2
A
A= $options{"profile"}
| |||||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||
| 830 | 0 | print {*STDOUT} $creds->format_credentials("export %s=%s\n"); | |||||||||||||||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||||||||||||||||
| 832 | 0 | exit SUCCESS; | |||||||||||||||||||||||||||||||||||||||||
| 833 | } | ||||||||||||||||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||||||||||||||||
| 835 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 836 | 17 | ▶ | sub sanitize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sanitize: called CC=21 SCAR=30.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 837 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 838 | 17 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||||||||||
| 840 | 17 | my %sensitive = map { lc $_ => TRUE } qw( | |||||||||||||||||||||||||||||||||||||||||
| 841 | authorization | ||||||||||||||||||||||||||||||||||||||||||
| 842 | aws_access_key_id | ||||||||||||||||||||||||||||||||||||||||||
| 843 | aws_secret_access_key | ||||||||||||||||||||||||||||||||||||||||||
| 844 | aws_session_token | ||||||||||||||||||||||||||||||||||||||||||
| 845 | accesskeyid | ||||||||||||||||||||||||||||||||||||||||||
| 846 | secretaccesskey | ||||||||||||||||||||||||||||||||||||||||||
| 847 | sessiontoken | ||||||||||||||||||||||||||||||||||||||||||
| 848 | token | ||||||||||||||||||||||||||||||||||||||||||
| 849 | accesstoken | ||||||||||||||||||||||||||||||||||||||||||
| 850 | refreshtoken | ||||||||||||||||||||||||||||||||||||||||||
| 851 | clientsecret | ||||||||||||||||||||||||||||||||||||||||||
| 852 | webidentitytoken | ||||||||||||||||||||||||||||||||||||||||||
| 853 | x-amz-security-token | ||||||||||||||||||||||||||||||||||||||||||
| 854 | x-amz-sso_bearer_token | ||||||||||||||||||||||||||||||||||||||||||
| 855 | x-aws-ec2-metadata-token | ||||||||||||||||||||||||||||||||||||||||||
| 856 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||||||||||||||||
| 858 | 17 | ▶ | if ( blessed($value) && $value->isa('HTTP::Request') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($value) and $value->isa("HTTP::Request")
MC/DC100%2/2
builtin::blessed($value) and $value->isa("HTTP::Request")
builtin::blessed($value)
$value->isa("HTTP::Request")
Truth table100%3/3
A and B
A= builtin::blessed($value)B= $value->isa("HTTP::Request")
| |||||||||||||||||||||||||||||||||||||||||||
| 859 | 1 | my $request = $value->clone; | |||||||||||||||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||||||||||||||||
| 861 | 1 | foreach my $header_name ( $request->header_field_names ) { | |||||||||||||||||||||||||||||||||||||||||
| 862 | next | ||||||||||||||||||||||||||||||||||||||||||
| 863 | 3 | ▶ | if !$sensitive{ lc $header_name }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 864 | |||||||||||||||||||||||||||||||||||||||||||
| 865 | 2 | $request->header( $header_name => '[REDACTED]' ); | |||||||||||||||||||||||||||||||||||||||||
| 866 | } | ||||||||||||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||||||||||||
| 868 | 1 | return $request; | |||||||||||||||||||||||||||||||||||||||||
| 869 | } | ||||||||||||||||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||||||||||||||||
| 871 | 16 | ▶ | if ( blessed($value) && $value->isa('Amazon::Credentials::HTTP::Response') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($value) and $value->isa("Amazon::Credentials::HTTP::Response")
MC/DC50%1/2
builtin::blessed($value) and $value->isa("Amazon::Credentials::HTTP::Response")
builtin::blessed($value)
$value->isa("Amazon::Credentials::HTTP::Response")
Truth table66%2/3
A and B
A= builtin::blessed($value)B= $value->isa("Amazon::Credentials::HTTP::Response")
| |||||||||||||||||||||||||||||||||||||||||||
| 872 | 2 | my $response = $self->sanitize( $value->{response} ); | |||||||||||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||||||||||||
| 874 | 2 | ▶ | if ( defined $response->{content} && length $response->{content} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $response->{"content"} and length $response->{"content"}
MC/DC0%0/2
defined $response->{"content"} and length $response->{"content"}
defined $response->{"content"}
length $response->{"content"}
Truth table33%1/3
A and B
A= defined $response->{"content"}B= length $response->{"content"}
| |||||||||||||||||||||||||||||||||||||||||||
| 875 | 2 | my $content = eval { decode_json( $response->{content} ) }; | |||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||||
| 877 | 2 | ▶ | if ( !$EVAL_ERROR && ref $content ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $Amazon::Credentials::EVAL_ERROR and ref $content
MC/DC50%1/2
not $Amazon::Credentials::EVAL_ERROR and ref $content
not $Amazon::Credentials::EVAL_ERROR
ref $content
Truth table66%2/3
not(A) and B
A= not $Amazon::Credentials::EVAL_ERRORB= ref $content
| |||||||||||||||||||||||||||||||||||||||||||
| 878 | 1 | $response->{content} = encode_json( $self->sanitize($content) ); | |||||||||||||||||||||||||||||||||||||||||
| 879 | } | ||||||||||||||||||||||||||||||||||||||||||
| 880 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 881 | 1 | $response->{content} = '[REDACTED]'; | |||||||||||||||||||||||||||||||||||||||||
| 882 | } | ||||||||||||||||||||||||||||||||||||||||||
| 883 | } | ||||||||||||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||||||||||||
| 885 | 2 | return Amazon::Credentials::HTTP::Response->new($response); | |||||||||||||||||||||||||||||||||||||||||
| 886 | } | ||||||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||||||
| 888 | 14 | ▶ | if ( ref $value && reftype($value) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $value and builtin::reftype($value) eq "HASH"
MC/DC100%2/2
ref $value and builtin::reftype($value) eq "HASH"
ref $value
builtin::reftype($value) eq "HASH"
Truth table100%3/3
A and B
A= ref $valueB= builtin::reftype($value) eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 889 | 5 | my %copy; | |||||||||||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||||||||||||
| 891 | 5 | foreach my $key ( keys %{$value} ) { | |||||||||||||||||||||||||||||||||||||||||
| 892 | 15 | ▶ | if ( $sensitive{ lc $key } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 893 | 7 | $copy{$key} = '[REDACTED]'; | |||||||||||||||||||||||||||||||||||||||||
| 894 | 7 | next; | |||||||||||||||||||||||||||||||||||||||||
| 895 | } | ||||||||||||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||||||||||||
| 897 | 8 | $copy{$key} = $self->sanitize( $value->{$key} ); | |||||||||||||||||||||||||||||||||||||||||
| 898 | } | ||||||||||||||||||||||||||||||||||||||||||
| 899 | |||||||||||||||||||||||||||||||||||||||||||
| 900 | 5 | return \%copy; | |||||||||||||||||||||||||||||||||||||||||
| 901 | } | ||||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||
| 903 | 9 | ▶ | if ( ref $value && reftype($value) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $value and builtin::reftype($value) eq "ARRAY"
MC/DC50%1/2
ref $value and builtin::reftype($value) eq "ARRAY"
ref $value
builtin::reftype($value) eq "ARRAY"
Truth table66%2/3
A and B
A= ref $valueB= builtin::reftype($value) eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 904 | 1 | my @copy; | |||||||||||||||||||||||||||||||||||||||||
| 905 | |||||||||||||||||||||||||||||||||||||||||||
| 906 | 1 | ▶ | for ( my $i = 0; $i < @{$value}; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 907 | 3 | my $item = $value->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||||||||||||||||
| 909 | 3 | ▶ | if ( !ref $item | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not ref $item and $sensitive{lc $item} and $i + 1 < @{$value;}
not ref $item and $sensitive{lc $item}
MC/DC33%1/3
not ref $item and $sensitive{lc $item} and $i + 1 < @{$value;}
not ref $item
$sensitive{lc $item}
$i + 1 < @{$value;}
Truth table50%2/4
not(A) and B and C
A= not ref $itemB= $sensitive{lc $item}C= $i + 1 < @{$value;}
| |||||||||||||||||||||||||||||||||||||||||||
| 910 | && $sensitive{ lc $item } | ||||||||||||||||||||||||||||||||||||||||||
| 911 | 1 | && $i + 1 < @{$value} ) { | |||||||||||||||||||||||||||||||||||||||||
| 912 | 1 | push @copy, $item, '[REDACTED]'; | |||||||||||||||||||||||||||||||||||||||||
| 913 | 1 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 914 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 915 | } | ||||||||||||||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||||||||||||
| 917 | 2 | push @copy, $self->sanitize($item); | |||||||||||||||||||||||||||||||||||||||||
| 918 | } | ||||||||||||||||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||||||||||||||||
| 920 | 1 | return \@copy; | |||||||||||||||||||||||||||||||||||||||||
| 921 | } | ||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||
| 923 | 8 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 924 | } | ||||||||||||||||||||||||||||||||||||||||||
| 925 | |||||||||||||||||||||||||||||||||||||||||||
| 926 | 14 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||||||||||||||||
| 928 | __END__ | ||||||||||||||||||||||||||||||||||||||||||