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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f5f82836a1ef13c74c8ea8ee34e4b03adbf1bd5
4
- data.tar.gz: 4eea87944e778b4d4cd94112aa9b8e58f3e47588
3
+ metadata.gz: a4a21547d3908c6cbfd826ee93a4106990a1981f
4
+ data.tar.gz: a04a1405caa9e0360bc58636ce59ae498d748129
5
5
  SHA512:
6
- metadata.gz: 54e4b74a04201d403e573c9d58ce4f13ee6237356e7f788aec3d66d299bebcfb151844c567a9cb3bc7bd51b277c0ac1d1397baa9e68f7f26a605b6ce4ef9dabb
7
- data.tar.gz: de24589f9f8feef46adc4f245cbfcdefe262598ced7a9d9e980a5a05e2e72e8ee06ba9d4f5285358509c38426d3f1dea0e9299e4dabeb08c86bba5bb3f1f6d71
6
+ metadata.gz: 2be90ca647c63d0947cb0792288a6431b0abf1d5b4cc11b4b04067663bc634687b676444c36e88ffe597f162067b5a94490cd08e1c2d94c25200155e5bc4bcd1
7
+ data.tar.gz: c777416c75e594a442eeb918460b6648df5d61a7a52b18f812970e264f14f99fb6063209e4187c1e23d2b552fabf2ecdddef4270c81079fc3fa32f9595447162
data/CHANGELOG.md CHANGED
@@ -1,2 +1,6 @@
1
+ # Route53Aliaser 0.0.2
2
+ - add Rails Engine support
3
+ - use Rails.cache when Rails is defined
4
+
1
5
  # Route53Aliaser 0.0.1
2
6
  - initial release
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
- Then, just call `Route53Aliaser.update_alias_if_needed` periodically.
86
+ ### Other Options
56
87
 
57
- Not sure what the best approach is for this yet, but here are a few ideas:
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 page).
66
- This is the #YOLO approach, but shouldn't be terribly harmful since: A) this
67
- is a very short-lived thread, and B) there are no real consequences if the
68
- thread were suddenly killed. Note that I would not recommend calling this in
69
- line (i.e., not in a separate thread) in a controller action since DNS
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
- I'm using this against a limited number of configurations so patches are
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/[my-github-username]/route53_aliaser/fork )
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! *(Yes, I feel dirty.)*
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
- ## Warranty
120
+ ### Questions?
91
121
 
92
- This software is provided “as is” and without any express or implied
93
- warranties, including, without limitation, the implied warranties of
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).
@@ -0,0 +1,8 @@
1
+ module Route53Aliaser
2
+ class AliaserController < ActionController::Base
3
+ def update
4
+ Route53Aliaser.update_alias_if_needed
5
+ head :ok
6
+ end
7
+ end
8
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Route53Aliaser::Engine.routes.draw do
2
+ root to: 'aliaser#update', via: [:get, :head]
3
+ end
@@ -11,16 +11,19 @@ module Route53Aliaser
11
11
  end
12
12
 
13
13
  def call
14
- # NOOP if we haven't expired
15
- return unless stale?
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
@@ -5,7 +5,7 @@ module Route53Aliaser
5
5
 
6
6
  def initialize
7
7
  @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
8
- @cache = ActiveSupport::Cache::MemoryStore.new
8
+ @cache = defined?(Rails) ? Rails.cache : ActiveSupport::Cache::MemoryStore.new
9
9
  end
10
10
 
11
11
  def target_key
@@ -0,0 +1,5 @@
1
+ module Route53Aliaser
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Route53Aliaser
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Route53Aliaser
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -3,6 +3,8 @@ require "route53_aliaser/configuration"
3
3
  require "route53_aliaser/route53_updater"
4
4
  require "route53_aliaser/aliaser"
5
5
 
6
+ require "route53_aliaser/engine" if defined?(Rails)
7
+
6
8
  require "resolv"
7
9
 
8
10
  require "aws-sdk"
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.1
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-03 00:00:00.000000000 Z
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