├── .ruby-gemset ├── .ruby-version ├── .rspec ├── .gitignore ├── lib ├── route53 │ ├── version.rb │ ├── dns_record.rb │ ├── connection.rb │ ├── aws_response.rb │ ├── zone.rb │ └── cli.rb └── route53.rb ├── spec ├── lib │ └── route53 │ │ ├── dns_record_spec.rb │ │ ├── aws_response_spec.rb │ │ ├── zone_spec.rb │ │ └── connection_spec.rb ├── spec_helper.rb └── fixtures │ └── vcr_cassettes │ ├── aws_zones.yml │ ├── aws_zone_delete.yml │ ├── aws_zone.yml │ └── aws_zone_records.yml ├── Rakefile ├── .travis.yml ├── bin └── route53 ├── Gemfile ├── route53.gemspec ├── README.markdown └── LICENSE /.ruby-gemset: -------------------------------------------------------------------------------- 1 | route53 2 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | ruby-2.0.0-p353 2 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --format progress 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | pkg 2 | route53-*.gem 3 | Gemfile.lock 4 | .bundle 5 | -------------------------------------------------------------------------------- /lib/route53/version.rb: -------------------------------------------------------------------------------- 1 | module Route53 2 | VERSION = "0.4.0" 3 | end 4 | -------------------------------------------------------------------------------- /spec/lib/route53/dns_record_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Route53::DNSRecord do 4 | end 5 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rspec/core/rake_task' 2 | 3 | RSpec::Core::RakeTask.new(:spec) 4 | 5 | task :default => :spec 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 1.9.3 4 | - 2.0.0 5 | - 2.1 6 | - 2.2 7 | - 2.3 8 | - 2.4 9 | - 2.5 10 | - 2.6 11 | before_install: 12 | - gem update bundler 13 | -------------------------------------------------------------------------------- /spec/lib/route53/aws_response_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Route53::AWSResponse do 4 | describe "#initialize" 5 | describe "#error?" 6 | describe "#error_message" 7 | describe "#helpful_message" 8 | describe "#complete?" 9 | describe "#pending?" 10 | end 11 | -------------------------------------------------------------------------------- /bin/route53: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | lib = File.expand_path(File.dirname(__FILE__) + '/../lib') 4 | $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib) 5 | 6 | require 'route53' 7 | require 'route53/cli' 8 | require 'route53/version' 9 | 10 | app = Route53::CLI.new(ARGV, STDIN) 11 | app.run 12 | -------------------------------------------------------------------------------- /lib/route53.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'hmac' 3 | require 'hmac-sha2' 4 | require 'base64' 5 | require 'time' 6 | require 'net/http' 7 | require 'net/https' 8 | require 'uri' 9 | require 'nokogiri' 10 | require 'builder' 11 | require 'digest/md5' 12 | require 'route53/connection' 13 | require 'route53/zone' 14 | require 'route53/aws_response' 15 | require 'route53/dns_record' 16 | 17 | module Route53 18 | end 19 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | 5 | gem 'nokogiri', '~> 1.5.10' if RUBY_VERSION.start_with? '1.8' 6 | gem 'nokogiri', '~> 1.6.0' if RUBY_VERSION.start_with? '2.0' 7 | gem 'nokogiri', '~> 1.6.0' if RUBY_VERSION.start_with? '1.9' 8 | 9 | group :development do 10 | gem 'rake', '< 12.0' if RUBY_VERSION.start_with? '1.9' 11 | gem 'rake', '< 11.0' if RUBY_VERSION.start_with? '1.8' 12 | gem 'vcr', '< 3' if RUBY_VERSION.start_with? '1.8' 13 | end 14 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'route53' 2 | require 'vcr' 3 | require 'webmock/rspec' 4 | 5 | VCR.configure do |c| 6 | c.cassette_library_dir = 'spec/fixtures/vcr_cassettes' 7 | c.hook_into :webmock 8 | end 9 | 10 | RSpec.configure do |config| 11 | config.run_all_when_everything_filtered = true 12 | config.filter_run :focus 13 | config.order = 'random' 14 | config.mock_with :rspec do |mocks| 15 | mocks.syntax = :should 16 | end 17 | end 18 | 19 | def credentials(key) 20 | credentials_file = File.join(ENV['HOME'], '.route53') 21 | File.exist?(credentials_file) ? YAML.load_file(credentials_file)[key] : '' 22 | end 23 | -------------------------------------------------------------------------------- /route53.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | require File.expand_path("../lib/route53/version", __FILE__) 3 | 4 | Gem::Specification.new do |s| 5 | s.name = "route53" 6 | s.version = Route53::VERSION 7 | s.platform = Gem::Platform::RUBY 8 | s.authors = "Philip Corliss" 9 | s.email = 'pcorlis@50projects.com' 10 | s.homepage = 'http://github.com/pcorliss/ruby_route_53' 11 | s.summary = "Library for Amazon's Route 53 service" 12 | s.description = "Provides CRUD and list operations for records and zones as part of Amazon's Route 53 service." 13 | 14 | s.required_rubygems_version = ">= 1.3.5" 15 | 16 | s.add_dependency "ruby-hmac" 17 | s.add_dependency "nokogiri" 18 | s.add_dependency "builder" 19 | 20 | s.add_development_dependency "rspec", "~> 3.0" 21 | s.add_development_dependency "vcr" 22 | s.add_development_dependency "webmock", '~> 2.3.2' 23 | # addressable 2.5 requires public_suffix 2.0.4 which doesn't support older versions of ruby 24 | s.add_development_dependency "addressable", '~> 2.4.0' 25 | s.add_development_dependency "pry" 26 | s.add_development_dependency "wirble" 27 | s.add_development_dependency "rake" 28 | 29 | s.files = `git ls-files`.split("\n") 30 | s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact 31 | s.require_path = 'lib' 32 | end 33 | -------------------------------------------------------------------------------- /spec/fixtures/vcr_cassettes/aws_zones.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: head 5 | uri: https://route53.amazonaws.com/date 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept: 11 | - '*/*' 12 | User-Agent: 13 | - Ruby 14 | response: 15 | status: 16 | code: 200 17 | message: OK 18 | headers: 19 | X-Amzn-Requestid: 20 | - 67ee6ab3-879d-11e3-98d7-73059d19e8a2 21 | Content-Type: 22 | - content/unknown 23 | Content-Length: 24 | - '2' 25 | Date: 26 | - Mon, 27 Jan 2014 21:53:06 GMT 27 | body: 28 | encoding: UTF-8 29 | string: '' 30 | http_version: 31 | recorded_at: Mon, 27 Jan 2014 21:53:07 GMT 32 | - request: 33 | method: get 34 | uri: https://route53.amazonaws.com/2012-12-12/hostedzone 35 | body: 36 | encoding: US-ASCII 37 | string: '' 38 | headers: 39 | Date: 40 | - Mon, 27 Jan 2014 21:53:06 GMT 41 | X-Amzn-Authorization: 42 | - AWS3-HTTPS AWSAccessKeyId=AKIAIK7CBPSH72TVCGBA,Algorithm=HmacSHA256,Signature=R4f+9b2CnE/AEx6CPlvMGM3plJr4rgYZo8VLw2ZaIMc= 43 | Content-Type: 44 | - text/xml; charset=UTF-8 45 | Accept-Encoding: 46 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 47 | Accept: 48 | - '*/*' 49 | User-Agent: 50 | - Ruby 51 | response: 52 | status: 53 | code: 200 54 | message: OK 55 | headers: 56 | X-Amzn-Requestid: 57 | - 680b684c-879d-11e3-8adc-c709b31246ca 58 | Content-Type: 59 | - text/xml 60 | Content-Length: 61 | - '401' 62 | Date: 63 | - Mon, 27 Jan 2014 21:53:06 GMT 64 | body: 65 | encoding: UTF-8 66 | string: |- 67 | 68 | /hostedzone/Z3HXUG22R8JWBK50projects.com.a9f6b14e22false100 69 | http_version: 70 | recorded_at: Mon, 27 Jan 2014 21:53:07 GMT 71 | recorded_with: VCR 2.8.0 72 | -------------------------------------------------------------------------------- /spec/lib/route53/zone_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Route53::Zone do 4 | let(:conn) { 5 | Route53::Connection.new( 6 | credentials('access_key'), 7 | credentials('secret_key') 8 | ) 9 | } 10 | let(:sample_zone) { Route53::Zone.new("50projects.com.", "/hostedzone/Z3HXUG22R8JWBK", conn) } 11 | 12 | describe "#initialize" do 13 | it "auto sets the name to end with a '.'" do 14 | zone = Route53::Zone.new('foo', '/hostedzone/bar', conn) 15 | expect(zone.name).to eq('foo.') 16 | end 17 | end 18 | 19 | describe "#nameservers" do 20 | it "returns the name servers assigned to a zone" do 21 | VCR.use_cassette("aws_zone", :record => :none) do 22 | expected_nameservers = ["ns-535.awsdns-02.net", "ns-1725.awsdns-23.co.uk", "ns-308.awsdns-38.com", "ns-1452.awsdns-53.org"] 23 | expect(sample_zone.nameservers).to eq(expected_nameservers) 24 | end 25 | end 26 | end 27 | 28 | describe "#delete_zone" do 29 | it "deletes a zone" do 30 | VCR.use_cassette("aws_zone_delete", :record => :none) do 31 | zone = Route53::Zone.new("example.com.", '/hostedzone/Z3E84CELCS8770', conn) 32 | resp = zone.delete_zone 33 | expect(resp.pending?).to be_truthy 34 | expect(resp.error?).to be_falsey 35 | end 36 | end 37 | end 38 | 39 | describe "#create_zone" do 40 | it "creates a zone" do 41 | VCR.use_cassette("aws_zone", :record => :none) do 42 | new_zone = Route53::Zone.new("example.com.", nil, conn) 43 | resp = new_zone.create_zone 44 | expect(resp.pending?).to be_truthy 45 | expect(resp.error?).to be_falsey 46 | expect(new_zone.host_url).to eq('/hostedzone/Z3E84CELCS8770') 47 | end 48 | end 49 | end 50 | 51 | describe "#get_records" do 52 | it "pulls records" do 53 | VCR.use_cassette("aws_zone_records", :record => :none) do 54 | zone_records = sample_zone.get_records 55 | bar_50_proj = zone_records.detect { |r| r.name == 'bar.50projects.com.' } 56 | foo_50_proj = zone_records.detect { |r| r.name == 'foo.50projects.com.' } 57 | expect(bar_50_proj.values).to eq(['www.google.com']) 58 | expect(foo_50_proj.values).to eq(['www.groupon.com']) 59 | end 60 | end 61 | 62 | it "filters by type" do 63 | VCR.use_cassette("aws_zone_records", :record => :none) do 64 | a_records = sample_zone.get_records('A') 65 | sample_a_record = a_records.detect { |r| r.name == 'arecord.50projects.com.' } 66 | expect(a_records.map(&:type).uniq).to eq(['A']) 67 | expect(sample_a_record.values).to eq(['8.8.8.8']) 68 | end 69 | end 70 | end 71 | end 72 | -------------------------------------------------------------------------------- /spec/lib/route53/connection_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Route53::Connection do 4 | describe "#initialize" do 5 | it "sets the base_url to the endpoint plus the api" do 6 | conn = Route53::Connection.new('access_key', 'secret', '1999-01-01', 'https://www.example.com/') 7 | expect(conn.base_url).to eq('https://www.example.com/1999-01-01') 8 | end 9 | end 10 | 11 | describe "#request" 12 | 13 | describe "#get_zones" do 14 | it "gets back a list of zones" do 15 | VCR.use_cassette("aws_zones", :record => :none) do 16 | conn = Route53::Connection.new(credentials('access_key'), credentials('secret_key')) 17 | expect(conn.get_zones.map(&:name)).to eq(['50projects.com.']) 18 | end 19 | end 20 | 21 | it "handles a single domain name" do 22 | VCR.use_cassette("aws_zones", :record => :none) do 23 | conn = Route53::Connection.new(credentials('access_key'), credentials('secret_key')) 24 | expect(conn.get_zones('50projects.com.').map(&:name)).to eq(['50projects.com.']) 25 | end 26 | end 27 | 28 | it "handles subdomains" do 29 | VCR.use_cassette("aws_zones", :record => :none) do 30 | conn = Route53::Connection.new(credentials('access_key'), credentials('secret_key')) 31 | expect(conn.get_zones('sub.50projects.com.').map(&:name)).to eq(['50projects.com.']) 32 | end 33 | end 34 | 35 | it "handles truncated responses" 36 | it "handles subqueries based on the hostedzone" 37 | end 38 | 39 | describe "#get_date" do 40 | let(:conn) { Route53::Connection.new(credentials('access_key'), credentials('secret_key')) } 41 | let(:expected_date) { "Mon, 27 Jan 2014 20:43:36 GMT" } 42 | 43 | before do 44 | VCR.turn_off! 45 | stub_request(:head, "https://route53.amazonaws.com/date").to_return( 46 | :headers => { 'Date' => expected_date } 47 | ) 48 | end 49 | 50 | after do 51 | VCR.turn_on! 52 | end 53 | 54 | it "makes a request to amazon's /date endpoint" do 55 | expect(conn.get_date).to eq(expected_date) 56 | end 57 | 58 | it "doesn't make extra calls to the network after the first request" do 59 | expect(conn.get_date).to eq(expected_date) 60 | stub_request(:head, "https://route53.amazonaws.com/date").to_return( 61 | :headers => { 'Date' => 'Mon, 27 Jan 2014 23:59:59 GMT' } 62 | ) 63 | expect(conn.get_date).to eq(expected_date) 64 | end 65 | 66 | it "makes a new call if the first date call was made longer than 30 seconds ago" do 67 | expect(conn.get_date).to eq(expected_date) 68 | current_time = Time.now 69 | Time.stub(:now => current_time + 31) 70 | stub_request(:head, "https://route53.amazonaws.com/date").to_return( 71 | :headers => { 'Date' => 'Mon, 27 Jan 2014 23:59:59 GMT' } 72 | ) 73 | expect(conn.get_date).to eq('Mon, 27 Jan 2014 23:59:59 GMT') 74 | end 75 | end 76 | end 77 | -------------------------------------------------------------------------------- /spec/fixtures/vcr_cassettes/aws_zone_delete.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: head 5 | uri: https://route53.amazonaws.com/date 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept: 11 | - '*/*' 12 | User-Agent: 13 | - Ruby 14 | response: 15 | status: 16 | code: 200 17 | message: OK 18 | headers: 19 | X-Amzn-Requestid: 20 | - 9eebd6a5-87a0-11e3-b239-49b331f5c62c 21 | Content-Type: 22 | - content/unknown 23 | Content-Length: 24 | - '2' 25 | Date: 26 | - Mon, 27 Jan 2014 22:16:07 GMT 27 | body: 28 | encoding: UTF-8 29 | string: '' 30 | http_version: 31 | recorded_at: Mon, 27 Jan 2014 22:16:08 GMT 32 | - request: 33 | method: delete 34 | uri: https://route53.amazonaws.com/2012-12-12/hostedzone/Z3E84CELCS8770 35 | body: 36 | encoding: US-ASCII 37 | string: '' 38 | headers: 39 | Date: 40 | - Mon, 27 Jan 2014 22:16:07 GMT 41 | X-Amzn-Authorization: 42 | - AWS3-HTTPS AWSAccessKeyId=AKIAIK7CBPSH72TVCGBA,Algorithm=HmacSHA256,Signature=BSeUb4ZKEBrwpG/Tp/1zoge9sHX7PTdctJVU2beO/G4= 43 | Content-Type: 44 | - text/xml; charset=UTF-8 45 | Accept-Encoding: 46 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 47 | Accept: 48 | - '*/*' 49 | User-Agent: 50 | - Ruby 51 | response: 52 | status: 53 | code: 200 54 | message: OK 55 | headers: 56 | X-Amzn-Requestid: 57 | - 9f04411c-87a0-11e3-bf8c-1f13207fd337 58 | Content-Type: 59 | - text/xml 60 | Content-Length: 61 | - '259' 62 | Date: 63 | - Mon, 27 Jan 2014 22:16:07 GMT 64 | body: 65 | encoding: UTF-8 66 | string: |- 67 | 68 | /change/CCVCCM8EFB4P8PENDING2014-01-27T22:16:08.408Z 69 | http_version: 70 | recorded_at: Mon, 27 Jan 2014 22:16:09 GMT 71 | - request: 72 | method: get 73 | uri: https://route53.amazonaws.com/2012-12-12/change/CCVCCM8EFB4P8 74 | body: 75 | encoding: US-ASCII 76 | string: '' 77 | headers: 78 | Date: 79 | - Mon, 27 Jan 2014 22:16:07 GMT 80 | X-Amzn-Authorization: 81 | - AWS3-HTTPS AWSAccessKeyId=AKIAIK7CBPSH72TVCGBA,Algorithm=HmacSHA256,Signature=BSeUb4ZKEBrwpG/Tp/1zoge9sHX7PTdctJVU2beO/G4= 82 | Content-Type: 83 | - text/xml; charset=UTF-8 84 | Accept-Encoding: 85 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 86 | Accept: 87 | - '*/*' 88 | User-Agent: 89 | - Ruby 90 | response: 91 | status: 92 | code: 200 93 | message: OK 94 | headers: 95 | X-Amzn-Requestid: 96 | - 9f7a0d33-87a0-11e3-ad32-ed3fdad9cbb6 97 | Content-Type: 98 | - text/xml 99 | Content-Length: 100 | - '245' 101 | Date: 102 | - Mon, 27 Jan 2014 22:16:08 GMT 103 | body: 104 | encoding: UTF-8 105 | string: |- 106 | 107 | /change/CCVCCM8EFB4P8PENDING2014-01-27T22:16:08.408Z 108 | http_version: 109 | recorded_at: Mon, 27 Jan 2014 22:16:09 GMT 110 | recorded_with: VCR 2.8.0 111 | -------------------------------------------------------------------------------- /lib/route53/dns_record.rb: -------------------------------------------------------------------------------- 1 | module Route53 2 | class DNSRecord 3 | attr_reader :name 4 | attr_reader :type 5 | attr_reader :ttl 6 | attr_reader :values 7 | attr_reader :weight 8 | attr_reader :ident 9 | attr_reader :zone_apex 10 | attr_reader :health_id 11 | 12 | def initialize(name,type,ttl,values,zone,zone_apex=nil,weight=nil,ident=nil, evaluate_target_health=false, health_id=nil) 13 | @name = name 14 | unless @name.end_with?(".") 15 | @name += "." 16 | end 17 | @type = type.upcase 18 | @ttl = ttl 19 | @values = values 20 | @zone = zone 21 | @zone_apex = zone_apex 22 | @weight = weight 23 | @ident = ident 24 | @evaluate_target_health = evaluate_target_health 25 | @health_id = health_id 26 | end 27 | 28 | def gen_change_xml(xml,action) 29 | xml.Change { |change| 30 | change.Action(action.upcase) 31 | change.ResourceRecordSet { |record| 32 | record.Name(@name) 33 | record.Type(@type) 34 | record.SetIdentifier(@ident) if @ident 35 | record.Weight(@weight) if @weight 36 | record.TTL(@ttl) unless @zone_apex 37 | record.HealthCheckId(@health_id) if @health_id 38 | if @zone_apex 39 | record.AliasTarget { |targets| 40 | targets.HostedZoneId(@zone_apex) 41 | targets.DNSName(@values.first) 42 | targets.EvaluateTargetHealth(@evaluate_target_health) 43 | } 44 | else 45 | record.ResourceRecords { |resources| 46 | @values.each { |val| 47 | resources.ResourceRecord { |record| 48 | record.Value(val) 49 | } 50 | } 51 | } 52 | end 53 | } 54 | } 55 | end 56 | 57 | def delete(comment=nil) 58 | @zone.perform_actions([{:action => "DELETE", :record => self}],comment) 59 | end 60 | 61 | def create(comment=nil) 62 | @zone.perform_actions([{:action => "CREATE", :record => self}],comment) 63 | end 64 | 65 | #Need to modify to a param hash 66 | def update(name,type,ttl,values,comment=nil, zone_apex = nil) 67 | prev = self.clone 68 | @name = name unless name.nil? 69 | @type = type unless type.nil? 70 | @ttl = ttl unless ttl.nil? 71 | @values = values unless values.nil? 72 | @zone_apex = zone_apex unless zone_apex.nil? 73 | @zone.perform_actions([ 74 | {:action => "DELETE", :record => prev}, 75 | {:action => "CREATE", :record => self}, 76 | ],comment) 77 | end 78 | 79 | #Returns the raw array so the developer can update large batches manually 80 | #Need to modify to a param hash 81 | def update_dirty(name,type,ttl,values,zone_apex = nil) 82 | prev = self.clone 83 | @name = name unless name.nil? 84 | @type = type unless type.nil? 85 | @ttl = ttl unless ttl.nil? 86 | @values = values unless values.nil? 87 | @zone_apex = zone_apex unless zone_apex.nil? 88 | return [{:action => "DELETE", :record => prev}, 89 | {:action => "CREATE", :record => self}] 90 | end 91 | 92 | def to_s 93 | if @weight 94 | "#{@name} #{@type} #{@ttl} '#{@ident}' #{@weight} #{@values.join(",")}" 95 | elsif @zone_apex 96 | "#{@name} #{@type} #{@zone_apex} #{@values.join(",")}" 97 | else 98 | "#{@name} #{@type} #{@ttl} #{@values.join(",")}" 99 | end 100 | end 101 | end 102 | end 103 | -------------------------------------------------------------------------------- /lib/route53/connection.rb: -------------------------------------------------------------------------------- 1 | module Route53 2 | class Connection 3 | attr_reader :base_url 4 | attr_reader :api 5 | attr_reader :endpoint 6 | attr_reader :verbose 7 | 8 | def initialize(accesskey,secret,api='2012-12-12',endpoint='https://route53.amazonaws.com/',verbose=false,ssl_no_verify=false) 9 | @accesskey = accesskey 10 | @secret = secret 11 | @api = api 12 | @endpoint = endpoint 13 | @base_url = endpoint+@api 14 | @verbose = verbose 15 | @ssl_no_verify = ssl_no_verify 16 | end 17 | 18 | def request(url,type = "GET",data = nil) 19 | puts "URL: #{url}" if @verbose 20 | puts "Type: #{type}" if @verbose 21 | puts "Req: #{data}" if type != "GET" && @verbose 22 | uri = URI(url) 23 | http = Net::HTTP.new(uri.host, uri.port) 24 | http.use_ssl = true if uri.scheme == "https" 25 | http.verify_mode = OpenSSL::SSL::VERIFY_NONE if RUBY_VERSION.start_with?("1.8") or @ssl_no_verify 26 | time = get_date 27 | hmac = HMAC::SHA256.new(@secret) 28 | hmac.update(time) 29 | signature = Base64.encode64(hmac.digest).chomp 30 | headers = { 31 | 'Date' => time, 32 | 'X-Amzn-Authorization' => "AWS3-HTTPS AWSAccessKeyId=#{@accesskey},Algorithm=HmacSHA256,Signature=#{signature}", 33 | 'Content-Type' => 'text/xml; charset=UTF-8' 34 | } 35 | resp = http.send_request(type,uri.path+"?"+(uri.query.nil? ? "" : uri.query),data,headers) 36 | #puts "Resp:"+resp.to_s if @verbose 37 | #puts "RespBody: #{resp.body}" if @verbose 38 | return AWSResponse.new(resp.body,self) 39 | end 40 | 41 | def get_zones(name = nil) 42 | truncated = true 43 | query = [] 44 | zones = [] 45 | while truncated 46 | if !name.nil? && name.start_with?("/hostedzone/") 47 | resp = request("#{@base_url}#{name}") 48 | truncated = false 49 | else 50 | resp = request("#{@base_url}/hostedzone?"+query.join("&")) 51 | end 52 | return nil if resp.error? 53 | zone_list = Nokogiri::XML(resp.raw_data) 54 | elements = zone_list.search("HostedZone") 55 | elements.each do |e| 56 | zones.push(Zone.new(e.search("Name").first.inner_text, 57 | e.search("Id").first.inner_text, 58 | self)) 59 | end 60 | truncated = (zone_list.search("IsTruncated").first.inner_text == "true") if truncated 61 | query = ["marker="+zone_list.search("NextMarker").first.inner_text] if truncated 62 | end 63 | unless name.nil? || name.start_with?("/hostedzone/") 64 | name_arr = name.split('.') 65 | (0 ... name_arr.size).each do |i| 66 | search_domain = name_arr.last(name_arr.size-i).join('.')+"." 67 | zone_select = zones.select { |z| z.name == search_domain } 68 | return zone_select if zone_select.any? 69 | end 70 | return nil 71 | end 72 | return zones 73 | end 74 | 75 | def get_date 76 | #return Time.now.utc.rfc2822 77 | #Cache date for 30 seconds to reduce extra calls 78 | if @date_stale.nil? || @date_stale < Time.now - 30 79 | uri = URI(@endpoint) 80 | http = Net::HTTP.new(uri.host, uri.port) 81 | http.use_ssl = true if uri.scheme == "https" 82 | http.verify_mode = OpenSSL::SSL::VERIFY_NONE if RUBY_VERSION.start_with?("1.8") or @ssl_no_verify 83 | resp = nil 84 | puts "Making Date Request" if @verbose 85 | http.start { |http| resp = http.head('/date') } 86 | @date = resp['Date'] 87 | @date_stale = Time.now 88 | puts "Received Date." if @verbose 89 | end 90 | return @date 91 | end 92 | end 93 | end 94 | -------------------------------------------------------------------------------- /lib/route53/aws_response.rb: -------------------------------------------------------------------------------- 1 | module Route53 2 | class AWSResponse 3 | attr_reader :raw_data 4 | 5 | MESSAGES = { 6 | "InvalidClientTokenId" => "You may have a missing or incorrect secret or access key. Please double check your configuration files and amazon account", 7 | "MissingAuthenticationToken" => "You may have a missing or incorrect secret or access key. Please double check your configuration files and amazon account", 8 | "OptInRequired" => "In order to use Amazon's Route 53 service you first need to signup for it. Please see http://aws.amazon.com/route53/ for your account information and use the associated access key and secret.", 9 | "Other" => "It looks like you've run into an unhandled error. Please send a detailed bug report with the entire input and output from the program to support@50projects.com or to https://github.com/pcorliss/ruby_route_53/issues and we'll do out best to help you.", 10 | "SignatureDoesNotMatch" => "It looks like your secret key is incorrect or no longer valid. Please check your amazon account information for the proper key.", 11 | "HostedZoneNotEmpty" => "You'll need to first delete the contents of this zone. You can do so using the '--remove' option as part of the command line interface.", 12 | "InvalidChangeBatch" => "You may have tried to delete a NS or SOA record. This error is safe to ignore if you're just trying to delete all records as part of a zone prior to deleting the zone. Or you may have tried to create a record that already exists. Otherwise please file a bug by sending a detailed bug report with the entire input and output from the program to support@50projects.com or to https://github.com/pcorliss/ruby_route_53/issues and we'll do out best to help you.", 13 | "ValidationError" => "Check over your input again to make sure the record to be created is valid. The error message should give you some hints on what went wrong. If you're still having problems please file a bug by sending a detailed bug report with the entire input and output from the program to support@50projects.com or to https://github.com/pcorliss/ruby_route_53/issues and we'll do out best to help you.", 14 | "ServiceUnavailable" => "It looks like Amazon Route 53 is having availability problems. If the error persists, you may want to check http://status.aws.amazon.com/ for more information on the current system status." 15 | } 16 | 17 | def initialize(resp,conn) 18 | @raw_data = unescape(resp) 19 | if error? 20 | $stderr.puts "ERROR: Amazon returned an error for the request." 21 | $stderr.puts "ERROR: RAW_XML: "+@raw_data 22 | $stderr.puts "ERROR: "+error_message 23 | $stderr.puts "" 24 | $stderr.puts "What now? "+helpful_message 25 | #exit 1 26 | end 27 | @conn = conn 28 | @created = Time.now 29 | puts "Raw: #{@raw_data}" if @conn.verbose 30 | end 31 | 32 | def error? 33 | return Nokogiri::XML(@raw_data).search("ErrorResponse").size > 0 34 | end 35 | 36 | def error_message 37 | xml = Nokogiri::XML(@raw_data) 38 | msg_code = xml.search("Code") 39 | msg_text = xml.search("Message") 40 | return (msg_code.size > 0 ? msg_code.first.inner_text : "") + (msg_text.size > 0 ? ': ' + msg_text.first.inner_text : "") 41 | end 42 | 43 | def helpful_message 44 | xml = Nokogiri::XML(@raw_data) 45 | msg_code = xml.search("Code").first.inner_text 46 | MESSAGES[msg_code] || MESSAGES["Other"] 47 | end 48 | 49 | def complete? 50 | return true if error? 51 | if @change_url.nil? 52 | change = Nokogiri::XML(@raw_data).search("ChangeInfo") 53 | if change.size > 0 54 | @change_url = change.first.search("Id").first.inner_text 55 | else 56 | return false 57 | end 58 | end 59 | if @complete.nil? || @complete == false 60 | status = Nokogiri::XML(@conn.request(@conn.base_url+@change_url).raw_data).search("Status") 61 | @complete = status.size > 0 && status.first.inner_text == "INSYNC" ? true : false 62 | if !@complete && @created - Time.now > 60 63 | $stderr.puts "WARNING: Amazon Route53 Change timed out on Sync. This may not be an issue as it may just be Amazon being assy. Then again your request may not have completed.'" 64 | @complete = true 65 | end 66 | end 67 | return @complete 68 | end 69 | 70 | def pending? 71 | #Return opposite of complete via XOR 72 | return complete? ^ true 73 | end 74 | 75 | def to_s 76 | return @raw_data 77 | end 78 | 79 | def unescape(string) 80 | string.gsub(/\\0(\d{2})/) { $1.oct.chr } 81 | end 82 | end 83 | end 84 | -------------------------------------------------------------------------------- /lib/route53/zone.rb: -------------------------------------------------------------------------------- 1 | module Route53 2 | class Zone 3 | attr_reader :host_url 4 | attr_reader :name 5 | attr_reader :records 6 | attr_reader :conn 7 | 8 | def initialize(name,host_url,conn) 9 | @name = name 10 | unless @name.end_with?(".") 11 | @name += "." 12 | end 13 | @host_url = host_url 14 | @conn = conn 15 | end 16 | 17 | def nameservers 18 | return @nameservers if @nameservers 19 | response = Nokogiri::XML(@conn.request(@conn.base_url + @host_url).to_s) 20 | @nameservers = response.search("NameServer").map(&:inner_text) 21 | @nameservers 22 | end 23 | 24 | def delete_zone 25 | @conn.request(@conn.base_url + @host_url,"DELETE") 26 | end 27 | 28 | def create_zone(comment = nil) 29 | xml_str = "" 30 | xml = Builder::XmlMarkup.new(:target=>xml_str, :indent=>2) 31 | xml.instruct! 32 | xml.CreateHostedZoneRequest(:xmlns => @conn.endpoint+'doc/'+@conn.api+'/') { |create| 33 | create.Name(@name) 34 | # AWS lists this as required 35 | # "unique string that identifies the request and that 36 | # allows failed CreateHostedZone requests to be retried without the risk of executing the operation twice." 37 | # Just going to pass a random string instead. 38 | create.CallerReference(rand(2**32).to_s(16)) 39 | create.HostedZoneConfig { |conf| 40 | conf.Comment(comment) 41 | } 42 | } 43 | #puts "XML:\n#{xml_str}" if @conn.verbose 44 | resp = @conn.request(@conn.base_url + "/hostedzone","POST",xml_str) 45 | resp_xml = Nokogiri::XML(resp.raw_data) 46 | @host_url = resp_xml.search("HostedZone").first.search("Id").first.inner_text 47 | return resp 48 | end 49 | 50 | def get_records(type="ANY") 51 | return nil if host_url.nil? 52 | 53 | truncated = true 54 | query = [] 55 | dom_records = [] 56 | while truncated 57 | resp = @conn.request(@conn.base_url+@host_url+"/rrset?"+query.join("&")) 58 | if resp.error? 59 | return nil 60 | end 61 | zone_file = Nokogiri::XML(resp.raw_data) 62 | records = zone_file.search("ResourceRecordSet") 63 | 64 | records.each do |record| 65 | #puts "Name:"+record.search("Name").first.inner_text if @conn.verbose 66 | #puts "Type:"+record.search("Type").first.inner_text if @conn.verbose 67 | #puts "TTL:"+record.search("TTL").first.inner_text if @conn.verbose 68 | #record.search("Value").each do |val| 69 | # #puts "Val:"+val.inner_text if @conn.verbose 70 | #end 71 | zone_apex_records = record.search("HostedZoneId") 72 | values = record.search("Value").map { |val| val.inner_text } 73 | values << record.search("DNSName").first.inner_text unless zone_apex_records.empty? 74 | weight_records = record.search("Weight") 75 | ident_records = record.search("SetIdentifier") 76 | dom_records.push(DNSRecord.new(record.search("Name").first.inner_text, 77 | record.search("Type").first.inner_text, 78 | ((record.search("TTL").first.nil? ? '' : record.search("TTL").first.inner_text) if zone_apex_records.empty?), 79 | values, 80 | self, 81 | (zone_apex_records.first.inner_text unless zone_apex_records.empty?), 82 | (weight_records.first.inner_text unless weight_records.empty?), 83 | (ident_records.first.inner_text unless ident_records.empty?) 84 | )) 85 | end 86 | 87 | truncated = (zone_file.search("IsTruncated").first.inner_text == "true") 88 | if truncated 89 | next_name = zone_file.search("NextRecordName").first.inner_text 90 | next_type = zone_file.search("NextRecordType").first.inner_text 91 | query = ["name="+next_name,"type="+next_type] 92 | end 93 | end 94 | @records = dom_records 95 | if type != 'ANY' 96 | return dom_records.select { |r| r.type == type } 97 | end 98 | return dom_records 99 | end 100 | 101 | #When deleting a record an optional value is available to specify just a single value within a recordset like an MX record 102 | #Takes an array of [:action => , :record => ] where action is either CREATE or DELETE and record is a DNSRecord 103 | def gen_change_xml(change_list,comment=nil) 104 | #Get zone list and pick zone that matches most ending chars 105 | 106 | xml_str = "" 107 | xml = Builder::XmlMarkup.new(:target=>xml_str, :indent=>2) 108 | xml.instruct! 109 | xml.ChangeResourceRecordSetsRequest(:xmlns => @conn.endpoint+'doc/'+@conn.api+'/') { |req| 110 | req.ChangeBatch { |batch| 111 | batch.Comment(comment) unless comment.nil? 112 | batch.Changes { |changes| 113 | change_list.each { |change_item| 114 | change_item[:record].gen_change_xml(changes,change_item[:action]) 115 | } 116 | } 117 | } 118 | } 119 | #puts "XML:\n#{xml_str}" if @conn.verbose 120 | return xml_str 121 | end 122 | 123 | #For modifying multiple or single records within a single transaction 124 | def perform_actions(change_list,comment=nil) 125 | xml_str = gen_change_xml(change_list,comment) 126 | @conn.request(@conn.base_url + @host_url+"/rrset","POST",xml_str) 127 | end 128 | 129 | 130 | def to_s 131 | return "#{@name} #{@host_url}" 132 | end 133 | end 134 | end 135 | -------------------------------------------------------------------------------- /spec/fixtures/vcr_cassettes/aws_zone.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: head 5 | uri: https://route53.amazonaws.com/date 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept: 11 | - '*/*' 12 | User-Agent: 13 | - Ruby 14 | response: 15 | status: 16 | code: 200 17 | message: OK 18 | headers: 19 | X-Amzn-Requestid: 20 | - 9391c336-879f-11e3-8a96-59f82340bc25 21 | Content-Type: 22 | - content/unknown 23 | Content-Length: 24 | - '2' 25 | Date: 26 | - Mon, 27 Jan 2014 22:08:38 GMT 27 | body: 28 | encoding: UTF-8 29 | string: '' 30 | http_version: 31 | recorded_at: Mon, 27 Jan 2014 22:08:39 GMT 32 | - request: 33 | method: get 34 | uri: https://route53.amazonaws.com/2012-12-12/hostedzone/Z3HXUG22R8JWBK 35 | body: 36 | encoding: US-ASCII 37 | string: '' 38 | headers: 39 | Date: 40 | - Mon, 27 Jan 2014 22:08:38 GMT 41 | X-Amzn-Authorization: 42 | - AWS3-HTTPS AWSAccessKeyId=AKIAIK7CBPSH72TVCGBA,Algorithm=HmacSHA256,Signature=5iNDIpJBlCE+2sAhhanRAOsppsBpm5chQpw/DuSvwZo= 43 | Content-Type: 44 | - text/xml; charset=UTF-8 45 | Accept-Encoding: 46 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 47 | Accept: 48 | - '*/*' 49 | User-Agent: 50 | - Ruby 51 | response: 52 | status: 53 | code: 200 54 | message: OK 55 | headers: 56 | X-Amzn-Requestid: 57 | - 93b3ca64-879f-11e3-9add-f35e9c3aa272 58 | Content-Type: 59 | - text/xml 60 | Content-Length: 61 | - '556' 62 | Date: 63 | - Mon, 27 Jan 2014 22:08:39 GMT 64 | body: 65 | encoding: UTF-8 66 | string: |- 67 | 68 | /hostedzone/Z3HXUG22R8JWBK50projects.com.a9f6b14e22ns-535.awsdns-02.netns-1725.awsdns-23.co.ukns-308.awsdns-38.comns-1452.awsdns-53.org 69 | http_version: 70 | recorded_at: Mon, 27 Jan 2014 22:08:40 GMT 71 | - request: 72 | method: post 73 | uri: https://route53.amazonaws.com/2012-12-12/hostedzone 74 | body: 75 | encoding: UTF-8 76 | string: | 77 | 78 | 79 | example.com. 80 | dbdc62da 81 | 82 | 83 | 84 | 85 | headers: 86 | Date: 87 | - Mon, 27 Jan 2014 22:08:38 GMT 88 | X-Amzn-Authorization: 89 | - AWS3-HTTPS AWSAccessKeyId=AKIAIK7CBPSH72TVCGBA,Algorithm=HmacSHA256,Signature=5iNDIpJBlCE+2sAhhanRAOsppsBpm5chQpw/DuSvwZo= 90 | Content-Type: 91 | - text/xml; charset=UTF-8 92 | Accept-Encoding: 93 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 94 | Accept: 95 | - '*/*' 96 | User-Agent: 97 | - Ruby 98 | response: 99 | status: 100 | code: 201 101 | message: Created 102 | headers: 103 | X-Amzn-Requestid: 104 | - 25358b9e-87a0-11e3-bf8c-1f13207fd337 105 | Location: 106 | - https://route53.amazonaws.com/2012-12-12//hostedzone/Z3E84CELCS8770 107 | Content-Type: 108 | - text/xml 109 | Content-Length: 110 | - '716' 111 | Date: 112 | - Mon, 27 Jan 2014 22:12:47 GMT 113 | body: 114 | encoding: UTF-8 115 | string: |- 116 | 117 | /hostedzone/Z3E84CELCS8770example.com.dbdc62da2/change/C2ZW86S7M9XIU1PENDING2014-01-27T22:12:47.576Zns-1621.awsdns-10.co.ukns-510.awsdns-63.comns-1232.awsdns-26.orgns-806.awsdns-36.net 118 | http_version: 119 | recorded_at: Mon, 27 Jan 2014 22:12:47 GMT 120 | - request: 121 | method: get 122 | uri: https://route53.amazonaws.com/2012-12-12/change/C2ZW86S7M9XIU1 123 | body: 124 | encoding: US-ASCII 125 | string: '' 126 | headers: 127 | Date: 128 | - Mon, 27 Jan 2014 22:08:38 GMT 129 | X-Amzn-Authorization: 130 | - AWS3-HTTPS AWSAccessKeyId=AKIAIK7CBPSH72TVCGBA,Algorithm=HmacSHA256,Signature=5iNDIpJBlCE+2sAhhanRAOsppsBpm5chQpw/DuSvwZo= 131 | Content-Type: 132 | - text/xml; charset=UTF-8 133 | Accept-Encoding: 134 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 135 | Accept: 136 | - '*/*' 137 | User-Agent: 138 | - Ruby 139 | response: 140 | status: 141 | code: 200 142 | message: OK 143 | headers: 144 | X-Amzn-Requestid: 145 | - 278a2a47-87a0-11e3-a58f-435e724ec933 146 | Content-Type: 147 | - text/xml 148 | Content-Length: 149 | - '246' 150 | Date: 151 | - Mon, 27 Jan 2014 22:12:47 GMT 152 | body: 153 | encoding: UTF-8 154 | string: |- 155 | 156 | /change/C2ZW86S7M9XIU1PENDING2014-01-27T22:12:47.576Z 157 | http_version: 158 | recorded_at: Mon, 27 Jan 2014 22:12:48 GMT 159 | - request: 160 | method: delete 161 | uri: https://route53.amazonaws.com/2012-12-12/hostedzone/Z3E84CELCS8770 162 | body: 163 | encoding: US-ASCII 164 | string: '' 165 | headers: 166 | Date: 167 | - Mon, 27 Jan 2014 22:08:38 GMT 168 | X-Amzn-Authorization: 169 | - AWS3-HTTPS AWSAccessKeyId=AKIAIK7CBPSH72TVCGBA,Algorithm=HmacSHA256,Signature=5iNDIpJBlCE+2sAhhanRAOsppsBpm5chQpw/DuSvwZo= 170 | Content-Type: 171 | - text/xml; charset=UTF-8 172 | Accept-Encoding: 173 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 174 | Accept: 175 | - '*/*' 176 | User-Agent: 177 | - Ruby 178 | response: 179 | status: 180 | code: 400 181 | message: Bad Request 182 | headers: 183 | X-Amzn-Requestid: 184 | - 8f57cd8b-87a0-11e3-b239-49b331f5c62c 185 | Content-Type: 186 | - text/xml 187 | Content-Length: 188 | - '348' 189 | Date: 190 | - Mon, 27 Jan 2014 22:15:41 GMT 191 | body: 192 | encoding: UTF-8 193 | string: |- 194 | 195 | SenderRequestExpiredRequest timestamp: Mon, 27 Jan 2014 22:08:38 GMT expired. It must be within 300 secs/ of server time.8f57cd8b-87a0-11e3-b239-49b331f5c62c 196 | http_version: 197 | recorded_at: Mon, 27 Jan 2014 22:15:42 GMT 198 | recorded_with: VCR 2.8.0 199 | -------------------------------------------------------------------------------- /spec/fixtures/vcr_cassettes/aws_zone_records.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: head 5 | uri: https://route53.amazonaws.com/date 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept: 11 | - '*/*' 12 | User-Agent: 13 | - Ruby 14 | response: 15 | status: 16 | code: 200 17 | message: OK 18 | headers: 19 | X-Amzn-Requestid: 20 | - 634efeeb-87a2-11e3-bf8c-1f13207fd337 21 | Content-Type: 22 | - content/unknown 23 | Content-Length: 24 | - '2' 25 | Date: 26 | - Mon, 27 Jan 2014 22:28:46 GMT 27 | body: 28 | encoding: UTF-8 29 | string: '' 30 | http_version: 31 | recorded_at: Mon, 27 Jan 2014 22:28:47 GMT 32 | - request: 33 | method: get 34 | uri: https://route53.amazonaws.com/2012-12-12/hostedzone/Z3HXUG22R8JWBK/rrset 35 | body: 36 | encoding: US-ASCII 37 | string: '' 38 | headers: 39 | Date: 40 | - Mon, 27 Jan 2014 22:28:46 GMT 41 | X-Amzn-Authorization: 42 | - AWS3-HTTPS AWSAccessKeyId=AKIAIK7CBPSH72TVCGBA,Algorithm=HmacSHA256,Signature=APVNFJA9XYDYwKsrPuBwP2jYLz/P8+tIGRRfGewPerk= 43 | Content-Type: 44 | - text/xml; charset=UTF-8 45 | Accept-Encoding: 46 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 47 | Accept: 48 | - '*/*' 49 | User-Agent: 50 | - Ruby 51 | response: 52 | status: 53 | code: 200 54 | message: OK 55 | headers: 56 | X-Amzn-Requestid: 57 | - 6364aa49-87a2-11e3-ad32-ed3fdad9cbb6 58 | Content-Type: 59 | - text/xml 60 | Transfer-Encoding: 61 | - chunked 62 | Vary: 63 | - Accept-Encoding 64 | Date: 65 | - Mon, 27 Jan 2014 22:28:47 GMT 66 | body: 67 | encoding: UTF-8 68 | string: |- 69 | 70 | 50projects.com.AZ3DZXE0Q79N41Hmy-load-balancer-498104842.us-east-1.elb.amazonaws.com.false50projects.com.MX360020 ALT1.ASPMX.L.GOOGLE.com.10 ASPMX.L.GOOGLE.com.30 ALT2.ASPMX.L.GOOGLE.com.40 ASPMX2.GOOGLEMAIL.com.50 ASPMX3.GOOGLEMAIL.com.50projects.com.NS172800ns-535.awsdns-02.net.ns-1725.awsdns-23.co.uk.ns-308.awsdns-38.com.ns-1452.awsdns-53.org.50projects.com.SOA900ns-535.awsdns-02.net. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 8640050projects.com.TXT3600"foo""barr""fubar"\052.50projects.com.CNAME3600www.google.comarecord.50projects.com.A36008.8.8.8bar.50projects.com.CNAME3600www.google.combar2.50projects.com.CNAME553600www.google.combar2.50projects.com.CNAMESecond113600www.yahoo.comfoo.50projects.com.CNAME999www.groupon.com\052.foo.50projects.com.CNAME3600www.google.comfoo2.50projects.com.CNAME999www.yahoo.commodify-test.50projects.com.A360010.146.15.27philctest.50projects.com.CNAME360050projects.com.philctest2.50projects.com.CNAME3600foo.50projects.com.philctest3.50projects.com.CNAME3600example.com.rubyhead.50projects.com.CNAME3600www.google.comtext.50projects.com.TXT3600"foo""bar""***"text2.50projects.com.TXT3600"foo""bar"text3.50projects.com.TXT3600"bar""foo"www.50projects.com.CNAME25 percent of traffic to pool253600pool2.50projects.com.www.50projects.com.CNAME75 percent of traffic to pool1153600pool1.50projects.com.false100 71 | http_version: 72 | recorded_at: Mon, 27 Jan 2014 22:28:47 GMT 73 | recorded_with: VCR 2.8.0 74 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | Ruby Interface for Amazon's Route 53 2 | ==================================== 3 | 4 | This interface can either be used as a command line tool or as a library from within your existing ruby project. It provides a way to interact with Amazon's Route 53 service. 5 | 6 | Costs & Impact 7 | -------------- 8 | 9 | At the time of this writing Amazon charges $1/zone/month. This includes zones that have been created and deleted and then recreated outside of the normal 12 hour grace period. The creator of this gem is not responsible for costs incurred while using this interface or unexpected oepration or bugs which may incur a cost for the user. The creator is also not responsible for any downtime incurred or disruption in service from the usage of this tool. DNS can be a tricky thing, be careful and always make sure you have a backup of your zone prior to mucking around with it. (route53 -l example.com.) 10 | 11 | Latest Version 12 | -------------- 13 | 14 | The latest source should be available on my [github account](https://github.com/pcorliss/ruby_route_53) and if you can't obtain it using the gem command you can go directly to the [gem page](https://rubygems.org/gems/route53) hosted on rubygems. 15 | 16 | Installation 17 | ------------ 18 | 19 | Installing the Gem 20 | 21 | ```bash 22 | sudo gem install route53 23 | ``` 24 | 25 | Ubuntu with precompiled dependencies 26 | 27 | ```bash 28 | sudo apt-get update 29 | sudo apt-get install ruby rubygems libopenssl-ruby libhmac-ruby libbuilder-ruby libhpricot-ruby 30 | sudo gem install route53 --ignore-dependencies 31 | /var/lib/gems/1.X/gems/route53-W.Y.Z/bin/route53 32 | 33 | #When working with the library and using this method you may need to require the library manually 34 | require '/var/lib/gems/1.X/gems/route53-W.Y.Z/lib/route53' 35 | ``` 36 | 37 | Ubuntu with building dependencies 38 | 39 | ```bash 40 | sudo apt-get update 41 | sudo apt-get install ruby rubygems ruby-dev build-essential libopenssl-ruby 42 | sudo gem install route53 43 | /var/lib/gems/1.X/bin/route53 44 | ``` 45 | 46 | The first time you run the gem in command line mode you'll be prompted to setup. You'll want to have your Amazon access and secret key ready. 47 | 48 | You've either elected to run the setup or a configuration file could not be found. 49 | Please answer the following prompts. 50 | Amazon Access Key: [] 51 | Amazon Secret Key: [] 52 | Amazon Route 53 API Version: [2011-05-05] 53 | Amazon Route 53 Endpoint: [https://route53.amazonaws.com/] 54 | Default TTL: [3600] 55 | Save the configuration file to "~/.route53"?: [Y] 56 | 57 | Command Line Options 58 | -------------------- 59 | 60 | Usage: route53 [options] 61 | 62 | -v, --version Print Version Information 63 | -h, --help Show this message 64 | -V, --verbose Verbose Output 65 | -l, --list [ZONE] Receive a list of all zones or specify a zone to view 66 | -n, --new [ZONE] Create a new Zone 67 | -d, --delete [ZONE] Delete a Zone 68 | -z, --zone [ZONE] Specify a zone to perform an operation on. Either in 'example.com.' or '/hostedzone/XXX' format 69 | -c, --create Create a new record 70 | -r, --remove Remove a record 71 | -g, --change Change a record 72 | --name [NAME] Specify a name for a record 73 | --type [TYPE] Specify a type for a record 74 | --ttl [TTL] Specify a TTL for a record 75 | --weight [WEIGHT] Specify a Weight for a record 76 | --ident [IDENTIFIER] Specify a unique identifier for a record 77 | --values [VALUE1],[VALUE2],[VALUE3] 78 | Specify one or multiple values for a record 79 | --zone-apex-id [ZONE_APEX_ID] 80 | Specify a zone apex if for the record 81 | -m, --comment [COMMENT] Provide a comment for this operation 82 | --no-wait Do not wait for actions to finish syncing. 83 | -s, --setup Run the setup ptogram to create your configuration file. 84 | -f, --file [CONFIGFILE] Specify a configuration file to use 85 | --access [ACCESSKEY] Specify an access key on the command line. 86 | --secret [SECRETKEY] Specify a secret key on the command line. WARNING: Not a good idea 87 | --no-upgrade Do not automatically upgrade the route53 api spec for this version. 88 | 89 | Command Line Usage 90 | ------------------ 91 | 92 | Once route53 is installed, started and has been setup you're ready to start. You can use the following examples to get started. 93 | 94 | ```bash 95 | #Creating a new zone 96 | route53 -n example.com. 97 | 98 | #List Operations 99 | route53 -l #Get all zones for this account 100 | route53 -l example.com. #Get all records for this account within the zone example.com. 101 | 102 | #Create a new record within our newly created zone. 103 | route53 --zone example.com. -c --name foo.example.com. --type CNAME --ttl 3600 --values example.com. 104 | 105 | #New MX Record for a Google Apps hosted domain 106 | route53 --zone example.com. -c --name example.com. --type MX --ttl 3600 \ 107 | --values "10 ASPMX.L.GOOGLE.com.","20 ALT1.ASPMX.L.GOOGLE.com.","30 ALT2.ASPMX.L.GOOGLE.com.","40 ASPMX2.GOOGLEMAIL.com.","50 ASPMX3.GOOGLEMAIL.com." 108 | 109 | #Update the TTL of a record (Leave values nil to leave them alone) 110 | #You'll be prompted to select the record from a list. 111 | #If updating values for a record, make sure to includ all other values. Otherwise they will be dropped 112 | route53 --zone example.com. -g --ttl 600 113 | 114 | #Creating a record that corresponds to an Amazon ELB (zone apex support) 115 | route53 --zone example.com. -c --name example. --zone-apex-id Z3DZXE0XXXXXXX --type A --values my-load-balancer-XXXXXXX.us-east-1.elb.amazonaws.com 116 | 117 | #Creating weighted record sets 118 | route53 example.com. -c --name www.example.com. --weight 15 --ident "75 percent of traffic to pool1" --type CNAME --values pool1.example.com. 119 | route53 example.com. -c --name www.example.com. --weight 5 --ident "25 percent of traffic to pool2" --type CNAME --values pool2.example.com. 120 | 121 | #Creating a wildcard domain 122 | route53 example.com. -c --name *.example.com --type CNAME --values pool1.example.com. 123 | 124 | #Deleting a zone - First remove all records except the NS and SOA record. Then delete the zone. 125 | route53 --zone example.com. -r 126 | route53 -d example.com. 127 | ``` 128 | 129 | Library Usage 130 | ------------- 131 | 132 | If you're using this as a library for your own ruby project you can load it and perform operations by using the following examples. 133 | 134 | ```ruby 135 | require 'route53' 136 | 137 | #Creating a Connection object 138 | conn = Route53::Connection.new(my_access_key,my_secret_key) #opens connection 139 | 140 | #Creating a new zone and working with responses 141 | new_zone = Route53::Zone.new("example.com.",nil,conn) #Create a new zone "example.com." 142 | resp = new_zone.create_zone #Creates a new zone 143 | exit 1 if resp.error? #Exit if there was an error. The AWSResponse Class automatically prints out error messages to STDERR. 144 | while resp.pending? #Waits for response to sync on Amazon's servers. 145 | sleep 1 #If you'll be performing operations on this newly created zone you'll probably want to wait. 146 | end 147 | 148 | #List Operations 149 | zones = conn.get_zones #Requests list of all zones for this account 150 | records = zones.first.get_records #Gets list of all records for a specific zone 151 | 152 | #Create a new record within our newly created zone. 153 | new_record = Route53::DNSRecord.new("foo.example.com.","CNAME","3600",["example.com."],new_zone) 154 | resp = new_record.create 155 | 156 | #New MX Record for a Google Apps hosted domain 157 | new_mx_record = Route53::DNSRecord.new("example.com.","MX","3600", 158 | ["10 ASPMX.L.GOOGLE.com.", 159 | "20 ALT1.ASPMX.L.GOOGLE.com.", 160 | "30 ALT2.ASPMX.L.GOOGLE.com.", 161 | "40 ASPMX2.GOOGLEMAIL.com.", 162 | "50 ASPMX3.GOOGLEMAIL.com."], 163 | new_zone) 164 | resp = new_mx_record.create 165 | 166 | #Update the TTL of a record (Leave values nil to leave them alone) 167 | #If updating values for a record, make sure to includ all other values. Otherwise they will be dropped 168 | resp = new_record.update(nil,nil,"600",nil) 169 | 170 | #Deleting a zone 171 | #A zone can't be deleted until all of it's records have been deleted (Except for 1 NS record and 1 SOA record) 172 | new_zone.get_records.each do |record| 173 | unless record.type == 'NS' || record.type == 'SOA' 174 | record.delete 175 | end 176 | end 177 | new_zone.delete_zone 178 | ``` 179 | 180 | Requirements 181 | ------------ 182 | 183 | Written with Ruby 1.9.2 on an Ubuntu Linux machine. Smoke tested on an Ubuntu Linux machine with Ruby 1.8.7. 184 | 185 | Amazon AWS account with Route 53 opted into - See the signup link at [http://aws.amazon.com/route53/](http://aws.amazon.com/route53/) 186 | ruby openssl support 187 | ruby-hmac 188 | nokogiri 189 | builder 190 | 191 | Support and Bugs 192 | ---------------- 193 | 194 | Bug reports are appreciated and encouraged. Please either file a detailed issue on [Github](https://github.com/pcorliss/ruby_route_53/issues) or send an email to support@50projects.com. 195 | 196 | Contact 197 | ------- 198 | 199 | This ruby interface for Amazon's Route 53 service was created by Philip Corliss (pcorliss@50projects.com) [50projects.com](http://50projects.com). You can find more information on him and 50projects at [http://blog.50projects.com](http://blog.50projects.com) 200 | 201 | License 202 | ------- 203 | 204 | Ruby Route 53 is licensed under the GPL. See the LICENSE file for details. 205 | -------------------------------------------------------------------------------- /lib/route53/cli.rb: -------------------------------------------------------------------------------- 1 | 2 | require 'rubygems' 3 | require 'optparse' 4 | require 'ostruct' 5 | require 'date' 6 | require 'yaml' 7 | 8 | module Route53 9 | class CLI 10 | 11 | attr_reader :options 12 | 13 | def initialize(arguments, stdin) 14 | @arguments = arguments 15 | @stdin = stdin 16 | 17 | # Set defaults 18 | @options = OpenStruct.new 19 | @options.verbose = false 20 | @options.quiet = false 21 | end 22 | 23 | #Skeleton obtained from http://blog.toddwerth.com/entries/show/5 and modified 24 | 25 | # Parse options, check arguments, then process the command 26 | def run 27 | if parsed_options? && arguments_valid? 28 | puts "Start at #{DateTime.now}\n\n" if @options.verbose 29 | 30 | output_options if @options.verbose # [Optional] 31 | 32 | process_arguments 33 | process_command 34 | 35 | puts "\nFinished at #{DateTime.now}" if @options.verbose 36 | 37 | else 38 | puts "ERROR: Invalid Options passed. Please run with --help" 39 | exit 1 40 | end 41 | 42 | end 43 | 44 | protected 45 | 46 | def parsed_options? 47 | 48 | # Specify options 49 | opts = OptionParser.new 50 | opts.on('-v', '--version', "Print Version Information") { output_version ; exit 0 } 51 | opts.on('-h', '--help',"Show this message") { puts opts ; exit 0 } 52 | opts.on('-V', '--verbose',"Verbose Output") { @options.verbose = true } 53 | #opts.on('-q', '--quiet',"Quiet Output") { @options.quiet = true } 54 | 55 | opts.on('-l', '--list [ZONE]', String, "Receive a list of all zones or specify a zone to view") { |zone| @options.zone = zone unless zone.nil?; @options.list = true } 56 | opts.on('-n', '--new [ZONE]', String, "Create a new Zone") { |zone| @options.zone = zone unless zone.nil?; @options.new_zone = true } 57 | opts.on('-d', '--delete [ZONE]', String, "Delete a Zone") { |zone| @options.zone = zone unless zone.nil?; @options.delete_zone = true } 58 | opts.on('-z', '--zone [ZONE]', String, "Specify a zone to perform an operation on. Either in 'example.com.' or '/hostedzone/XXX' format") { |zone| @options.zone = zone } 59 | 60 | opts.on('-c', '--create', "Create a new record") { @options.create_record = true } 61 | 62 | opts.on('-r', '--remove', String, "Remove a record") { |record| @options.remove_record = true } 63 | opts.on('-g', '--change', String, "Change a record") { |record| @options.change_record = true } 64 | 65 | opts.on('--name [NAME]', String, "Specify a name for a record") { |name| @options.name = name } 66 | opts.on('--type [TYPE]', String, "Specify a type for a record") { |dnstype| @options.dnstype = dnstype } 67 | opts.on('--ttl [TTL]', String, "Specify a TTL for a record") { |ttl| @options.ttl = ttl } 68 | opts.on('--weight [WEIGHT]', String, "Specify a Weight for a record") { |weight| @options.weight = weight } 69 | opts.on('--ident [IDENTIFIER]', String, "Specify a unique identifier for a record") { |ident| @options.ident = ident } 70 | opts.on('--values [VALUE1],[VALUE2],[VALUE3]', Array, "Specify one or multiple values for a record") { |value| @options.values = value } 71 | opts.on('--zone-apex-id [ZONE_APEX_ID]', String, "Specify a zone apex if for the record") { |zone_apex| @options.zone_apex = zone_apex } 72 | 73 | opts.on('-m', '--comment [COMMENT]', String, "Provide a comment for this operation") { |comment| @options.comment = comment } 74 | 75 | opts.on('--no-wait',"Do not wait for actions to finish syncing.") { @options.nowait = true } 76 | opts.on('-s', '--setup',"Run the setup ptogram to create your configuration file.") { @options.setup = true } 77 | opts.on('-f', '--file [CONFIGFILE]',String,"Specify a configuration file to use") { |file| @options.file = file } 78 | 79 | opts.on('--access [ACCESSKEY]',String,"Specify an access key on the command line.") { |access| @options.access = access } 80 | opts.on('--secret [SECRETKEY]',String,"Specify a secret key on the command line. WARNING: Not a good idea") { |secret| @options.secret = secret } 81 | 82 | opts.on('--no-upgrade',"Do not automatically upgrade the route53 api spec for this version.") { @options.no_upgrade = true } 83 | opts.on('-k', '--ssl_no_verify',"set none to ssl veryfy mode ") { @options.ssl_no_verify = true } 84 | 85 | opts.parse!(@arguments) rescue return false 86 | 87 | process_options 88 | true 89 | end 90 | 91 | # Performs post-parse processing on options 92 | def process_options 93 | @options.verbose = false if @options.quiet 94 | @options.file = (user_home+"/.route53") if @options.file.nil? 95 | #setup file 96 | if @options.setup 97 | setup 98 | end 99 | load_config 100 | @config['access_key'] = @options.access unless @options.access.nil? 101 | @config['secret_key'] = @options.secret unless @options.secret.nil? 102 | 103 | 104 | required_options("",["--access-key"]) if @config['access_key'].nil? || @config['access_key'] == "" 105 | required_options("",["--secret_key"]) if @config['secret_key'].nil? || @config['secret_key'] == "" 106 | 107 | end 108 | 109 | def output_options 110 | puts "Options:\n" 111 | 112 | @options.marshal_dump.each do |name, val| 113 | puts " #{name} = #{val}" 114 | end 115 | end 116 | 117 | def arguments_valid? 118 | if @arguments.length <= 1 119 | @options.zone = @arguments.pop if @options.zone.nil? 120 | return true 121 | else 122 | $stderr.puts "Received extra arguments. that couldn't be handled:#{@arguments}" 123 | return false 124 | end 125 | end 126 | 127 | # Setup the arguments 128 | def process_arguments 129 | if @options.new_zone 130 | new_zone 131 | elsif @options.delete_zone 132 | delete_zone 133 | elsif @options.create_record 134 | create_record 135 | elsif @options.remove_record 136 | remove_record 137 | elsif @options.change_record 138 | change_record 139 | else 140 | list 141 | end 142 | end 143 | 144 | def list 145 | zones = conn.get_zones(@options.zone) 146 | unless zones.nil? 147 | zones.each do |z| 148 | puts z 149 | if @options.zone 150 | records = z.get_records(@options.dnstype.nil? ? "ANY" : @options.dnstype) 151 | records.each do |r| 152 | puts r 153 | end 154 | end 155 | end 156 | else 157 | $stderr.puts "ERROR: No Records found for #{@options.zone}" 158 | end 159 | end 160 | 161 | def new_zone 162 | if @options.zone 163 | new_zone = Route53::Zone.new(@options.zone,nil,conn) 164 | puts "Creating New Zone #{@options.zone}" 165 | resp = new_zone.create_zone(@options.comment) 166 | if resp.error? 167 | $stderr.puts "ERROR: Failed to create new zone." 168 | else 169 | pending_wait(resp) 170 | puts "Zone Created." 171 | end 172 | else 173 | required_options("new zone",["--zone"]) 174 | end 175 | end 176 | 177 | def delete_zone 178 | if @options.zone 179 | records = conn.get_zones(@options.zone) 180 | if records.size > 0 181 | if records.size > 1 182 | records = record_picker(records) 183 | end 184 | records.each do |r| 185 | puts "Deleting Zone #{r.name}" 186 | resp = r.delete_zone 187 | pending_wait(resp) 188 | puts "Zone Deleted." unless resp.error? 189 | end 190 | else 191 | $stderr.puts "ERROR: Couldn't Find Record for #{@options.zone}." 192 | end 193 | else 194 | required_options("delete zone",["--zone"]) 195 | end 196 | end 197 | 198 | def create_record 199 | if @options.zone && @options.name && 200 | @options.dnstype && @options.values && 201 | (@options.ttl || @config['default_ttl']) 202 | zones = conn.get_zones(@options.zone) 203 | if zones.size > 0 204 | resps = [] 205 | zones.each do |z| 206 | puts "Creating Record" 207 | @options.ttl = @config['default_ttl'] if @options.ttl.nil? 208 | if @options.dnstype.upcase == 'TXT' 209 | @options.values = @options.values.map do |val| 210 | unless val.start_with?('"') && val.end_with?('"') 211 | val = '"' + val unless val.start_with? '"' 212 | val = val + '"' unless val.end_with? '"' 213 | end 214 | val 215 | end 216 | end 217 | record = Route53::DNSRecord.new(@options.name,@options.dnstype,@options.ttl,@options.values,z,@options.zone_apex,@options.weight,@options.ident) 218 | puts "Creating Record #{record}" 219 | resps.push(record.create) 220 | end 221 | resps.each do |resp| 222 | pending_wait(resp) 223 | puts "Record Created." unless resp.error? 224 | end 225 | else 226 | $stderr.puts "ERROR: Couldn't Find Record for #{@options.zone}." 227 | end 228 | else 229 | #$stderr.puts "ERROR: The following arguments are required for a create record operation." 230 | #$stderr.puts "ERROR: --zone and at least one of --name, --type, --ttl or --values" 231 | #exit 1 232 | required_options("create record",["--zone","--name","--type","--ttl","--values"]) 233 | end 234 | end 235 | 236 | def remove_record 237 | if @options.zone 238 | zones = conn.get_zones(@options.zone) 239 | if zones.size > 0 240 | zones.each do |z| 241 | records = z.get_records(@options.dnstype.nil? ? "ANY" : @options.dnstype) 242 | records = records.select { |rec| rec.name == @options.name } if @options.name 243 | if records.size > 0 244 | if records.size > 1 245 | records = record_picker(records) 246 | end 247 | records.each do |r| 248 | puts "Deleting Record #{r.name}" 249 | resp = r.delete 250 | pending_wait(resp) 251 | puts "Record Deleted." unless resp.error? 252 | end 253 | else 254 | $stderr.puts "ERROR: Couldn't Find Record for #{@options.zone} of type "+(@options.dnstype.nil? ? "ANY" : @options.dnstype)+"." 255 | end 256 | end 257 | else 258 | $stderr.puts "ERROR: Couldn't Find Record for #{@options.zone}." 259 | end 260 | else 261 | #$stderr.puts "ERROR: The following arguments are required for a record removal operation." 262 | #$stderr.puts "ERROR: --zone" 263 | #exit 1 264 | required_options("record removal",["--zone"]) 265 | end 266 | end 267 | 268 | def change_record 269 | if @options.zone && (@options.name || @options.dnstype || @options.ttl || @options.values) 270 | zones = conn.get_zones(@options.zone) 271 | if zones.size > 0 272 | zones.each do |z| 273 | records = z.get_records(@options.dnstype.nil? ? "ANY" : @options.dnstype) 274 | records = records.select { |rec| puts "Rec: #{rec.name}"; rec.name == @options.name } if @options.name 275 | if records.size > 0 276 | if records.size > 1 277 | records = record_picker(records,false) 278 | end 279 | records.each do |r| 280 | puts "Modifying Record #{r.name}" 281 | resp = r.update(@options.name,@options.dnstype,@options.ttl,@options.values,comment=nil) 282 | pending_wait(resp) 283 | puts "Record Modified." unless resp.error? 284 | end 285 | else 286 | $stderr.puts "ERROR: Couldn't Find Record for #{@options.name} of type "+(@options.dnstype.nil? ? "ANY" : @options.dnstype)+"." 287 | end 288 | end 289 | else 290 | $stderr.puts "ERROR: Couldn't Find Record for #{@options.name}." 291 | end 292 | else 293 | #$stderr.puts "ERROR: The following arguments are required for a record change operation." 294 | #$stderr.puts "ERROR: --zone and at least one of --name, --type, --ttl or --values" 295 | #exit 1 296 | required_options("record change",["--zone"],["--name","--type","--ttl","--values"]) 297 | end 298 | end 299 | 300 | def required_options(operation,required = [],at_least_one = [],optional = []) 301 | operation == "" ? operation += " " : operation = " "+operation+" " 302 | $stderr.puts "ERROR: The following arguments are required for a#{operation}operation." 303 | $stderr.puts "ERROR: #{required.join(", ")} #{ (required.size > 1 ? "are" : "is") } required." if required.size > 0 304 | $stderr.puts "ERROR: At least one of #{at_least_one.join(", ")} are required." if at_least_one.size > 0 305 | $stderr.puts "ERROR: #{optional.join(", ")}are optional." if optional.size > 0 306 | exit 1 307 | end 308 | 309 | def setup 310 | puts "You've either elected to run the setup or a configuration file could not be found." 311 | puts "Please answer the following prompts." 312 | new_config = Hash.new 313 | new_config['access_key'] = get_input(String,"Amazon Access Key") 314 | new_config['secret_key'] = get_input(String,"Amazon Secret Key") 315 | new_config['api'] = get_input(String,"Amazon Route 53 API Version","2011-05-05") 316 | new_config['endpoint'] = get_input(String,"Amazon Route 53 Endpoint","https://route53.amazonaws.com/") 317 | new_config['default_ttl'] = get_input(String,"Default TTL","3600") 318 | if get_input(true.class,"Save the configuration file to \"~/.route53\"?","Y") 319 | File.open(@options.file,'w') do |out| 320 | YAML.dump(new_config,out) 321 | end 322 | File.chmod(0600,@options.file) 323 | load_config 324 | else 325 | puts "Not Saving File. Dumping Config instead." 326 | puts YAML.dump(new_config) 327 | exit 0 328 | end 329 | 330 | end 331 | 332 | def get_input(inputtype,description,default = nil) 333 | print "#{description}: [#{default}] " 334 | STDOUT.flush 335 | selection = gets 336 | selection.chomp! 337 | if selection == "" 338 | selection = default 339 | end 340 | if inputtype == true.class 341 | selection = (selection == 'Y') 342 | end 343 | return selection 344 | end 345 | 346 | def record_picker(records,allowall = true) 347 | puts "Please select the record to perform the action on." 348 | records.each_with_index do |r,i| 349 | puts "[#{i}] #{r}" 350 | end 351 | puts "[#{records.size}] All" if allowall 352 | puts "[#{records.size+1}] None" 353 | print "Make a selection: [#{records.size+1}] " 354 | STDOUT.flush 355 | selection = gets 356 | selection.chomp! 357 | if selection == "" 358 | selection = records.size+1 359 | elsif selection != "0" && selection.to_i == 0 360 | $stderr.puts "a Invalid selection: #{selection}" 361 | exit 1 362 | end 363 | selection = selection.to_i 364 | if selection == records.size && allowall 365 | return records 366 | elsif selection == records.size + 1 367 | return [] 368 | elsif records[selection] 369 | return [records[selection]] 370 | else 371 | $stderr.puts "Invalid selection: #{selection}" 372 | exit 1 373 | end 374 | end 375 | 376 | def pending_wait(resp) 377 | while !@options.nowait && resp.pending? 378 | print '.' 379 | 380 | STDOUT.flush 381 | sleep 1 382 | end 383 | end 384 | 385 | def output_version 386 | puts "Ruby route53 interface version #{Route53::VERSION}" 387 | puts "Written by Philip Corliss (pcorliss@50projects.com)" 388 | puts "https://github.com/pcorliss/ruby_route_53" 389 | end 390 | 391 | def process_command 392 | 393 | end 394 | 395 | def process_standard_input 396 | input = @stdin.read 397 | #@stdin.each do |line| 398 | # 399 | #end 400 | end 401 | 402 | def conn 403 | if @conn.nil? 404 | @conn = Route53::Connection.new(@config['access_key'],@config['secret_key'],@config['api'],@config['endpoint'],@options.verbose,@options.ssl_no_verify) 405 | end 406 | return @conn 407 | end 408 | 409 | def load_config 410 | unless File.exists?(@options.file) 411 | setup 412 | end 413 | @config = YAML.load_file(@options.file) 414 | unless @config 415 | @config = Hash.new 416 | end 417 | if @config['api'] != '2011-05-05' && !@options.no_upgrade 418 | puts "Note: Automatically setting your configuration file to the amazon route 53 api spec this program was written for. You can avoid this by passing --no-upgrade" 419 | @config['api'] = '2011-05-05' 420 | File.open(@options.file,'w') do |out| 421 | YAML.dump(@config,out) 422 | end 423 | File.chmod(0600,@options.file) 424 | end 425 | end 426 | 427 | def user_home 428 | homes = ["HOME", "HOMEPATH"] 429 | realHome = homes.detect {|h| ENV[h] != nil} 430 | if not realHome 431 | $stderr.puts "Could not find home directory" 432 | end 433 | return ENV[realHome] 434 | end 435 | end 436 | end 437 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------