dynamic_53 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6e34de7925e2085889ace31594a9fa4d48c7c331
4
+ data.tar.gz: d2b767328cd595de21553d0866aa5b3b49242c4f
5
+ SHA512:
6
+ metadata.gz: 3c1e43d841ff94ba97c6938286ff960e4efbdd9da644c23a702680f66d99908b2534220cebd414738b2c7c5deb7da43b194a4536913c34a9566cb6e5b352aad5
7
+ data.tar.gz: f6d477c106f5d50dc10ce1b40aabd30f10fc8634a341947b42e2dc998716b7db899a9ef651a6464c498b59904ba7eadbf553028e3c1883ae9c529347c2174a65
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ # Rubymine:
20
+ .idea/
21
+
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dynamic_53.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Matt Connolly
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Dynamic53
2
+
3
+ A simple tool to update Amazon Route 53 with based on your current IP Address.
4
+
5
+ Requirements:
6
+
7
+ * An amazon account with a zone created in route 53.
8
+ * AWS credentials with access to update Route 53.
9
+ * Access to internet. :)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'dynamic_53'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install dynamic_53
24
+
25
+ ## Usage
26
+
27
+ Run the command as following:
28
+
29
+ $ dynamic_53 -z example.com. -h dynamic.example.com.
30
+
31
+ This will update the host "dynamic.example.com." within the route 53 zone "example.com." with you current IP address.
32
+
33
+ Note that AWS credentials are expected to be provided in the environment variables `AWS_ACCESS_KEY_ID` and
34
+ `AWS_SECRET_ACCESS_KEY`. Refer to Amazon Web Services console to create a user with the credentials to make updates
35
+ in Route 53.
36
+
37
+ ## Development
38
+
39
+ Use `rake` to run tests.
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( http://github.com/<my-github-username>/dynamic_53/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
data/bin/dynamic_53 ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.expand_path("../../lib", __FILE__))
4
+ require 'dynamic_53'
5
+ require 'dynamic_53/cli'
6
+
7
+ Dynamic53::CLI.new(ARGV).run
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dynamic_53/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dynamic_53"
8
+ spec.version = Dynamic53::VERSION
9
+ spec.authors = ["Matt Connolly"]
10
+ spec.email = ["matt.connolly@me.com"]
11
+ spec.summary = %q{A simple tool to update Amazon Route 53 with based on your current IP Address.}
12
+ spec.description = %q{A simple tool to update Amazon Route 53 with based on your current IP Address.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "aws-sdk", "~> 1.38.0"
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ end
data/lib/dynamic_53.rb ADDED
@@ -0,0 +1,59 @@
1
+ require "dynamic_53/version"
2
+ require "aws-sdk"
3
+ require "net/http"
4
+
5
+ class Dynamic53
6
+
7
+ DEFAULT_TTL = 3600 # 1 hour
8
+
9
+ attr :zone
10
+ attr :hostname
11
+ attr :options
12
+
13
+ # Initializes an object for updating the Route 53 hostname with the machine's
14
+ # current public IP address.
15
+ def initialize(zone, hostname, options={})
16
+ @zone = zone
17
+ @hostname = hostname
18
+ @options = options
19
+ end
20
+
21
+ # perform the Route 53 update, returning the AWS SDK changelist object for the change.
22
+ def update
23
+ record_set.ttl = options[:ttl] || DEFAULT_TTL
24
+ record_set.resource_records = [{:value => ip_address}]
25
+ result = record_set.update
26
+ $stdout.puts "Record updated" if options[:verbose]
27
+ result
28
+ end
29
+
30
+ # fetch the current machine's public IP address.
31
+ def ip_address
32
+ @ip_address ||=
33
+ begin
34
+ ip_address = Net::HTTP.get("bot.whatismyipaddress.com", "/")
35
+ $stdout.puts "Public IP Address: #{ip_address}" if options[:verbose]
36
+ ip_address
37
+ end
38
+ end
39
+
40
+ # Fetches the AWS Route53 zone id for the specified zone.
41
+ def zone_id
42
+ route_53_client.
43
+ list_hosted_zones[:hosted_zones].
44
+ each.
45
+ select { |z| z[:name] == zone }.
46
+ map {|z| z[:id] }.
47
+ first
48
+ end
49
+
50
+ # Fetch a record set object for the given hostname in the Route 53 zone specified.
51
+ def record_set
52
+ @record_set ||= AWS::Route53::HostedZone.new(zone_id).rrsets[hostname, 'A']
53
+ end
54
+
55
+ # A client for making Route 53 API requests.
56
+ def route_53_client
57
+ @route_53_client ||= AWS::Route53.new.client
58
+ end
59
+ end
@@ -0,0 +1,45 @@
1
+ require 'optparse'
2
+
3
+ class Dynamic53::CLI
4
+ attr :options
5
+
6
+ def initialize(argv)
7
+ @argv = argv
8
+ @options = {}
9
+ end
10
+
11
+ def parse_options!
12
+ parser = options_parser
13
+ parser.parse!(@argv)
14
+
15
+ unless options[:hostname] && options[:zone]
16
+ $stderr.puts "Error: both zone and hostname arguments must be provided."
17
+ $stderr.puts parser.banner
18
+ exit(1)
19
+ end
20
+ end
21
+
22
+ def run
23
+ parse_options!
24
+ Dynamic53.new(options.delete(:zone), options.delete(:hostname), options).update
25
+ end
26
+
27
+ private
28
+
29
+ def options_parser
30
+ @options_parser ||= OptionParser.new do |opts|
31
+ opts.banner = "Usage: dynamic_53 -z zone -h hostname [options]"
32
+
33
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
34
+ options[:verbose] = v
35
+ end
36
+ opts.on("-z ZONE", "--zone ZONE", "Use the given zone ZONE in AWS Route53") do |arg|
37
+ options[:zone] = arg
38
+ end
39
+ opts.on("-h HOSTNAME", "--hostname HOSTNAME",
40
+ "Updates the IP address for the name HOSTNAME to the current machine's public IP address") do |arg|
41
+ options[:hostname] = arg
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ class Dynamic53
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'dynamic_53/cli'
3
+
4
+ describe Dynamic53::CLI do
5
+ let(:args) { [] }
6
+ subject { Dynamic53::CLI.new(args) }
7
+ context "#parse_options!" do
8
+ context "with required arguments" do
9
+ let(:args) { %w[-z my_zone -h my_host] }
10
+ it do
11
+ subject.parse_options!
12
+ expect(subject.options[:zone]).to eq("my_zone")
13
+ end
14
+ it do
15
+ subject.parse_options!
16
+ expect(subject.options[:hostname]).to eq("my_host")
17
+ end
18
+ end
19
+ context "--wrong" do
20
+ let(:args) { %w[--wrong] }
21
+ it { expect { subject.parse_options! }.to raise_error }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dynamic53 do
4
+
5
+ let(:zone) { "example.com." }
6
+ let(:hostname) { "dynamic.example.com." }
7
+ subject { Dynamic53.new zone, hostname }
8
+
9
+ it "has a version" do
10
+ expect(Dynamic53::VERSION).not_to be_nil
11
+ end
12
+
13
+ context "#ip_address" do
14
+ it "calls Net::HTTP.get" do
15
+ Net::HTTP.should_receive(:get).and_return("1.2.3.4")
16
+ expect(subject.ip_address).to match(/\d+\.\d+\.\d+\.\d+/)
17
+ end
18
+ end
19
+
20
+ context "fetching zone_id" do
21
+ let(:client) { double("client", :list_hosted_zones => {:hosted_zones => [{:id => "/some/id", :name => zone}]}) }
22
+ before { subject.stub(:route_53_client).and_return(client) }
23
+ it "fetches the zone id" do
24
+ expect(subject.zone_id).to eq("/some/id")
25
+ end
26
+ end
27
+
28
+ context "record_set" do
29
+ let(:record_set) { double("record_set") }
30
+ let(:rrsets) { double("rrsets", :[] => record_set)}
31
+ let(:record_sets) { double("record sets", :rrsets => rrsets)}
32
+ it do
33
+ subject.stub(:zone_id => "/some/id")
34
+ AWS::Route53::HostedZone.should_receive(:new).with("/some/id").and_return(record_sets)
35
+ expect(subject.record_set).to eq(record_set)
36
+ end
37
+ end
38
+
39
+ context "update" do
40
+ let(:record_set) { double("record set") }
41
+ it do
42
+ subject.stub(:ip_address => "1.2.3.4")
43
+ subject.stub(:record_set => record_set)
44
+ record_set.should_receive(:ttl=).with(Dynamic53::DEFAULT_TTL)
45
+ record_set.should_receive(:resource_records=).with([{:value => "1.2.3.4"}])
46
+ record_set.should_receive(:update)
47
+ subject.update
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,19 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
18
+
19
+ require 'dynamic_53'
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dynamic_53
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matt Connolly
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.38.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.38.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A simple tool to update Amazon Route 53 with based on your current IP
70
+ Address.
71
+ email:
72
+ - matt.connolly@me.com
73
+ executables:
74
+ - dynamic_53
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/dynamic_53
85
+ - dynamic_53.gemspec
86
+ - lib/dynamic_53.rb
87
+ - lib/dynamic_53/cli.rb
88
+ - lib/dynamic_53/version.rb
89
+ - spec/dynamic_53/cli_spec.rb
90
+ - spec/dynamic_53_spec.rb
91
+ - spec/spec_helper.rb
92
+ homepage: ''
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.2.2
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: A simple tool to update Amazon Route 53 with based on your current IP Address.
116
+ test_files:
117
+ - spec/dynamic_53/cli_spec.rb
118
+ - spec/dynamic_53_spec.rb
119
+ - spec/spec_helper.rb