| 1 | package Paws::Credential::AssumeRoleWebIdentity; | ||||||||||
| 2 | |||||||||||
| 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 Paws::Credential::None; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | with 'Paws::Credential'; | |||||||||
| 8 | |||||||||||
| 9 | 1 | our $VERSION = "1.0.0"; | |||||||||
| 10 | |||||||||||
| 11 | has expiration => ( | ||||||||||
| 12 | is => 'rw', | ||||||||||
| 13 | isa => 'Int', | ||||||||||
| 14 | lazy => 1, | ||||||||||
| 15 | 0 | ▶ | default => sub { 0 } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 16 | 1 | ); | |||||||||
| 17 | |||||||||||
| 18 | has RoleArn => ( | ||||||||||
| 19 | is => 'rw', | ||||||||||
| 20 | isa => 'Str', | ||||||||||
| 21 | lazy => 1, | ||||||||||
| 22 | 0 | ▶ | default => sub { $ENV{'AWS_ROLE_ARN'} } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 23 | 1 | ); | |||||||||
| 24 | |||||||||||
| 25 | has WebIdentityTokenFile => ( | ||||||||||
| 26 | is => 'rw', | ||||||||||
| 27 | isa => 'Str', | ||||||||||
| 28 | lazy => 1, | ||||||||||
| 29 | 0 | ▶ | default => sub { $ENV{'AWS_WEB_IDENTITY_TOKEN_FILE'} } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 30 | 1 | ); | |||||||||
| 31 | |||||||||||
| 32 | has sts_region => ( | ||||||||||
| 33 | is => 'ro', | ||||||||||
| 34 | isa => 'Str|Undef', | ||||||||||
| 35 | 0 | ▶ | default => sub { undef } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 36 | 1 | ); | |||||||||
| 37 | |||||||||||
| 38 | has sts => ( | ||||||||||
| 39 | is => 'ro', | ||||||||||
| 40 | isa => 'Paws::STS', | ||||||||||
| 41 | lazy => 1, | ||||||||||
| 42 | 0 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 43 | 0 | my $self = shift; | |||||||||
| 44 | 0 | Paws->service('STS', | |||||||||
| 45 | credentials => Paws::Credential::None->new, | ||||||||||
| 46 | region => $self->sts_region | ||||||||||
| 47 | ); | ||||||||||
| 48 | } | ||||||||||
| 49 | 1 | ); | |||||||||
| 50 | |||||||||||
| 51 | has RoleSessionName => ( | ||||||||||
| 52 | is => 'rw', | ||||||||||
| 53 | isa => 'Str', | ||||||||||
| 54 | 0 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 55 | 0 | return sprintf('paws-session-%s', time()) | |||||||||
| 56 | } | ||||||||||
| 57 | 1 | ); | |||||||||
| 58 | |||||||||||
| 59 | 1 | has DurationSeconds => ( | |||||||||
| 60 | is => 'rw', | ||||||||||
| 61 | isa => 'Maybe[Int]' | ||||||||||
| 62 | ); | ||||||||||
| 63 | |||||||||||
| 64 | 1 | has actual_creds => ( | |||||||||
| 65 | is => 'rw', | ||||||||||
| 66 | isa => 'Object' | ||||||||||
| 67 | ); | ||||||||||
| 68 | |||||||||||
| 69 | 0 | ▶ | sub _web_identity_token { | ||||||||
|
Subroutine
_web_identity_token: not called CC=3 SCAR=24.8
| |||||||||||
| 70 | 0 | my $self = shift; | |||||||||
| 71 | |||||||||||
| 72 | 0 | ▶ | return unless -e $self->WebIdentityTokenFile; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | |||||||||||
| 74 | 0 | ▶ | open my $fh, '<', $self->WebIdentityTokenFile or | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | die "Not able to open WebIdentityTokenFile: $!"; | ||||||||||
| 76 | 0 | my $token = do { local $/; <$fh> }; | |||||||||
| 77 | 0 | close $fh; | |||||||||
| 78 | |||||||||||
| 79 | 0 | return $token; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | 0 | ▶ | sub access_key { | ||||||||
|
Subroutine
access_key: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 83 | 0 | my $self = shift; | |||||||||
| 84 | 0 | $self->_refresh; | |||||||||
| 85 | |||||||||||
| 86 | 0 | return $self->actual_creds->AccessKeyId; | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 0 | ▶ | sub secret_key { | ||||||||
|
Subroutine
secret_key: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 90 | 0 | my $self = shift; | |||||||||
| 91 | 0 | $self->_refresh; | |||||||||
| 92 | |||||||||||
| 93 | 0 | return $self->actual_creds->SecretAccessKey; | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | 0 | ▶ | sub session_token { | ||||||||
|
Subroutine
session_token: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 97 | 0 | my $self = shift; | |||||||||
| 98 | 0 | $self->_refresh; | |||||||||
| 99 | |||||||||||
| 100 | 0 | return $self->actual_creds->SessionToken; | |||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | 0 | ▶ | sub _refresh { | ||||||||
|
Subroutine
_refresh: not called CC=3 SCAR=24.8
| |||||||||||
| 104 | 0 | my $self = shift; | |||||||||
| 105 | 0 | ▶ | return if $self->expiration - 240 >= time; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | |||||||||||
| 107 | 0 | my $token = $self->_web_identity_token(); | |||||||||
| 108 | 0 | ▶ | my $result = $self->sts->AssumeRoleWithWebIdentity( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | RoleSessionName => $self->RoleSessionName, | ||||||||||
| 110 | RoleArn => $self->RoleArn, | ||||||||||
| 111 | WebIdentityToken => $token, | ||||||||||
| 112 | (defined $self->DurationSeconds) ? (DurationSeconds => $self->DurationSeconds) : (), | ||||||||||
| 113 | ); | ||||||||||
| 114 | 0 | my $creds = $self->actual_creds($result->Credentials); | |||||||||
| 115 | |||||||||||
| 116 | 0 | my $expiration = $result->Credentials->Expiration; | |||||||||
| 117 | 0 | $self->expiration( | |||||||||
| 118 | DateTime::Format::ISO8601->parse_datetime($expiration)->epoch | ||||||||||
| 119 | ); | ||||||||||
| 120 | } | ||||||||||
| 121 | |||||||||||
| 122 | 1 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 123 | 1 | 1; | |||||||||
| 124 | |||||||||||
| 125 | __END__ | ||||||||||