AWS-CLI-Config

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

{
   "abstract" : "Interface to access AWS CLI configs and credentials",
   "author" : [
      "IKEDA Kiyoshi <keyamb@cpan.org>"
   ],
   "dynamic_config" : 0,
   "generated_by" : "Dist::Zilla version 6.009, CPAN::Meta::Converter version 2.150005",
   "license" : [
      "perl_5"
   ],
   "meta-spec" : {
      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",

META.yml  view on Meta::CPAN

---
abstract: 'Interface to access AWS CLI configs and credentials'
author:
  - 'IKEDA Kiyoshi <keyamb@cpan.org>'
build_requires:
  File::Temp: '0'
  Test::More: '0.98'
  perl: '5.008001'
configure_requires:
  ExtUtils::MakeMaker: '0'
  Module::Build::Tiny: '0.035'
  perl: '5.008001'

Makefile.PL  view on Meta::CPAN

# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.009.
use strict;
use warnings;

use 5.008001;

use ExtUtils::MakeMaker;

my %WriteMakefileArgs = (
  "ABSTRACT" => "Interface to access AWS CLI configs and credentials",
  "AUTHOR" => "IKEDA Kiyoshi <keyamb\@cpan.org>",
  "CONFIGURE_REQUIRES" => {
    "ExtUtils::MakeMaker" => 0,
    "Module::Build::Tiny" => "0.035"
  },
  "DISTNAME" => "AWS-CLI-Config",
  "LICENSE" => "perl",
  "MIN_PERL_VERSION" => "5.008001",
  "NAME" => "AWS::CLI::Config",
  "PREREQ_PM" => {

README.md  view on Meta::CPAN

# 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.

README.md  view on Meta::CPAN

## region (Str)

Fetches $ENV{AWS\_DEFAULT\_REGION} or _region_ defined in the credential or
config file. You can optionally specify the profile as the first argument.

## output (Str)

Fetches _output_ defined in the credential or config file. You can optionally
specify the profile as the first argument.

## credentials (Str)

Fetches information from the credential file if it exists. You can optionally
specify the profile as the first argument.

## config (Str)

Fetches information from the config file if it exists. If you need to override
the default path of this file, use the `$ENV{AWS_CONFIG_FILE}` variable.
You can optionally specify the profile as the first argument.

README.md  view on Meta::CPAN

Accessors will also be automatically generated for all top-level keys in a given
profile the first time they are called. They will be cached, so that you only
pay this cost if you ask for it, and only do so once.

The accessors will have the same name as the keys they represent.

Please note, however, that accessors will **not** be generated for nested values.

# LIMITATIONS

"Instance profile credentials" are not yet supported by this module.

# SEE ALSO

- [Net::Amazon::Config](https://metacpan.org/pod/Net::Amazon::Config),
- [http://aws.amazon.com/cli/](http://aws.amazon.com/cli/)

# LICENSE

Copyright (C) IKEDA Kiyoshi.

lib/AWS/CLI/Config.pm  view on Meta::CPAN

    my $env_var = $opt{env};
    my $profile_key = $opt{key} || $attr;

    return sub {
        if ($env_var && exists $ENV{$env_var} && $ENV{$env_var}) {
            return $ENV{$env_var};
        }

        my $profile = shift || _default_profile();

        my $credentials = credentials($profile);
        if ($credentials && $credentials->$profile_key) {
            return $credentials->$profile_key;
        }

        my $config = config($profile);
        if ($config && $config->$profile_key) {
            return $config->$profile_key;
        }

        return undef;
    };
}

sub credentials {
    my $profile = shift || _default_profile();

    $CREDENTIALS ||= _parse(
        (exists $ENV{AWS_CONFIG_FILE} and $ENV{AWS_CONFIG_FILE})
            ? $ENV{AWS_CONFIG_FILE}
            : File::Spec->catfile(_default_dir(), 'credentials')
    );

    return unless (exists $CREDENTIALS->{$profile});
    $CREDENTIALS_PROFILE_OF{$profile} ||=
        AWS::CLI::Config::Profile->new($CREDENTIALS->{$profile});
    return $CREDENTIALS_PROFILE_OF{$profile};
}

sub config {
    my $profile = shift || _default_profile();

lib/AWS/CLI/Config.pm  view on Meta::CPAN

}

1;

__END__

=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.

lib/AWS/CLI/Config.pm  view on Meta::CPAN

=head2 region (Str)

Fetches $ENV{AWS_DEFAULT_REGION} or I<region> defined in the credential or
config file. You can optionally specify the profile as the first argument.

=head2 output (Str)

Fetches I<output> defined in the credential or config file. You can optionally
specify the profile as the first argument.

=head2 credentials (Str)

Fetches information from the credential file if it exists. You can optionally
specify the profile as the first argument.

=head2 config (Str)

Fetches information from the config file if it exists. If you need to override
the default path of this file, use the C<$ENV{AWS_CONFIG_FILE}> variable.
You can optionally specify the profile as the first argument.

lib/AWS/CLI/Config.pm  view on Meta::CPAN

Accessors will also be automatically generated for all top-level keys in a given
profile the first time they are called. They will be cached, so that you only
pay this cost if you ask for it, and only do so once.

The accessors will have the same name as the keys they represent.

Please note, however, that accessors will B<not> be generated for nested values.

=head1 LIMITATIONS

"Instance profile credentials" are not yet supported by this module.

=head1 SEE ALSO

=over 4

=item * L<Net::Amazon::Config>,

=item * L<http://aws.amazon.com/cli/>

=back

t/02_access_key_id.t  view on Meta::CPAN

use warnings;
use Test::More;

use AWS::CLI::Config;

subtest 'Environment Variable' => sub {
    local $ENV{AWS_ACCESS_KEY_ID} = '__dummy__';
    is(AWS::CLI::Config::access_key_id, $ENV{AWS_ACCESS_KEY_ID}, 'set by env');
};

subtest 'From credentials file' => sub {
    my $access_key_id = q[It's me.];
    undef local $ENV{AWS_ACCESS_KEY_ID};
    no strict 'refs';
    no warnings 'redefine';
    *AWS::CLI::Config::credentials = sub {
        return AWS::CLI::Config::Profile->new({
                aws_access_key_id => $access_key_id,
            });
    };
    is(AWS::CLI::Config::access_key_id, $access_key_id, 'set by credentials');
};

subtest 'From config file' => sub {
    my $access_key_id = q[It's me.];
    undef local $ENV{AWS_ACCESS_KEY_ID};
    no strict 'refs';
    no warnings 'redefine';
    *AWS::CLI::Config::credentials = sub {
        return undef;
    };
    *AWS::CLI::Config::config = sub {
        return AWS::CLI::Config::Profile->new({
                aws_access_key_id => $access_key_id,
            });
    };
    is(AWS::CLI::Config::access_key_id, $access_key_id, 'set by config');
};

t/03_output.t  view on Meta::CPAN

use strict;
use warnings;
use Test::More;

use AWS::CLI::Config;

subtest 'From credentials file' => sub {
    my $output = '__format__';
    no strict 'refs';
    no warnings 'redefine';
    *AWS::CLI::Config::credentials = sub {
        return AWS::CLI::Config::Profile->new({
                output => $output,
            });
    };
    is(AWS::CLI::Config::output, $output, 'set by credentials');
};

subtest 'From config file' => sub {
    my $output = '__format__';
    no strict 'refs';
    no warnings 'redefine';
    *AWS::CLI::Config::credentials = sub {
        return undef;
    };
    *AWS::CLI::Config::config = sub {
        return AWS::CLI::Config::Profile->new({
                output => $output,
            });
    };
    is(AWS::CLI::Config::output, $output, 'set by config');
};



( run in 0.400 second using v1.01-cache-2.11-cpan-4d50c553e7e )