Skip to content

Commit

Permalink
update s3cl: You need to use the module before you use it, added the …
Browse files Browse the repository at this point in the history
…mkbucket command, now you can run the help without your AWS secret key, add docs about the env variables you need to run s3cl (patches by Jesse Vincent)
  • Loading branch information
acme committed Mar 30, 2010
1 parent 95b94e4 commit 1383af2
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Expand Up @@ -9,6 +9,10 @@ Revision history for Perl module Net::Amazon::S3:
- fix max_keys when listing buckets (spotted by Andrew Bryan)
- add content_encoding to Net::Amazon::S3::Object (suggested
by Egor Korablev)
- update s3cl: You need to use the module before you use it,
added the mkbucket command, now you can run the help without
your AWS secret key, add docs about the env variables you need
to run s3cl (patches by Jesse Vincent)

0.52 Thu Jul 2 09:17:11 BST 2009
- increase version prerequisites for some modules so that they
Expand Down
89 changes: 61 additions & 28 deletions bin/s3cl
Expand Up @@ -4,22 +4,7 @@ use warnings;
use Getopt::Long;
use Pod::Usage;
use Path::Class;

# TODO: read key_id and secret from config file?
# use AppConfig;

# TODO: probably nicer to put all of this in Net::Amazon::S3::CommandLine
# and have simple call to that from here.

my $aws_access_key_id = $ENV{'AWS_ACCESS_KEY_ID'};
my $aws_secret_access_key = $ENV{'AWS_ACCESS_KEY_SECRET'};

my $s3 = Net::Amazon::S3->new(
{ aws_access_key_id => $aws_access_key_id,
aws_secret_access_key => $aws_secret_access_key,
retry => 1,
}
);
use Net::Amazon::S3;

=head1 NAME
Expand All @@ -30,6 +15,7 @@ s3cl - Command line for Amazon s3 cloud storage
s3cl command [options]
s3cl buckets
s3cl mkbucket --bucket some_bucket_name --jurisdiction [EU|US]
s3cl ls <bucket>:[prefix]
s3cl cp <bucket>:<key> /path/[filename]
s3cl sync <bucket>:[prefix] /path/
Expand All @@ -42,6 +28,11 @@ s3cl command [options]
We take NO responsibility for the costs incured through using
this script.
To run this script, you need to set a pair of environment variables:
AWS_ACCESS_KEY_ID
AWS_ACCESS_KEY_SECRET
=head1 DESCRIPTION
This program gives a command line interface to Amazons s3 storage
Expand All @@ -53,28 +44,52 @@ for your bill.
=cut

my $s3;

my %args;

my %commands = (
buckets => \&buckets,
ls => \&ls,
rm => \&rm,
cp => \&cp,
sync => \&sync,
help => \&helper,
mkbucket => \&mk_bucket,
buckets => \&buckets,
ls => \&ls,
rm => \&rm,
cp => \&cp,
sync => \&sync,
help => \&helper,
);

terminal();
get_options();
main();

sub main {
terminal();
get_options();
init_s3();

my $command = shift @ARGV || "help";
$commands{$command}
or helper("Unknown command: $command");
$commands{$command}->();
}

sub init_s3 {

# TODO: read key_id and secret from config file?
# use AppConfig;

# TODO: probably nicer to put all of this in Net::Amazon::S3::CommandLine
# and have simple call to that from here.

my $aws_access_key_id = $ENV{'AWS_ACCESS_KEY_ID'};
my $aws_secret_access_key = $ENV{'AWS_ACCESS_KEY_SECRET'};

$s3 = Net::Amazon::S3->new(
{ aws_access_key_id => $aws_access_key_id,
aws_secret_access_key => $aws_secret_access_key,
retry => 1,
}
);
}

sub sync {
my $dest = $args{dest} || '';
helper("No destination supplied") if $dest eq '';
Expand Down Expand Up @@ -157,6 +172,15 @@ sub rm {
}
}

sub mk_bucket {
my $bucketname = $args{bucket};
my $bucket
= $s3->add_bucket(
{ bucket => $bucketname, location_constraint => 'EU' } )
or die $s3->err . ": " . $s3->errstr;

}

sub buckets {
my $response = $s3->buckets;
my $num = scalar @{ $response->{buckets} || [] };
Expand All @@ -179,11 +203,13 @@ sub terminal {

# TODO: Replace with AppConfig this is ick!
sub get_options {
my $help = 0;
my $man = 0;
my $force = 0;
my $help = 0;
my $man = 0;
my $force = 0;
my $loc = "US";
my $bucket = "";
GetOptions(
\%args, "bucket=s",
\%args, "bucket=s", "jurisdiction=s",
"f|force" => \$force,
"h|help|?" => \$help,
"man" => \$man,
Expand Down Expand Up @@ -235,6 +261,13 @@ s3cl buckets
List all buckets for this account.
=item B<mkbucket>
s3cl mkbucket --bucket sombucketname [--jurisdiction [EU|US]]
Create a new bucket, optionally specifying what jurisdiction
it should be created in.
=item B<ls>
s3cl ls <bucket>:[prefix]
Expand Down

0 comments on commit 1383af2

Please sign in to comment.