From a8defa9a7471ffb42ce575e7006d7786bc10fbed Mon Sep 17 00:00:00 2001 From: Josh Blancett Date: Tue, 24 Sep 2013 14:28:36 -0400 Subject: [PATCH 1/7] added put_record for dynect --- lib/fog/dynect/requests/dns/put_record.rb | 72 +++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 lib/fog/dynect/requests/dns/put_record.rb diff --git a/lib/fog/dynect/requests/dns/put_record.rb b/lib/fog/dynect/requests/dns/put_record.rb new file mode 100644 index 000000000..5740161d8 --- /dev/null +++ b/lib/fog/dynect/requests/dns/put_record.rb @@ -0,0 +1,72 @@ +module Fog + module DNS + class Dynect + class Real + + # Create a record + # + # ==== Parameters + # * type<~String> - type of record in ['AAAA', 'ANY', 'A', 'CNAME', 'DHCID', 'DNAME', 'DNSKEY', 'DS', 'KEY', 'LOC', 'MX', 'NSA', 'NS', 'PTR', 'PX', 'RP', 'SOA', 'SPF', 'SRV', 'SSHFP', 'TXT'] + # * zone<~String> - zone of record + # * rdata<~Hash> - rdata for record + # * options<~Hash>: (options vary by type, listing below includes common parameters) + # * ttl<~Integer> - ttl for the record, defaults to zone ttl + + def put_record(type, zone, fqdn, rdata, options = {}) + options.merge!('rdata' => rdata) + request( + :body => Fog::JSON.encode(options), + :expects => 200, + :method => :put, + :path => ["#{type.to_s.upcase}Record", zone, fqdn].join('/') + ) + end + end + + class Mock + def put_record(type, zone, fqdn, rdata, options = {}) + raise Fog::DNS::Dynect::NotFound unless zone = self.data[:zones][zone] + + records = zone[:records] + record_id = zone[:next_record_id] + zone[:next_record_id] += 1 + + record = { + :type => type, + :zone => zone, + :fqdn => fqdn, + :rdata => rdata, + :ttl => options[:ttl] || zone[:ttl], + :record_id => record_id + } + + records[type] << record + + response = Excon::Response.new + response.status = 200 + + response.body = { + "status" => "success", + "data" => { + "zone" => record[:zone][:zone], + "ttl" => record[:ttl], + "fqdn" => record[:fqdn], + "record_type" => record[:type], + "rdata" => record[:rdata], + "record_id" => record[:record_id] + }, + "job_id" => Fog::Dynect::Mock.job_id, + "msgs" => [{ + "INFO"=>"add: Record added", + "SOURCE"=>"BLL", + "ERR_CD"=>nil, + "LVL"=>"INFO" + }] + } + + response + end + end + end + end +end From 43e4eb16cb263980e4ce8a138d69670ab7a6af93 Mon Sep 17 00:00:00 2001 From: Josh Blancett Date: Wed, 25 Sep 2013 10:21:00 -0400 Subject: [PATCH 2/7] added shindo config for dynect put_record --- tests/dynect/requests/dns/dns_tests.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/dynect/requests/dns/dns_tests.rb b/tests/dynect/requests/dns/dns_tests.rb index a65deb868..6d0dfa58c 100644 --- a/tests/dynect/requests/dns/dns_tests.rb +++ b/tests/dynect/requests/dns/dns_tests.rb @@ -79,6 +79,23 @@ Shindo.tests('Dynect::dns | DNS requests', ['dynect', 'dns']) do @dns.post_record('A', @domain, @fqdn, {'address' => '1.2.3.4'}).body end + put_record_format = shared_format.merge({ + 'data' => { + 'fqdn' => String, + 'rdata' => { + 'address' => String + }, + 'record_id' => Integer, + 'record_type' => String, + 'ttl' => Integer, + 'zone' => String + } + }) + + tests("put_record('A', '#{@domain}', '#{@fqdn}', 'address' => '1.2.3.4')").formats(post_record_format) do + @dns.ut_record('A', @domain, @fqdn, {'address' => '1.2.3.4'}).body + end + publish_zone_format = shared_format.merge({ 'data' => { 'serial' => Integer, From ff82ba53b92e28214ab93a8eb96d1cbf38f698c4 Mon Sep 17 00:00:00 2001 From: Josh Blancett Date: Wed, 25 Sep 2013 10:45:04 -0400 Subject: [PATCH 3/7] fixed typo --- tests/dynect/requests/dns/dns_tests.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dynect/requests/dns/dns_tests.rb b/tests/dynect/requests/dns/dns_tests.rb index 6d0dfa58c..2b008bc79 100644 --- a/tests/dynect/requests/dns/dns_tests.rb +++ b/tests/dynect/requests/dns/dns_tests.rb @@ -93,7 +93,7 @@ Shindo.tests('Dynect::dns | DNS requests', ['dynect', 'dns']) do }) tests("put_record('A', '#{@domain}', '#{@fqdn}', 'address' => '1.2.3.4')").formats(post_record_format) do - @dns.ut_record('A', @domain, @fqdn, {'address' => '1.2.3.4'}).body + @dns.put_record('A', @domain, @fqdn, {'address' => '1.2.3.4'}).body end publish_zone_format = shared_format.merge({ From ff080a776026ee426c9f53e00633a4a1af8c7860 Mon Sep 17 00:00:00 2001 From: Josh Blancett Date: Wed, 25 Sep 2013 11:08:02 -0400 Subject: [PATCH 4/7] added put_record to requests in dynect class --- lib/fog/dynect/dns.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/fog/dynect/dns.rb b/lib/fog/dynect/dns.rb index 185af5f90..fa1320f27 100644 --- a/lib/fog/dynect/dns.rb +++ b/lib/fog/dynect/dns.rb @@ -25,6 +25,7 @@ module Fog request :post_session request :post_zone request :put_zone + request :put_record class JobIncomplete < Error; end From dfe0043405eb5589ca2564eb027da1fa7935d1b1 Mon Sep 17 00:00:00 2001 From: Josh Blancett Date: Wed, 25 Sep 2013 14:46:12 -0400 Subject: [PATCH 5/7] added support for both update and replace for dynect put_record request --- lib/fog/dynect/requests/dns/put_record.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/fog/dynect/requests/dns/put_record.rb b/lib/fog/dynect/requests/dns/put_record.rb index 5740161d8..0371c4ff7 100644 --- a/lib/fog/dynect/requests/dns/put_record.rb +++ b/lib/fog/dynect/requests/dns/put_record.rb @@ -14,11 +14,15 @@ module Fog def put_record(type, zone, fqdn, rdata, options = {}) options.merge!('rdata' => rdata) + type.to_s.upcase! + options = {"#{type}Records" => [options]} unless options['record_id'] + path = ["#{type}Record", zone, fqdn].join('/') + path += "/#{options.delete('record_id')}" if options['record_id'] request( :body => Fog::JSON.encode(options), :expects => 200, :method => :put, - :path => ["#{type.to_s.upcase}Record", zone, fqdn].join('/') + :path => path ) end end From ec7908a740cdd5ed6349b62d75b8eb51c2bf4bbb Mon Sep 17 00:00:00 2001 From: Josh Blancett Date: Wed, 25 Sep 2013 14:48:42 -0400 Subject: [PATCH 6/7] fixed doc info --- lib/fog/dynect/requests/dns/put_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fog/dynect/requests/dns/put_record.rb b/lib/fog/dynect/requests/dns/put_record.rb index 0371c4ff7..b65513467 100644 --- a/lib/fog/dynect/requests/dns/put_record.rb +++ b/lib/fog/dynect/requests/dns/put_record.rb @@ -3,7 +3,7 @@ module Fog class Dynect class Real - # Create a record + # Update or replace a record # # ==== Parameters # * type<~String> - type of record in ['AAAA', 'ANY', 'A', 'CNAME', 'DHCID', 'DNAME', 'DNSKEY', 'DS', 'KEY', 'LOC', 'MX', 'NSA', 'NS', 'PTR', 'PX', 'RP', 'SOA', 'SPF', 'SRV', 'SSHFP', 'TXT'] From 247d8d35fdc5c6fc0fa221fd766a560634c20c38 Mon Sep 17 00:00:00 2001 From: Josh Blancett Date: Wed, 25 Sep 2013 14:49:23 -0400 Subject: [PATCH 7/7] fixed data formatting for testing dynect put_record --- tests/dynect/requests/dns/dns_tests.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/dynect/requests/dns/dns_tests.rb b/tests/dynect/requests/dns/dns_tests.rb index 2b008bc79..8b6000bdc 100644 --- a/tests/dynect/requests/dns/dns_tests.rb +++ b/tests/dynect/requests/dns/dns_tests.rb @@ -82,9 +82,13 @@ Shindo.tests('Dynect::dns | DNS requests', ['dynect', 'dns']) do put_record_format = shared_format.merge({ 'data' => { 'fqdn' => String, - 'rdata' => { - 'address' => String - }, + 'ARecords' => [ + { + 'rdata' => { + 'address' => String + } + } + ], 'record_id' => Integer, 'record_type' => String, 'ttl' => Integer,