Skip to content

Commit d2ac8da

Browse files
committed
check for invalid regions
1 parent cd63f92 commit d2ac8da

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

bin/cq

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ def main():
5757
region = a
5858
if region:
5959
c = boto.sqs.connect_to_region(region)
60+
if c is None:
61+
print 'Invalid region (%s)' % region
62+
sys.exit(1)
6063
else:
6164
c = SQSConnection()
6265
if queue_name:

bin/elbadmin

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ def list(elb):
7272
for b in elb.get_all_load_balancers():
7373
print "%-20s %s" % (b.name, b.dns_name)
7474

75+
def check_valid_region(conn, region):
76+
if conn is None:
77+
print 'Invalid region (%s)' % region
78+
sys.exit(1)
7579

7680
def get(elb, name):
7781
"""Get details about ELB <name>"""
@@ -113,6 +117,7 @@ def get(elb, name):
113117
ec2 = boto.connect_ec2()
114118
else:
115119
ec2 = boto.ec2.connect_to_region(options.region)
120+
check_valid_region(ec2, options.region)
116121

117122
instance_health = b.get_instance_health()
118123
instances = [state.instance_id for state in instance_health]
@@ -255,6 +260,7 @@ if __name__ == "__main__":
255260
else:
256261
import boto.ec2.elb
257262
elb = boto.ec2.elb.connect_to_region(options.region)
263+
check_valid_region(elb, options.region)
258264

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

bin/s3put

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ def _upload_part(bucketname, aws_key, aws_secret, multipart_id, part_num,
173173

174174
_upload()
175175

176+
def check_valid_region(conn, region):
177+
if conn is None:
178+
print 'Invalid region (%s)' % region
179+
sys.exit(1)
176180

177181
def multipart_upload(bucketname, aws_key, aws_secret, source_path, keyname,
178182
reduced, debug, cb, num_cb, acl='private', headers={},
@@ -183,6 +187,7 @@ def multipart_upload(bucketname, aws_key, aws_secret, source_path, keyname,
183187
"""
184188
conn = boto.s3.connect_to_region(region, aws_access_key_id=aws_key,
185189
aws_secret_access_key=aws_secret)
190+
check_valid_region(conn, region)
186191
conn.debug = debug
187192
bucket = conn.get_bucket(bucketname)
188193

@@ -334,6 +339,7 @@ def main():
334339
connect_args['host'] = host
335340

336341
c = boto.s3.connect_to_region(region or DEFAULT_REGION, **connect_args)
342+
check_valid_region(c, region or DEFAULT_REGION)
337343
c.debug = debug
338344
b = c.get_bucket(bucket_name, validate=False)
339345

bin/sdbadmin

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,19 @@ def load_db(domain, file, use_json=False):
9090
else:
9191
domain.from_xml(file)
9292

93+
def check_valid_region(conn, region):
94+
if conn is None:
95+
print 'Invalid region (%s)' % region
96+
sys.exit(1)
97+
9398
def create_db(domain_name, region_name):
9499
"""Create a new DB
95100
96101
:param domain: Name of the domain to create
97102
:type domain: str
98103
"""
99104
sdb = boto.sdb.connect_to_region(region_name)
105+
check_valid_region(sdb, region_name)
100106
return sdb.create_domain(domain_name)
101107

102108
if __name__ == "__main__":
@@ -125,6 +131,7 @@ if __name__ == "__main__":
125131
exit()
126132

127133
sdb = boto.sdb.connect_to_region(options.region_name)
134+
check_valid_region(sdb, options.region_name)
128135
if options.list:
129136
for db in sdb.get_all_domains():
130137
print db

0 commit comments

Comments
 (0)