AWS-CLI-Config
view release on metacpan or search on metacpan
# NAME
AWS::CLI::Config - Interface to access AWS CLI configs and credentials
# SYNOPSIS
use AWS::CLI::Config;
my $aws_access_key_id = AWS::CLI::Config::access_key_id;
my $aws_secret_access_key = AWS::CLI::Config::secret_access_key($profile);
my $aws_session_token = AWS::CLI::Config::session_token($profile);
my $region = AWS::CLI::Config::region($profile);
# DESCRIPTION
**AWS::CLI::Config** provides an interface to access AWS CLI configuration and
credentials. It fetches its values from the appropriate environment variables,
or a credential or config file in the order described in
[AWS CLI Documents](http://docs.aws.amazon.com/cli/).
# SUBROUTINES
## access\_key\_id (Str)
Fetches $ENV{AWS\_ACCESS\_KEY\_ID} or _aws\_access\_key\_id_ defined in the
credential or config file. You can optionally specify the profile as the
first argument.
## secret\_access\_key (Str)
Fetches $ENV{AWS\_SECRET\_ACCESS\_KEY} or _aws\_secret\_access\_key_ defined in
the credential or config file. You can optionally specify the profile as
the first argument.
## session\_token (Str)
Fetches $ENV{AWS\_SESSION\_TOKEN} or _aws\_session\_token_ defined in the
credential or config file. You can optionally specify the profile as the first
argument.
## region (Str)
lib/AWS/CLI/Config.pm view on Meta::CPAN
my %CREDENTIALS_PROFILE_OF;
my $CONFIG;
my %CONFIG_PROFILE_OF;
BEGIN: {
my %attributes = (
access_key_id => {
env => 'AWS_ACCESS_KEY_ID',
key => 'aws_access_key_id'
},
secret_access_key => {
env => 'AWS_SECRET_ACCESS_KEY',
key => 'aws_secret_access_key',
},
session_token => {
env => 'AWS_SESSION_TOKEN',
key => 'aws_session_token',
},
region => { env => 'AWS_DEFAULT_REGION' },
output => {},
);
while (my ($name, $opts) = each %attributes) {
lib/AWS/CLI/Config.pm view on Meta::CPAN
=encoding UTF-8
=head1 NAME
AWS::CLI::Config - Interface to access AWS CLI configs and credentials
=head1 SYNOPSIS
use AWS::CLI::Config;
my $aws_access_key_id = AWS::CLI::Config::access_key_id;
my $aws_secret_access_key = AWS::CLI::Config::secret_access_key($profile);
my $aws_session_token = AWS::CLI::Config::session_token($profile);
my $region = AWS::CLI::Config::region($profile);
=head1 DESCRIPTION
B<AWS::CLI::Config> provides an interface to access AWS CLI configuration and
credentials. It fetches its values from the appropriate environment variables,
or a credential or config file in the order described in
L<AWS CLI Documents|http://docs.aws.amazon.com/cli/>.
=head1 SUBROUTINES
=head2 access_key_id (Str)
Fetches $ENV{AWS_ACCESS_KEY_ID} or I<aws_access_key_id> defined in the
credential or config file. You can optionally specify the profile as the
first argument.
=head2 secret_access_key (Str)
Fetches $ENV{AWS_SECRET_ACCESS_KEY} or I<aws_secret_access_key> defined in
the credential or config file. You can optionally specify the profile as
the first argument.
=head2 session_token (Str)
Fetches $ENV{AWS_SESSION_TOKEN} or I<aws_session_token> defined in the
credential or config file. You can optionally specify the profile as the first
argument.
=head2 region (Str)
t/04_config.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use File::Temp 'tempfile';
use AWS::CLI::Config;
my ($fh, $file) = tempfile(UNLINK => 1);
my $default_access_key_id = 'Me';
my $default_secret_access_key = '__secret__';
my $tester_access_key_id = "Tester$default_access_key_id";
my $tester_secret_access_key = "__tester$default_secret_access_key";
print $fh <<"EOS";
[default]
aws_access_key_id = $default_access_key_id
aws_secret_access_key = $default_secret_access_key
[profile tester]
aws_access_key_id = $tester_access_key_id
aws_secret_access_key = $tester_secret_access_key
s3 =
addressing_style = path
EOS
close $fh;
local $ENV{AWS_CONFIG_FILE} = $file;
subtest 'Default profile' => sub {
my $config = AWS::CLI::Config::config;
is($config->aws_access_key_id, $default_access_key_id, 'access_key_id');
is($config->aws_secret_access_key, $default_secret_access_key, 'secret_access_key');
};
subtest 'Specific profile' => sub {
my $config = AWS::CLI::Config::config('tester');
is($config->aws_access_key_id, $tester_access_key_id, 'access_key_id');
is($config->aws_secret_access_key, $tester_secret_access_key, 'secret_access_key');
is($config->s3->{addressing_style}, 'path', 'nested value');
};
subtest 'Undefined profile' => sub {
my $config = AWS::CLI::Config::config('no-such-profile');
ok(!$config, 'undefined');
};
done_testing;
( run in 0.987 second using v1.01-cache-2.11-cpan-39bf76dae61 )