File Coverage

blib/lib/Paws/Credential/File.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Paws::Credential::File;
2 1     1   847 use Moose;
  1         2  
  1         7  
3 1     1   7207 use Config::INI::Reader;
  1         8706  
  1         40  
4 1     1   305 use File::HomeDir;
  1         4161  
  1         349  
5              
6             has profile => (is => 'ro', default => sub { $ENV{ AWS_DEFAULT_PROFILE } or 'default' });
7              
8             has credentials_file => (is => 'ro', lazy => 1, default => sub {
9             my $self = shift;
10             if (defined $ENV{AWS_CONFIG_FILE}){
11             return $ENV{AWS_CONFIG_FILE};
12             } else {
13             return $self->path . '/' . $self->file_name;
14             }
15             });
16              
17             has file_name => (is => 'ro', default => sub { 'credentials' });
18             has path => (is => 'ro', default => sub {
19             return (File::HomeDir->my_home || '') . '/.aws/';
20             });
21              
22             has _ini_contents => (is => 'ro', isa => 'HashRef', lazy => 1, default => sub {
23             my $self = shift;
24             my $ini_file = $self->credentials_file;
25             return {} if (not -e $ini_file);
26             my $ini = Config::INI::Reader->read_file($ini_file);
27             return $ini;
28             });
29              
30             has access_key => (is => 'ro', lazy => 1, default => sub {
31             my $self = shift;
32             my $ini_section = $self->profile;
33             my $ak = $self->_ini_contents->{ $ini_section }->{ aws_access_key_id };
34             return $ak;
35             });
36             has secret_key => (is => 'ro', lazy => 1, default => sub {
37             my $self = shift;
38             my $ini_section = $self->profile;
39             my $sk = $self->_ini_contents->{ $ini_section }->{ aws_secret_access_key };
40             return $sk;
41             });
42             has session_token => (is => 'ro', lazy => 1, default => sub {
43             my $self = shift;
44             my $ini_section = $self->profile;
45             my $st = $self->_ini_contents->{ $ini_section }->{ aws_session_token };
46             return $st;
47             });
48              
49             with 'Paws::Credential';
50              
51 1     1   9 no Moose;
  1         2  
  1         10  
52             1;
53             ### main pod documentation begin ###
54              
55             =encoding UTF-8
56              
57             =head1 NAME
58              
59             Paws::Credential::File
60              
61             =head1 SYNOPSIS
62              
63             use Paws::Credential::File;
64              
65             my $paws = Paws->new(config => {
66             credentials => Paws::Credential::File->new(
67             profile => 'profile1',
68             credentials_file => '/etc/aws_system_credentials',
69             )
70             });
71             # will open /etc/aws_system_credentials
72              
73            
74             my $paws = Paws->new(config => {
75             credentials => Paws::Credential::File->new(
76             profile => 'profile1',
77             file_name => 'my_creds',
78             )
79             });
80             # will open $HOME/.aws/my_creds
81              
82             my $paws = Paws->new(config => {
83             credentials => Paws::Credential::File->new(
84             profile => 'profile1',
85             dir => '/etc/',
86             )
87             });
88             # will open /etc/credentials
89              
90              
91             =head1 DESCRIPTION
92              
93             The File credential provider is to read credentials from AWS SDK config files
94              
95             =head2 profile: Str
96              
97             The section in the ini file where credentials will be looked up:
98              
99             Defaults to the environment variable C<AWS_DEFAULT_PROFILE>, and if that is not defined, to "default"
100              
101             =head2 credentials_file: Str
102              
103             The path of the ini file to open
104              
105             Defaults to the path + file_name (C<$HOME/.aws/credentials> by default) if the environment variable AWS_CONFIG_FILE doesn't exist
106              
107             =head2 path: Str
108              
109             Path to the ini file
110              
111             Defaults to C<$HOME/.aws>
112              
113             =head2 file_name: Str
114              
115             Name of the ini file
116              
117             Defaults to C<credentials>
118              
119             =cut