Skip to content

Commit

Permalink
check for invalid regions
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfharing committed Feb 19, 2014
1 parent cd63f92 commit d2ac8da
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bin/cq
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def main():
region = a
if region:
c = boto.sqs.connect_to_region(region)
if c is None:
print 'Invalid region (%s)' % region
sys.exit(1)
else:
c = SQSConnection()
if queue_name:
Expand Down
6 changes: 6 additions & 0 deletions bin/elbadmin
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def list(elb):
for b in elb.get_all_load_balancers():
print "%-20s %s" % (b.name, b.dns_name)

def check_valid_region(conn, region):
if conn is None:
print 'Invalid region (%s)' % region
sys.exit(1)

def get(elb, name):
"""Get details about ELB <name>"""
Expand Down Expand Up @@ -113,6 +117,7 @@ def get(elb, name):
ec2 = boto.connect_ec2()
else:
ec2 = boto.ec2.connect_to_region(options.region)
check_valid_region(ec2, options.region)

instance_health = b.get_instance_health()
instances = [state.instance_id for state in instance_health]
Expand Down Expand Up @@ -255,6 +260,7 @@ if __name__ == "__main__":
else:
import boto.ec2.elb
elb = boto.ec2.elb.connect_to_region(options.region)
check_valid_region(elb, options.region)

print "%s" % (elb.region.endpoint)

Expand Down
6 changes: 6 additions & 0 deletions bin/s3put
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ def _upload_part(bucketname, aws_key, aws_secret, multipart_id, part_num,

_upload()

def check_valid_region(conn, region):
if conn is None:
print 'Invalid region (%s)' % region
sys.exit(1)

def multipart_upload(bucketname, aws_key, aws_secret, source_path, keyname,
reduced, debug, cb, num_cb, acl='private', headers={},
Expand All @@ -183,6 +187,7 @@ def multipart_upload(bucketname, aws_key, aws_secret, source_path, keyname,
"""
conn = boto.s3.connect_to_region(region, aws_access_key_id=aws_key,
aws_secret_access_key=aws_secret)
check_valid_region(conn, region)
conn.debug = debug
bucket = conn.get_bucket(bucketname)

Expand Down Expand Up @@ -334,6 +339,7 @@ def main():
connect_args['host'] = host

c = boto.s3.connect_to_region(region or DEFAULT_REGION, **connect_args)
check_valid_region(c, region or DEFAULT_REGION)
c.debug = debug
b = c.get_bucket(bucket_name, validate=False)

Expand Down
7 changes: 7 additions & 0 deletions bin/sdbadmin
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,19 @@ def load_db(domain, file, use_json=False):
else:
domain.from_xml(file)

def check_valid_region(conn, region):
if conn is None:
print 'Invalid region (%s)' % region
sys.exit(1)

def create_db(domain_name, region_name):
"""Create a new DB
:param domain: Name of the domain to create
:type domain: str
"""
sdb = boto.sdb.connect_to_region(region_name)
check_valid_region(sdb, region_name)
return sdb.create_domain(domain_name)

if __name__ == "__main__":
Expand Down Expand Up @@ -125,6 +131,7 @@ if __name__ == "__main__":
exit()

sdb = boto.sdb.connect_to_region(options.region_name)
check_valid_region(sdb, options.region_name)
if options.list:
for db in sdb.get_all_domains():
print db
Expand Down

0 comments on commit d2ac8da

Please sign in to comment.