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