blib/lib/Paws/Credential/ECSContainerProfile.pm

filter: Statementstmt 93.5% 58 / 62 Branchbran 64.2% 9 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 14 / 16 Podpod 0.0% 0 / 3 totaltotal 85.2% 81 / 95 CC 8 SCAR 9.4
CC
8
Cov
88%
_refresh
6.1
__ANON__
2.3
__ANON__
2.0
CRAP 2.6
« blib/lib/Paws/Net/RetryCallerRole.pm ↑ Summary blib/lib/Paws/Net/S3Signature.pm »
1 package Paws::Credential::ECSContainerProfile;
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 ▶ use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 with 'Paws::Credential';
7  
8 has container_local_uri => (
9 is => 'ro',
10 isa => 'Str|Undef',
11 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
12 $ENV{ AWS_CONTAINER_CREDENTIALS_RELATIVE_URI }
13 0 }
14 1 );
15  
16 has metadata_url => (
17 is => 'ro',
18 isa => 'Str|Undef',
19 lazy => 1,
20 1 ▶ default => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
21 1 my $self = shift;
22 1 ▶ return undef if (not defined $self->container_local_uri);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->container_local_uri 0 1 1
23 1 my $url = URI->new("http://169.254.170.2");
24 1 $url->path($self->container_local_uri);
25 1 return $url->as_string;
26 }
27 1 );
28  
29 1 has timeout => (is => 'ro', isa => 'Int', default => 1);
30  
31 has ua => (
32 is => 'ro',
33 lazy => 1,
34 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=0.6
35 0 my $self = shift;
36 1 ▶ use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 0 HTTP::Tiny->new(
38 agent => 'AWS Perl SDK',
39 timeout => $self->timeout,
40 );
41 }
42 1 );
43  
44 has expiration => (
45 is => 'rw',
46 isa => 'Int',
47 2 ▶ default => sub { 0 }
Subroutine __ANON__: called CC=1 SCAR=0.0
48 1 );
49  
50 2 ▶ has actual_creds => (is => 'rw', default => sub { {} });
Subroutine __ANON__: called CC=1 SCAR=0.0
51  
52 1 ▶ around are_set => sub {
Subroutine __ANON__: called CC=2 SCAR=8.1
53 1 my ($orig, $self) = @_;
54 1 ▶ return 0 if (not defined $self->container_local_uri);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->container_local_uri 1 0 1
55 0 return $self->$orig;
56 1 };
57  
58 3 ▶ sub access_key {
Subroutine access_key: called CC=1 SCAR=0.0
Pod undocumented
59 3 my $self = shift;
60 3 $self->_refresh;
61 2 $self->actual_creds->{AccessKeyId};
62 }
63  
64 2 ▶ sub secret_key {
Subroutine secret_key: called CC=1 SCAR=0.0
Pod undocumented
65 2 my $self = shift;
66 2 $self->_refresh;
67 2 $self->actual_creds->{SecretAccessKey};
68 }
69  
70 2 ▶ sub session_token {
Subroutine session_token: called CC=1 SCAR=0.0
Pod undocumented
71 2 my $self = shift;
72 2 $self->_refresh;
73 2 $self->actual_creds->{Token};
74 }
75  
76 #TODO: Raise exceptions if HTTP get didn't return success
77 7 ▶ sub _refresh {
Subroutine _refresh: called CC=6 SCAR=18.0
78 7 my $self = shift;
79  
80 7 ▶ return if $self->expiration - 240 >= time;
Branch: 1 branch
BranchTrueFalseTotal
if $self->expiration - 240 >= time 4 3 7
81 3 ▶ return if ! $self->metadata_url;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->metadata_url 0 3 3
82  
83 3 my $ua = $self->ua;
84  
85 3 my $r = $ua->get($self->metadata_url);
86 3 ▶ return unless $r->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"success"} 0 3 3
87 3 ▶ return unless $r->{content};
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"content"} 0 3 3
88  
89 3 my $json = eval { decode_json($r->{content}) };
90 3 ▶ if ($@) { die "Error in JSON from metadata URL" }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 2 3
91  
92 2 $self->actual_creds($json);
93 2 $self->expiration(DateTime::Format::ISO8601->parse_datetime($json->{Expiration})->epoch);
94 }
95  
96 1 ▶ no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
97 1 1;
98 ### main pod documentation begin ###
99  
100 =encoding UTF-8
101  
102 =head1 NAME
103  
104 Paws::Credential::ECSContainerProfile
105  
106 =head1 SYNOPSIS
107  
108 use Paws::Credential::ECSContainerProfile;
109  
110 my $paws = Paws->new(config => {
111 credentials => Paws::Credential::ECSContainerProfile->new(
112 metadata_url => 'http://localhost:8000/security-credentials',
113 timeout => 5,
114 )
115 });
116  
117 =head1 DESCRIPTION
118  
119 The InstanceProfile credential provider is used to call retrieve AWS credentials from conatiners running on AWS ECS
120  
121 When running in an ECS Container on AWS, if said container has a Role attached to it, Paws
122 can retrieve short-term credentials (and refresh them when needed) from the AWS provided "metadata service".
123  
124 =head2 metadata_url: Str
125  
126 The url where credentials will be retrieved. Defaults to documented endpoint for container profile retrieval. Should not
127 normally need to be overriden.
128  
129 =head2 timetout: Int
130  
131 Number of seconds to wait before timinig out a connection to the metadata service. It defaults to 1 second, as
132 the metadata service is almost local, and very fast responding. Note that if set too high, and the metadata
133 service is not present (not running on an AWS instance), the connection has to time out
134  
135 =head2 ua
136  
137 A user agent that has a C<get> method. Defaults to HTTP::Tiny
138  
139 =cut
« blib/lib/Paws/Net/RetryCallerRole.pm ↑ Summary blib/lib/Paws/Net/S3Signature.pm »