Amazon-Credentials

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

         }
      },
      "runtime" : {
         "requires" : {
            "Class::Accessor" : "0.31",
            "Data::Dumper" : "2.145",
            "Date::Format" : "2.24",
            "Exporter" : "5.68",
            "File::HomeDir" : "1.00",
            "File::chdir" : "0.1008",
            "HTTP::Request" : "6.00",
            "JSON" : "2.59",
            "LWP::UserAgent" : "6.05",
            "POSIX::strptime" : "0.13",
            "Scalar::Util" : "1.5",
            "Time::Local" : "1.2300",
            "constant" : "1.27",
            "parent" : "0.225",
            "strict" : "1.07",
            "vars" : "1.02",
            "warnings" : "1.13"

META.yml  view on Meta::CPAN

  directory:
    - t
    - inc
requires:
  Class::Accessor: '0.31'
  Data::Dumper: '2.145'
  Date::Format: '2.24'
  Exporter: '5.68'
  File::HomeDir: '1.00'
  File::chdir: '0.1008'
  HTTP::Request: '6.00'
  JSON: '2.59'
  LWP::UserAgent: '6.05'
  POSIX::strptime: '0.13'
  Scalar::Util: '1.5'
  Time::Local: '1.2300'
  constant: '1.27'
  parent: '0.225'
  strict: '1.07'
  vars: '1.02'
  warnings: '1.13'

Makefile.PL  view on Meta::CPAN

    ABSTRACT       => 'AWS credentials discoverer',
    LICENSE        => 'perl',
    PL_FILES       => {},
    PREREQ_PM      => {
      'Class::Accessor' => '0.31',
      'Data::Dumper' => '2.145',
      'Date::Format' => '2.24',
      'Exporter' => '5.68',
      'File::HomeDir' => '1.00',
      'File::chdir' => '0.1008',
      'HTTP::Request' => '6.00',
      'JSON' => '2.59',
      'LWP::UserAgent' => '6.05',
      'POSIX::strptime' => '0.13',
      'Scalar::Util' => '1.5',
      'Time::Local' => '1.2300',
      'constant' => '1.27',
      'parent' => '0.225',
      'strict' => '1.07',
      'vars' => '1.02',
      'warnings' => '1.13'

lib/Amazon/Credentials.pm  view on Meta::CPAN


__PACKAGE__->follow_best_practice;
__PACKAGE__->mk_accessors(qw/aws_secret_access_key aws_access_key_id token region
			     user_agent profile debug expiration role container order 
			     serialized logger
			    /);

use Data::Dumper;
use Date::Format;
use Exporter;
use HTTP::Request;
use JSON;
use LWP::UserAgent;
use POSIX::strptime qw/strptime/;
use Time::Local;
use Scalar::Util qw/reftype/;

use constant  AWS_IAM_SECURITY_CREDENTIALS_URL       => 'http://169.254.169.254/latest/meta-data/iam/security-credentials/';
use constant  AWS_AVAILABILITY_ZONE_URL              => 'http://169.254.169.254/latest/meta-data/placement/availability-zone';
use constant  AWS_CONTAINER_CREDENTIALS_URL          => 'http://169.254.170.2';

lib/Amazon/Credentials.pm  view on Meta::CPAN


sub get_default_region {
  my $self = shift;
  
  # try to get credentials from instance role, but we may not be
  # executing on an EC2 or container.
  my $url = AWS_AVAILABILITY_ZONE_URL;
  
  my $ua = ref($self) ? $self->get_user_agent : new LWP::UserAgent;

  my $req = HTTP::Request->new( GET => $url );
     
  my $region = eval {
    my $rsp = $ua->request($req);
      
    # if not 200, then get out of Dodge
    die "could not get availability zone\n"
      unless $rsp->is_success;
    
    my $region = $rsp->content;
    $region =~s/([0-9]+)[a-z]+$/$1/;

lib/Amazon/Credentials.pm  view on Meta::CPAN

  my $ua = $self->get_user_agent;
  my $role;

  eval {
    # could be infinite, but I don't think so.  Either we get an
    # error ($@), or a non-200 response code
    while ( ! $creds->{token} ) {
      
      $url .= $role if $role;
      
      my $req = HTTP::Request->new( GET => $url );
      
      $self->get_logger->debug(Dumper [ "HTTP REQUEST:\n", $req ])
	if $self->get_debug;
      
      my $rsp = $ua->request($req);
      
      $self->get_logger->debug(Dumper [ "HTTP RESPONSE:\n", $rsp ])
	if $self->get_debug;
      
      # if not 200, then get out of Dodge

lib/Amazon/Credentials.pm  view on Meta::CPAN

sub get_creds_from_container {
  my $self = shift;

  my $creds = {};
  
  if ( exists $ENV{AWS_CONTAINER_CREDENTIALS_RELATIVE_URI} ) {
    # try to get credentials from instance role
    my $url = sprintf("%s%s", AWS_CONTAINER_CREDENTIALS_URL, $ENV{AWS_CONTAINER_CREDENTIALS_RELATIVE_URI});
    
    my $ua = $self->get_user_agent;
    my $req = HTTP::Request->new( GET => $url );
    $req->header("Accept", "*/*");
    
    $self->get_logger->debug(Dumper [ "HTTP REQUEST:\n", $req ])
      if $self->get_debug;

    $self->get_logger->debug(Dumper [ $req->as_string ])
      if $self->get_debug;
    
    my $rsp = $ua->request($req);
    

t/02-credentials.t  view on Meta::CPAN

use Date::Format;
use File::Path;
use JSON;

use File::Temp qw/:mktemp/;

BEGIN {
  {
    no strict 'refs';
    
    *{'HTTP::Request::new'} = sub { bless{}, 'HTTP::Request'; };
    *{'HTTP::Request::request'} = sub { new HTTP::Response; };

    *{'HTTP::Response::new'} = sub { bless{}, 'HTTP::Response'; };
    *{'HTTP::Response::is_success'} = sub { 1; };

    *{'LWP::UserAgent::new'} = sub { bless {}, 'LWP::UserAgent'; };
    *{'LWP::UserAgent::request'} = sub { new HTTP::Response; };
  }

  use Module::Loaded;

  mark_as_loaded(HTTP::Request);
  mark_as_loaded(HTTP::Response);
  mark_as_loaded(LWP::UserAgent);

  use_ok('Amazon::Credentials');
}

my $home = mkdtemp("amz-credentials-XXXXX");

my $credentials_file = eval {
  mkdir "$home/.aws";



( run in 0.396 second using v1.01-cache-2.11-cpan-de7293f3b23 )