blib/lib/Paws/Credential/InstanceProfile.pm

filter: Statementstmt 95.9% 47 / 49 Branchbran 80.0% 8 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 3 totaltotal 89.1% 66 / 74 CC 6 SCAR 10.2
CC
6
Cov
93%
_refresh
6.0
__ANON__
1.1
BEGIN
1.0
CRAP 2.8
« blib/lib/Paws/Transfer.pm ↑ Summary blib/lib/Paws/Net/RetryCallerRole.pm »
1 package Paws::Credential::InstanceProfile;
2 1 ▶ use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶ use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶ use DateTime::Format::ISO8601;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 with 'Paws::Credential';
6  
7 1 has metadata_url => (
8 is => 'ro',
9 isa => 'Str',
10 default => 'http://169.254.169.254/latest/meta-data/iam/security-credentials/'
11 );
12  
13 1 has timeout => (is => 'ro', isa => 'Int', default => 1);
14  
15 has ua => (
16 is => 'ro',
17 lazy => 1,
18 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=0.6
19 0 my $self = shift;
20 1 ▶ use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 0 HTTP::Tiny->new(
22 agent => 'AWS Perl SDK',
23 timeout => $self->timeout,
24 );
25 }
26 1 );
27  
28 has expiration => (
29 is => 'rw',
30 isa => 'Int',
31 2 ▶ default => sub { 0 }
Subroutine __ANON__: called CC=1 SCAR=0.0
32 1 );
33  
34 2 ▶ has actual_creds => (is => 'rw', default => sub { {} });
Subroutine __ANON__: called CC=1 SCAR=0.0
35  
36 4 ▶ sub access_key {
Subroutine access_key: called CC=1 SCAR=0.0
Pod undocumented
37 4 my $self = shift;
38 4 $self->_refresh;
39 3 $self->actual_creds->{AccessKeyId};
40 }
41  
42 2 ▶ sub secret_key {
Subroutine secret_key: called CC=1 SCAR=0.0
Pod undocumented
43 2 my $self = shift;
44 2 $self->_refresh;
45 2 $self->actual_creds->{SecretAccessKey};
46 }
47  
48 2 ▶ sub session_token {
Subroutine session_token: called CC=1 SCAR=0.0
Pod undocumented
49 2 my $self = shift;
50 2 $self->_refresh;
51 2 $self->actual_creds->{Token};
52 }
53  
54 #TODO: Raise exceptions if HTTP get didn't return success
55 8 ▶ sub _refresh {
Subroutine _refresh: called CC=6 SCAR=18.0
56 8 my $self = shift;
57  
58 8 ▶ return if $self->expiration - 240 >= time;
Branch: 1 branch
BranchTrueFalseTotal
if $self->expiration - 240 >= time 4 4 8
59  
60 4 my $ua = $self->ua;
61 4 my $r = $ua->get($self->metadata_url);
62 4 ▶ return unless $r->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"success"} 0 4 4
63 4 ▶ return unless $r->{content};
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"content"} 1 3 4
64  
65 3 $r = $ua->get($self->metadata_url . $r->{content});
66 3 ▶ return unless $r->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"success"} 0 3 3
67  
68 3 my $json = eval { decode_json($r->{content}) };
69 3 ▶ if ($@) { die "Error in JSON from metadata URL" }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 2 3
70  
71 2 $self->actual_creds($json);
72 2 $self->expiration(DateTime::Format::ISO8601->parse_datetime($json->{Expiration})->epoch);
73 }
74  
75 1 ▶ no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
76 1 1;
77 ### main pod documentation begin ###
78  
79 =encoding UTF-8
80  
81 =head1 NAME
82  
83 Paws::Credential::InstanceProfile
84  
85 =head1 SYNOPSIS
86  
87 use Paws::Credential::InstanceProfile;
88  
89 my $paws = Paws->new(config => {
90 credentials => Paws::Credential::InstanceProfile->new(
91 metadata_url => 'http://localhost:8000/security-credentials',
92 timeout => 5,
93 )
94 });
95  
96 =head1 DESCRIPTION
97  
98 The InstanceProfile credential provider is used to call retrieve AWS credentials from instances running on AWS
99  
100 When running on an instance in AWS, if said instance has a Role attached to it (also named InstanceProfile), Paws
101 can retrieve short-term credentials (and refresh them when needed) from the AWS provided "metadata service".
102  
103 =head2 metadata_url: Str
104  
105 The section in the ini file where credentials will be looked up:
106  
107 =head2 timetout: Int
108  
109 Number of seconds to wait before timinig out a connection to the metadata service. It defaults to 1 second, as
110 the metadata service is almost local, and very fast responding. Note that if set too high, and the metadata
111 service is not present (not running on an AWS instance), the connection has to time out
112  
113 =head2 ua
114  
115 A user agent that has a C<get> method. Defaults to HTTP::Tiny
116  
117 =cut
« blib/lib/Paws/Transfer.pm ↑ Summary blib/lib/Paws/Net/RetryCallerRole.pm »