route53_aliaser 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +49 -20
- data/app/controllers/route53_aliaser/aliaser_controller.rb +8 -0
- data/config/routes.rb +3 -0
- data/lib/route53_aliaser/aliaser.rb +9 -6
- data/lib/route53_aliaser/configuration.rb +1 -1
- data/lib/route53_aliaser/engine.rb +5 -0
- data/lib/route53_aliaser/version.rb +1 -1
- data/lib/route53_aliaser.rb +2 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4a21547d3908c6cbfd826ee93a4106990a1981f
|
4
|
+
data.tar.gz: a04a1405caa9e0360bc58636ce59ae498d748129
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2be90ca647c63d0947cb0792288a6431b0abf1d5b4cc11b4b04067663bc634687b676444c36e88ffe597f162067b5a94490cd08e1c2d94c25200155e5bc4bcd1
|
7
|
+
data.tar.gz: c777416c75e594a442eeb918460b6648df5d61a7a52b18f812970e264f14f99fb6063209e4187c1e23d2b552fabf2ecdddef4270c81079fc3fa32f9595447162
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -21,6 +21,9 @@ This code will:
|
|
21
21
|
domain)
|
22
22
|
- If the Target and Source addresses differ, update the `target_record`
|
23
23
|
|
24
|
+
The updates are easily triggered by polling a URL in your application that is
|
25
|
+
mounted via a Rails Engine.
|
26
|
+
|
24
27
|
## Installation
|
25
28
|
|
26
29
|
Add this line to your application's Gemfile:
|
@@ -37,6 +40,8 @@ Or install it yourself as:
|
|
37
40
|
|
38
41
|
## Usage
|
39
42
|
|
43
|
+
#### With Rails
|
44
|
+
|
40
45
|
Add an initializer that looks like this:
|
41
46
|
|
42
47
|
# ./config/initializers/route53_aliaser.rb
|
@@ -47,34 +52,59 @@ Add an initializer that looks like this:
|
|
47
52
|
config.zone_id = ENV['RT53_ZONE_ID'] #Amazon Hosted Zone ID
|
48
53
|
|
49
54
|
# Only need to set these if you aren't already setting them for another AWS service
|
55
|
+
# NOTE: You'll need to use AWS IAM to add a Route 53 read/write Policy for the user/group
|
56
|
+
# associated with these credentials!
|
50
57
|
# config.aws_access_key_id = ENV['RT53_AWS_ACCESS_KEY_ID']
|
51
58
|
# config.aws_secret_access_key = ENV['RT53_AWS_SECRET_ACCESS_KEY']
|
52
59
|
end
|
53
60
|
|
61
|
+
Next, mount the Rails Engine at a URL of your choosing:
|
62
|
+
|
63
|
+
# ./config/routes.rb
|
64
|
+
mount Route53Aliaser::Engine => '/route53-update'
|
65
|
+
|
66
|
+
Finally, set up something to ping this URL occasionally:
|
67
|
+
|
68
|
+
$ curl https://example.com/route53-update
|
69
|
+
|
70
|
+
Heroku's [free scheduler](https://devcenter.heroku.com/articles/scheduler) has
|
71
|
+
an "every 10 minutes" option that'd be great for this. Just put the curl
|
72
|
+
command in there. Note that Heroku charges dyno hours for scheduled jobs; if
|
73
|
+
you're worried about this then you may prefer to use the "once an hour" option
|
74
|
+
instead.
|
75
|
+
|
76
|
+
You could also ping that URL via a free service like
|
77
|
+
[Pingdom](http://www.pingdom.com/free). Since the DNS lookups are cached, most
|
78
|
+
of the time requests to this URL will return nearly instantly.
|
79
|
+
|
80
|
+
#### Without Rails
|
81
|
+
|
82
|
+
If you're not using Rails, or if you'd like to update ad-hoc, just call
|
83
|
+
`Route53Aliaser.update_alias_if_needed` periodically. You'll of course need to
|
84
|
+
do some initialization similar to what is shown above.
|
54
85
|
|
55
|
-
|
86
|
+
### Other Options
|
56
87
|
|
57
|
-
|
88
|
+
For now, hitting the engine URL is the best option. It should keep things up
|
89
|
+
to date with minimal load on your app (since it's basically a NOOP when the
|
90
|
+
cached lookups are fresh). Please open an issue with your suggestion if you
|
91
|
+
have a better idea. Here are a couple alternatives:
|
58
92
|
|
59
93
|
- Add a `cron` job executing a Rake task.
|
60
|
-
- Create a special controller action that you load every so often via a ping
|
61
|
-
monitoring service. This controller action would act similar to a webhook in
|
62
|
-
that it would just call `Route53Aliaser.update_alias_if_needed` and return a
|
63
|
-
success code.
|
64
94
|
- Dropping `Thread.new { Route53Aliaser.update_alias_if_needed }` into a
|
65
|
-
controller action that gets called relatively frequently (say, your home
|
66
|
-
This is the #YOLO approach, but shouldn't be terribly harmful since:
|
67
|
-
is a very short-lived thread, and B) there are no real consequences
|
68
|
-
thread were suddenly killed. Note that
|
69
|
-
|
70
|
-
lookups / AWS calls might be slow & will block the request to your page.
|
95
|
+
controller action that gets called relatively frequently (say, your home
|
96
|
+
page). This is the #YOLO approach, but shouldn't be terribly harmful since:
|
97
|
+
A) this is a very short-lived thread, and B) there are no real consequences
|
98
|
+
if the thread were suddenly killed. Note that calling this in line (i.e.,
|
99
|
+
not in a separate thread) in a controller action is not recommended since
|
100
|
+
DNS lookups / AWS calls might be slow & will block the request to your page.
|
71
101
|
|
72
102
|
## Contributing
|
73
103
|
|
74
|
-
|
75
|
-
*very* welcome!
|
104
|
+
So far, this is being used against a limited number of configurations so
|
105
|
+
patches are *very* welcome!
|
76
106
|
|
77
|
-
1. Fork it ( https://github.com/
|
107
|
+
1. Fork it ( https://github.com/rdlugosz/route53_aliaser/fork )
|
78
108
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
79
109
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
80
110
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -82,13 +112,12 @@ I'm using this against a limited number of configurations so patches are
|
|
82
112
|
|
83
113
|
### Todos
|
84
114
|
|
85
|
-
1. Add some tests
|
115
|
+
1. Add some tests
|
86
116
|
1. Extract the dependency on ActiveSupport. The only thing really in use is
|
87
117
|
the caching mechanism.
|
88
118
|
1. Include support for other API-enabled DNS Hosts, e.g., Rackspace.
|
89
119
|
|
90
|
-
|
120
|
+
### Questions?
|
91
121
|
|
92
|
-
|
93
|
-
|
94
|
-
merchantability and fitness for a particular purpose.
|
122
|
+
Feel free to use the issue tracker for questions/comments or hit me up on
|
123
|
+
Twitter [@lbwski](https://twitter.com/lbwski).
|
data/config/routes.rb
ADDED
@@ -11,16 +11,19 @@ module Route53Aliaser
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def call
|
14
|
-
|
15
|
-
|
14
|
+
unless stale?
|
15
|
+
# NOOP if we haven't expired
|
16
|
+
config.logger.debug "Route53Aliaser: NOOP because cache is fresh"
|
17
|
+
return
|
18
|
+
end
|
16
19
|
|
17
20
|
target_ips = get_ips(config.target_record, config.target_key)
|
18
21
|
source_ips = get_ips(config.source_record, config.source_key)
|
19
22
|
|
20
23
|
if target_ips == source_ips
|
21
|
-
config.logger.debug "No Route 53 Update required
|
24
|
+
config.logger.debug "Route53Aliaser: No Route 53 Update required (Target IPs match the Source IPs)"
|
22
25
|
else
|
23
|
-
config.logger.info "IPs for #{config.target_record} #{target_ips} differ from #{config.source_record} #{source_ips}; will attempt to update
|
26
|
+
config.logger.info "Route53Aliaser: IPs for #{config.target_record} #{target_ips} differ from #{config.source_record} #{source_ips}; will attempt to update"
|
24
27
|
rt53 = Route53Updater.new(config)
|
25
28
|
rt53.update_target(config.target_record, source_ips, config.zone_id)
|
26
29
|
end
|
@@ -65,9 +68,9 @@ module Route53Aliaser
|
|
65
68
|
expires_in: ttl.seconds,
|
66
69
|
race_condition_ttl: 10
|
67
70
|
)
|
68
|
-
config.logger.debug "Route53Aliaser Caching #{key}: #{ips} for #{ttl} seconds (ttl)"
|
71
|
+
config.logger.debug "Route53Aliaser: Caching #{key}: #{ips} for #{ttl} seconds (ttl)"
|
69
72
|
else
|
70
|
-
config.logger.error "Route53Aliaser NOT Caching #{key} because no IPs were found."
|
73
|
+
config.logger.error "Route53Aliaser: NOT Caching #{key} because no IPs were found."
|
71
74
|
end
|
72
75
|
end
|
73
76
|
end
|
data/lib/route53_aliaser.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: route53_aliaser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Dlugosz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -93,9 +93,12 @@ files:
|
|
93
93
|
- LICENSE.txt
|
94
94
|
- README.md
|
95
95
|
- Rakefile
|
96
|
+
- app/controllers/route53_aliaser/aliaser_controller.rb
|
97
|
+
- config/routes.rb
|
96
98
|
- lib/route53_aliaser.rb
|
97
99
|
- lib/route53_aliaser/aliaser.rb
|
98
100
|
- lib/route53_aliaser/configuration.rb
|
101
|
+
- lib/route53_aliaser/engine.rb
|
99
102
|
- lib/route53_aliaser/route53_updater.rb
|
100
103
|
- lib/route53_aliaser/version.rb
|
101
104
|
- route53_aliaser.gemspec
|