File Coverage

blib/lib/Net/Amazon/S3/Authorization/IAM.pm
Criterion Covered Total %
statement 6 10 60.0
branch 0 4 0.0
condition n/a
subroutine 2 3 66.6
pod n/a
total 8 17 47.0


line stmt bran cond sub pod time code
1             $Net::Amazon::S3::Authorization::IAM::VERSION = '0.991';
2             # ABSTRACT: IAM authorization information
3              
4             use Moose 0.85;
5 1     1   6 use MooseX::StrictConstructor 0.16;
  1         19  
  1         7  
6 1     1   6163  
  1         18  
  1         6  
7             extends 'Net::Amazon::S3::Authorization::Basic';
8              
9             has '+aws_access_key_id' => (
10             lazy => 1,
11             default => sub { $_[0]->_credentials->accessKeyId },
12             );
13              
14             has '+aws_secret_access_key' => (
15             lazy => 1,
16             default => sub { $_[0]->_credentials->secretAccessKey },
17             );
18              
19             has aws_session_token => (
20             is => 'ro',
21             lazy => 1,
22             default => sub { $_[0]->_credentials->sessionToken },
23             );
24              
25             has _credentials => (
26             is => 'ro',
27             init_arg => undef,
28             lazy => 1,
29             builder => '_build_credentials',
30             );
31              
32             eval "require VM::EC2::Security::CredentialCache" or die $@;
33             my $creds = VM::EC2::Security::CredentialCache->get();
34 0 0   0     defined($creds) || die("Unable to retrieve IAM role credentials");
35 0            
36 0 0         return $creds;
37             }
38 0            
39             around authorization_headers => sub {
40             my ($orig, $self) = @_;
41              
42             return +(
43             $self->$orig,
44             'x-amz-security-token' => $self->aws_session_token,
45             );
46             };
47              
48             1;
49              
50              
51             =pod
52              
53             =encoding UTF-8
54              
55             =head1 NAME
56              
57             Net::Amazon::S3::Authorization::IAM - IAM authorization information
58              
59             =head1 VERSION
60              
61             version 0.991
62              
63             =head1 SYNOPSIS
64              
65             use Net::Amazon::S3;
66             use Net::Amazon::S3::Authorization::IAM;
67              
68             # obtain instance credentials
69             use VM::EC2::Security::CredentialCache;
70             my $s3 = Net::Amazon::S3->new (
71             authorization_context => Net::Amazon::S3::Authorization::IAM->new,
72             ...
73             );
74              
75             # or just provide your values
76             my $s3 = Net::Amazon::S3->new (
77             authorization_context => Net::Amazon::S3::Authorization::IAM->new (
78             aws_access_key_id => ...,
79             aws_secret_access_key => ...,
80             aws_session_token => ...,
81             ),
82             ...
83             );
84              
85             =head1 DESCRIPTION
86              
87             Authorization context using instance session credentials.
88              
89             Unless specified authorization context obtains credentials via L<< VM::EC2::Security::CredentialCache >>.
90             It is not listed as a L<< Net::Amazon::S3 >> dependency.
91              
92             =head1 INCOMPATIBILITY WARNING
93              
94             This module with its dependencies will be moved out and distributed separately
95             without dependency from L<Net::Amazon::S3>.
96              
97             If you use IAM, please consider to add proper C<use> statement into your code.
98              
99             =head1 AUTHOR
100              
101             Branislav Zahradník <barney@cpan.org>
102              
103             =head1 COPYRIGHT AND LICENSE
104              
105             This software is copyright (c) 2022 by Amazon Digital Services, Leon Brocard, Brad Fitzpatrick, Pedro Figueiredo, Rusty Conover, Branislav Zahradník.
106              
107             This is free software; you can redistribute it and/or modify it under
108             the same terms as the Perl 5 programming language system itself.
109              
110             =cut