Created
August 6, 2009 01:57
-
-
Save tokuhirom/163086 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From aa6e56cc12ae0f4bc61f6c8bdcca9ab717d52ae4 Mon Sep 17 00:00:00 2001 | |
From: Tokuhiro Matsuno <tokuhirom@gmail.com> | |
Date: Wed, 5 Aug 2009 17:08:09 +0900 | |
Subject: [PATCH 1/3] customizable host | |
--- | |
lib/Amazon/S3.pm | 8 +++++--- | |
1 files changed, 5 insertions(+), 3 deletions(-) | |
diff --git a/lib/Amazon/S3.pm b/lib/Amazon/S3.pm | |
index 799e365..1ddc0f7 100644 | |
--- a/lib/Amazon/S3.pm | |
+++ b/lib/Amazon/S3.pm | |
@@ -13,7 +13,7 @@ use XML::Simple; | |
use base qw(Class::Accessor::Fast); | |
__PACKAGE__->mk_accessors( | |
- qw(aws_access_key_id aws_secret_access_key secure ua err errstr timeout retry) | |
+ qw(aws_access_key_id aws_secret_access_key secure ua err errstr timeout retry host) | |
); | |
our $VERSION = '0.441'; | |
@@ -30,6 +30,7 @@ sub new { | |
$self->secure(0) if not defined $self->secure; | |
$self->timeout(30) if not defined $self->timeout; | |
+ $self->host('s3.amazonaws.com') if not defined $self->host; | |
my $ua; | |
if ($self->retry) { | |
@@ -260,9 +261,10 @@ sub _make_request { | |
$self->_add_auth_header($http_headers, $method, $path) | |
unless exists $headers->{Authorization}; | |
my $protocol = $self->secure ? 'https' : 'http'; | |
- my $url = "$protocol://s3.amazonaws.com/$path"; | |
+ my $host = $self->host; | |
+ my $url = "$protocol://$host/$path"; | |
if ($path =~ m{^([^/?]+)(.*)} && _is_dns_bucket($1)) { | |
- $url = "$protocol://$1.s3.amazonaws.com$2"; | |
+ $url = "$protocol://$1.$host$2"; | |
} | |
my $request = HTTP::Request->new($method, $url, $http_headers); | |
-- | |
1.6.1.2 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From ee3b4fc7dc3cb1cf351f1d6f0688d35da2507a7d Mon Sep 17 00:00:00 2001 | |
From: Tokuhiro Matsuno <tokuhirom@gmail.com> | |
Date: Wed, 5 Aug 2009 17:23:45 +0900 | |
Subject: [PATCH 2/3] do not die with no buckets | |
--- | |
lib/Amazon/S3.pm | 22 ++++++++++++---------- | |
1 files changed, 12 insertions(+), 10 deletions(-) | |
diff --git a/lib/Amazon/S3.pm b/lib/Amazon/S3.pm | |
index 1ddc0f7..19239ec 100644 | |
--- a/lib/Amazon/S3.pm | |
+++ b/lib/Amazon/S3.pm | |
@@ -64,16 +64,18 @@ sub buckets { | |
my $owner_displayname = $r->{Owner}{DisplayName}; | |
my @buckets; | |
- foreach my $node (@{$r->{Buckets}{Bucket}}) { | |
- push @buckets, | |
- Amazon::S3::Bucket->new( | |
- { | |
- bucket => $node->{Name}, | |
- creation_date => $node->{CreationDate}, | |
- account => $self, | |
- } | |
- ); | |
+ if (ref $r->{Buckets}) { | |
+ foreach my $node (@{$r->{Buckets}{Bucket}}) { | |
+ push @buckets, | |
+ Amazon::S3::Bucket->new( | |
+ { | |
+ bucket => $node->{Name}, | |
+ creation_date => $node->{CreationDate}, | |
+ account => $self, | |
+ } | |
+ ); | |
+ } | |
} | |
return { | |
owner_id => $owner_id, | |
-- | |
1.6.1.2 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From e7bac351c0a09bfdc51bbcb04da5ca9f1b3098f8 Mon Sep 17 00:00:00 2001 | |
From: Tokuhiro Matsuno <tokuhirom@gmail.com> | |
Date: Wed, 5 Aug 2009 18:18:26 +0900 | |
Subject: [PATCH 3/3] work with only one bucket =) | |
--- | |
lib/Amazon/S3.pm | 18 ++++++++++-------- | |
1 files changed, 10 insertions(+), 8 deletions(-) | |
diff --git a/lib/Amazon/S3.pm b/lib/Amazon/S3.pm | |
index 19239ec..4cd67fb 100644 | |
--- a/lib/Amazon/S3.pm | |
+++ b/lib/Amazon/S3.pm | |
@@ -65,15 +65,17 @@ sub buckets { | |
my @buckets; | |
if (ref $r->{Buckets}) { | |
- foreach my $node (@{$r->{Buckets}{Bucket}}) { | |
+ my $buckets = $r->{Buckets}{Bucket}; | |
+ $buckets = [$buckets] unless ref $buckets eq 'ARRAY'; | |
+ foreach my $node (@$buckets) { | |
push @buckets, | |
- Amazon::S3::Bucket->new( | |
- { | |
- bucket => $node->{Name}, | |
- creation_date => $node->{CreationDate}, | |
- account => $self, | |
- } | |
- ); | |
+ Amazon::S3::Bucket->new( | |
+ { | |
+ bucket => $node->{Name}, | |
+ creation_date => $node->{CreationDate}, | |
+ account => $self, | |
+ } | |
+ ); | |
} | |
} | |
-- | |
1.6.1.2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment