Skip to content

Commit 669ab53

Browse files
Gabriel Monroymboersma
authored andcommitted
feat(tests): add route53 utility for wildcard domains
1 parent e68d1ae commit 669ab53

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

tests/bin/route53-wildcard.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env python
2+
"""
3+
The route53-wildcard utility is used to add and remove wildcard
4+
DNS entries from an AWS Route53 zonefile.
5+
6+
Usage: route53-wildcard.py <action> <name> <value> [options]
7+
8+
Options:
9+
10+
--zone=<zone> name of zone to use [defaults to parsing name]
11+
--region=<region> AWS region to use [default: us-west-2].
12+
--ttl=<ttl> record TTL to use [default: 60].
13+
14+
Examples:
15+
16+
./route53-wildcard.py create mycluster.gabrtv.io deis-elb.blah.amazonaws.com
17+
./route53-wildcard.py delete mycluster.gabrtv.io deis-elb.blah.amazonaws.com
18+
"""
19+
import boto.route53
20+
import docopt
21+
import json
22+
import subprocess
23+
import time
24+
25+
26+
def parse_args():
27+
return docopt.docopt(__doc__)
28+
29+
def create_cname(args):
30+
conn = boto.route53.connect_to_region(args['--region'])
31+
zone = conn.get_zone(args['<zone>'])
32+
status = zone.add_cname(args['<name>'], args['<value>'], ttl=args['--ttl'])
33+
print("waiting for record to sync: {}".format(status))
34+
while status.update() != "INSYNC":
35+
time.sleep(2)
36+
print(status)
37+
38+
def delete_cname(args, block=False):
39+
conn = boto.route53.connect_to_region(args['--region'])
40+
zone = conn.get_zone(args['<zone>'])
41+
status = zone.delete_cname(args['<name>'])
42+
if block:
43+
print("waiting for record to sync: {}".format(status))
44+
while status.update() != "INSYNC":
45+
time.sleep(2)
46+
print(status)
47+
48+
if __name__ == '__main__':
49+
args = parse_args()
50+
51+
# calculate zone from provided name
52+
zone = '.'.join(args['<name>'].split('.')[-2:])
53+
args['<zone>'] = zone
54+
55+
# add a * to the provided name
56+
args['<name>'] = u'\\052.'+unicode(args['<name>'])
57+
58+
if args['<action>'] == 'create':
59+
create_cname(args)
60+
elif args['<action>'] == 'delete':
61+
delete_cname(args)
62+
else:
63+
raise NotImplementedError

0 commit comments

Comments
 (0)