blib/lib/Paws/Credential/AssumeRole.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 55 CC 5 SCAR 26.9
CC
5
Cov
0%
_refresh
30.0
access_key
2.0
secret_key
2.0
CRAP 14.7
1 package Paws::Credential::AssumeRole;
2 use Moose;
3 use DateTime::Format::ISO8601;
4 with 'Paws::Credential';
5  
6 has expiration => (
7 is => 'rw',
8 isa => 'Int',
9 lazy => 1,
10 default => sub { 0 }
11 );
12  
13 has actual_creds => (is => 'rw');
14  
15 sub access_key {
16 my $self = shift;
17 $self->_refresh;
18 $self->actual_creds->AccessKeyId;
19 }
20  
21 sub secret_key {
22 my $self = shift;
23 $self->_refresh;
24 $self->actual_creds->SecretAccessKey;
25 }
26  
27 sub session_token {
28 my $self = shift;
29 $self->_refresh;
30 $self->actual_creds->SessionToken;
31 }
32  
33 has sts_region => (is => 'ro', isa => 'Str|Undef', default => sub { undef });
34  
35 has sts => (is => 'ro', isa => 'Paws::STS', lazy => 1, default => sub {
36 my $self = shift;
37 Paws->service('STS', region => $self->sts_region);
38 });
39  
40 has DurationSeconds => (is => 'rw', isa => 'Maybe[Int]');
41 has Policy => (is => 'rw', isa => 'Maybe[Str]');
42  
43 has ExternalId => (is => 'rw', isa => 'Maybe[Str]');
44 has RoleArn => (is => 'rw', isa => 'Str', required => 1);
45 has RoleSessionName => (is => 'rw', isa => 'Str', required => 1);
46
47 sub _refresh {
48 my $self = shift;
49  
50 return if $self->expiration >= time;
51  
52 my $result = $self->sts->AssumeRole(
53 RoleSessionName => $self->RoleSessionName,
54 RoleArn => $self->RoleArn,
55 (defined $self->ExternalId) ? (ExternalId => $self->ExternalId) : (),
56 (defined $self->DurationSeconds) ? (DurationSeconds => $self->DurationSeconds) : (),
57 (defined $self->Policy) ? (Policy => $self->Policy) : (),
58 );
59  
60 my $creds = $self->actual_creds($result->Credentials);
61 $self->expiration(DateTime::Format::ISO8601->parse_datetime($result->Credentials->Expiration)->epoch);
62 }
63  
64 no Moose;
65 1;
66 ### main pod documentation begin ###
67  
68 =encoding UTF-8
69  
70 =head1 NAME
71  
72 Paws::Credential::AssumeRole
73  
74 =head1 SYNOPSIS
75  
76 use Paws::Credential::AssumeRole;
77  
78 my $paws = Paws->new(config => {
79 credentials => Paws::Credential::AssumeRole->new(
80 DurationSeconds => 60,
81 RoleArn => 'arn:....',
82 RoleSessionName => 'MySession',
83 )
84 });
85  
86 =head1 DESCRIPTION
87  
88 The AssumeRole provider is used to obtain temporary credentials with the AssumeRole STS call. These credentials
89 can further be limited by a Policy document.
90  
91 Credentials are refreshed with a re-call to STS when they have expired
92  
93 =head2 DurationSeconds: Int (optional)
94  
95 The number of seconds for which the credentials will be valid
96  
97 =head2 Policy: Str (optional)
98  
99 A string with an IAM policy that gets merged with the roles capabilities
100  
101 =head2 ExternalId: Str (optional)
102  
103 A string with the external id of the role
104  
105 =head2 RoleArn: Str
106  
107 The arn of the role to be assumed
108  
109 =head2 RoleSessionName: Str
110  
111 The name of the session (will appear in CloudTrail logs, for example)
112  
113 =cut