~tribaal/txaws/xss-hardening

« back to all changes in this revision

Viewing changes to bin/txaws-get-bucket

  • Committer: Duncan McGreggor
  • Date: 2009-10-06 00:14:10 UTC
  • mto: This revision was merged to the branch mainline in revision 35.
  • Revision ID: duncan@canonical.com-20091006001410-5dafos89jw2nbrbq
Added testing infratructure support for availability zones.

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.reactor 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_uri=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())