From d2ac8da3a698287e5687d03002e7d3bc524fd616 Mon Sep 17 00:00:00 2001 From: Ralf Haring Date: Tue, 18 Feb 2014 22:11:57 -0500 Subject: [PATCH] check for invalid regions --- bin/cq | 3 +++ bin/elbadmin | 6 ++++++ bin/s3put | 6 ++++++ bin/sdbadmin | 7 +++++++ 4 files changed, 22 insertions(+) diff --git a/bin/cq b/bin/cq index 242d0d2564..05bc95b9ca 100755 --- a/bin/cq +++ b/bin/cq @@ -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: diff --git a/bin/elbadmin b/bin/elbadmin index 816c7327f0..d83643f037 100755 --- a/bin/elbadmin +++ b/bin/elbadmin @@ -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 """ @@ -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] @@ -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) diff --git a/bin/s3put b/bin/s3put index 9d487f9f58..0a2088d3d2 100755 --- a/bin/s3put +++ b/bin/s3put @@ -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={}, @@ -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) @@ -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) diff --git a/bin/sdbadmin b/bin/sdbadmin index 8b072cc4ed..9e2448c531 100755 --- a/bin/sdbadmin +++ b/bin/sdbadmin @@ -90,6 +90,11 @@ 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 @@ -97,6 +102,7 @@ def create_db(domain_name, region_name): :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__": @@ -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