~tribaal/txaws/xss-hardening

44.3.4 by Duncan McGreggor
* Added a script option for bucket name.
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
55.1.2 by Paul Hummer
Used the new txaws.reactor module.
11
from txaws.reactor import reactor
44.3.4 by Duncan McGreggor
* Added a script option for bucket name.
12
13
14
def printResults(results):
15
    return 0
16
17
18
def printError(error):
19
    print error.value
20
    return 1
21
22
23
def finish(return_code):
24
    reactor.stop(exitStatus=return_code)
25
26
27
options, args = parse_options(__doc__.strip())
28
if options.bucket is None:
29
    print "Error Message: A bucket name is required."
30
    sys.exit(1)
31
creds = AWSCredentials(options.access_key, options.secret_key)
32
region = AWSServiceRegion(
78.1.1 by Gustavo Niemeyer
s/s3_endpoint/s3_uri/ in bin/*
33
    creds=creds, region=options.region, s3_uri=options.url)
44.3.4 by Duncan McGreggor
* Added a script option for bucket name.
34
client = region.get_s3_client()
35
36
d = client.create_bucket(options.bucket)
37
d.addCallback(printResults)
38
d.addErrback(printError)
39
d.addCallback(finish)
40
# We use a custom reactor so that we can return the exit status from
41
# reactor.run().
42
sys.exit(reactor.run())