blib/lib/Paws/Credential/CredProcess.pm

filter: Statementstmt 100% 51 / 51 Branchbran 83.3% 10 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 3 totaltotal 93.5% 72 / 77 CC 7 SCAR 9.3
CC
7
Cov
97%
_build_actual_creds
5.0
_refresh
3.0
BEGIN
1.0
CRAP 2.5
« blib/lib/Paws/Net/S3Signature.pm ↑ Summary blib/lib/Paws/S3Control.pm »
1 package Paws::Credential::CredProcess;
2 1 ▶ use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶ use JSON::MaybeXS qw/decode_json/;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶ use Paws::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶ use DateTime::Format::ISO8601;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 has credential_process => (is => 'ro', isa => 'Str', required => 1);
8  
9 has expiration => (
10 is => 'rw',
11 isa => 'Int|Undef',
12 lazy => 1,
13 8 ▶ default => sub { 0 }
Subroutine __ANON__: called CC=1 SCAR=0.0
14 1 );
15  
16 1 has actual_creds => (
17 is => 'ro',
18 isa => 'HashRef',
19 builder => '_build_actual_creds',
20 clearer => '_clear_actual_creds',
21 lazy => 1
22 );
23  
24 10 ▶ sub _build_actual_creds {
Subroutine _build_actual_creds: called CC=5 SCAR=16.1
25 10 my $self = shift;
26 10 my $creds;
27 my $rc;
28 {
29 10 local $/ = undef;
30 10 open (my $fh, '-|', $self->credential_process);
31 10 $creds = <$fh>;
32 10 close $fh;
33 10 $rc = $?;
34 }
35 10 ▶ Paws::Exception::CredentialProcess->throw("credential_process returned non-zero code") if ($rc != 0);
Branch: 1 branch
BranchTrueFalseTotal
if $rc != 0 2 8 10
36 8 $creds = decode_json($creds);
37 8 ▶ Paws::Exception::CredentialProcess->throw("credential_process didn't return a Version key") if (not exists $creds->{ Version });
Branch: 1 branch
BranchTrueFalseTotal
unless exists $creds->{"Version"} 2 6 8
38 6 ▶ Paws::Exception::CredentialProcess->throw("credential_process only understands Version 1") if ($creds->{ Version } != 1);
Branch: 1 branch
BranchTrueFalseTotal
if $creds->{"Version"} != 1 0 6 6
39  
40 6 my $expiry = $creds->{ Expiration };
41 6 ▶ if (defined $expiry) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $expiry) { } 4 2 6
42 4 $self->expiration(DateTime::Format::ISO8601->parse_datetime($expiry)->epoch)
43 } else {
44 2 $self->expiration(undef);
45 }
46  
47 6 return $creds;
48 }
49  
50 12 ▶ sub access_key {
Subroutine access_key: called CC=1 SCAR=0.0
Pod undocumented
51 12 my $self = shift;
52 12 $self->_refresh;
53 12 $self->actual_creds->{ AccessKeyId };
54 }
55  
56 4 ▶ sub secret_key {
Subroutine secret_key: called CC=1 SCAR=0.0
Pod undocumented
57 4 my $self = shift;
58 4 $self->_refresh;
59 $self->actual_creds->{ SecretAccessKey }
60 4 }
61  
62 2 ▶ sub session_token {
Subroutine session_token: called CC=1 SCAR=0.0
Pod undocumented
63 2 my $self = shift;
64 2 $self->_refresh;
65 2 $self->actual_creds->{ SessionToken };
66 }
67  
68 18 ▶ sub _refresh {
Subroutine _refresh: called CC=3 SCAR=11.0
69 18 my $self = shift;
70  
71 18 ▶ return if not defined $self->expiration;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->expiration 8 10 18
72 10 ▶ return if $self->expiration >= time;
Branch: 1 branch
BranchTrueFalseTotal
if $self->expiration >= time 0 10 10
73 10 $self->_clear_actual_creds;
74 }
75  
76 1 with 'Paws::Credential';
77  
78 1 ▶ no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
79 1 1;
80 ### main pod documentation begin ###
81  
82 =encoding UTF-8
83  
84 =head1 NAME
85  
86 Paws::Credential::File
87  
88 =head1 SYNOPSIS
89  
90 use Paws::Credential::File;
91  
92 my $paws = Paws->new(config => {
93 credentials => Paws::Credential::File->new(
94 profile => 'profile1',
95 credentials_file => '/etc/aws_system_credentials',
96 )
97 });
98 # will open /etc/aws_system_credentials
99  
100
101 my $paws = Paws->new(config => {
102 credentials => Paws::Credential::File->new(
103 profile => 'profile1',
104 file_name => 'my_creds',
105 )
106 });
107 # will open $HOME/.aws/my_creds
108  
109 my $paws = Paws->new(config => {
110 credentials => Paws::Credential::File->new(
111 profile => 'profile1',
112 dir => '/etc/',
113 )
114 });
115 # will open /etc/credentials
116  
117  
118 =head1 DESCRIPTION
119  
120 The File credential provider is to read credentials from AWS SDK config files
121  
122 =head2 profile: Str
123  
124 The section in the ini file where credentials will be looked up:
125  
126 Defaults to the environment variable C<AWS_DEFAULT_PROFILE>, and if that is not defined, to "default"
127  
128 =head2 credentials_file: Str
129  
130 The path of the ini file to open
131  
132 Defaults to the path + file_name (C<$HOME/.aws/credentials> by default) if the environment variable AWS_CONFIG_FILE doesn't exist
133  
134 =head2 path: Str
135  
136 Path to the ini file
137  
138 Defaults to C<$HOME/.aws>
139  
140 =head2 file_name: Str
141  
142 Name of the ini file
143  
144 Defaults to C<credentials>
145  
146 =cut
« blib/lib/Paws/Net/S3Signature.pm ↑ Summary blib/lib/Paws/S3Control.pm »