~tribaal/txaws/xss-hardening

« back to all changes in this revision

Viewing changes to bin/txaws-get-bucket

  • Committer: Duncan McGreggor
  • Date: 2009-12-08 04:08:53 UTC
  • mfrom: (44.5.4 486365-get-bucket)
  • Revision ID: duncan@canonical.com-20091208040853-9eaw3b8cnn07z781
Merged 486365-get-bucket [r=lifeless] [f=486365]

This change adds support for the "get bucket" API call, as well as a
corresponding s3 script.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
"""
 
3
%prog [options]
 
4
"""
 
5
 
 
6
import sys
 
7
 
 
8
from txaws.credentials import AWSCredentials
 
9
from txaws.script import parse_options
 
10
from txaws.service import AWSServiceRegion
 
11
from txaws.util import reactor
 
12
 
 
13
 
 
14
def printResults(listing, bucket):
 
15
    print "Contents of '%s' bucket:" % bucket
 
16
    for item in listing.contents:
 
17
        print "\t%s (last modified on %s)" % (item.key, item.modification_date)
 
18
    print "Total items: %s\n" % len(listing.contents)
 
19
    return 0
 
20
 
 
21
 
 
22
def printError(error):
 
23
    print error.value
 
24
    return 1
 
25
 
 
26
 
 
27
def finish(return_code):
 
28
    reactor.stop(exitStatus=return_code)
 
29
 
 
30
 
 
31
options, args = parse_options(__doc__.strip())
 
32
if options.bucket is None:
 
33
    print "Error Message: A bucket name is required."
 
34
    sys.exit(1)
 
35
creds = AWSCredentials(options.access_key, options.secret_key)
 
36
region = AWSServiceRegion(
 
37
    creds=creds, region=options.region, s3_endpoint=options.url)
 
38
client = region.get_s3_client()
 
39
 
 
40
d = client.get_bucket(options.bucket)
 
41
d.addCallback(printResults, options.bucket)
 
42
d.addErrback(printError)
 
43
d.addCallback(finish)
 
44
# We use a custom reactor so that we can return the exit status from
 
45
# reactor.run().
 
46
sys.exit(reactor.run())