From fd36a788cd9c8dff6a279c1519512897c0b4e628 Mon Sep 17 00:00:00 2001 From: George Scott Date: Sat, 31 Mar 2012 10:01:45 -0700 Subject: [PATCH] [aws|dns] Fixed #all iteration It was not possible to iterate all records using #all because of lack of NextRecordIdentifier. --- lib/fog/aws/models/dns/records.rb | 23 ++++++++++++------- .../parsers/dns/list_resource_record_sets.rb | 2 +- .../requests/dns/list_resource_record_sets.rb | 6 +++-- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/fog/aws/models/dns/records.rb b/lib/fog/aws/models/dns/records.rb index 2e23037c2..012f16047 100644 --- a/lib/fog/aws/models/dns/records.rb +++ b/lib/fog/aws/models/dns/records.rb @@ -7,12 +7,14 @@ module Fog class Records < Fog::Collection - attribute :is_truncated, :aliases => ['IsTruncated'] - attribute :max_items, :aliases => ['MaxItems'] + attribute :is_truncated, :aliases => ['IsTruncated'] + attribute :max_items, :aliases => ['MaxItems'] attribute :name - attribute :next_record_name, :aliases => ['NextRecordName'] - attribute :next_record_type, :aliases => ['NextRecordType'] + attribute :next_record_name, :aliases => ['NextRecordName'] + attribute :next_record_type, :aliases => ['NextRecordType'] + attribute :next_record_identifier, :aliases => ['NextRecordIdentifier'] attribute :type + attribute :identifier attribute :zone @@ -20,11 +22,16 @@ module Fog def all(options = {}) requires :zone - options['maxitems'] ||= max_items - options['name'] ||= name - options['type'] ||= type + options[:max_items] ||= max_items + options[:name] ||= name + options[:type] ||= type + options[:identifier] ||= identifier + data = connection.list_resource_record_sets(zone.id, options).body - merge_attributes(data.reject {|key, value| !['IsTruncated', 'MaxItems', 'NextRecordName', 'NextRecordType'].include?(key)}) + # NextRecordIdentifier is completely absent instead of nil, so set to nil, or iteration breaks. + data['NextRecordIdentifier'] = nil unless data.has_key?('NextRecordIdentifier') + + merge_attributes(data.reject {|key, value| !['IsTruncated', 'MaxItems', 'NextRecordName', 'NextRecordType', 'NextRecordIdentifier'].include?(key)}) # leave out the default, read only records data = data['ResourceRecordSets'].reject {|record| ['NS', 'SOA'].include?(record['Type'])} load(data) diff --git a/lib/fog/aws/parsers/dns/list_resource_record_sets.rb b/lib/fog/aws/parsers/dns/list_resource_record_sets.rb index 9d59eedab..39ffde4a1 100644 --- a/lib/fog/aws/parsers/dns/list_resource_record_sets.rb +++ b/lib/fog/aws/parsers/dns/list_resource_record_sets.rb @@ -38,7 +38,7 @@ module Fog case name when 'MaxItems' @response[name] = value.to_i - when 'NextRecordName', 'NextRecordType' + when 'NextRecordName', 'NextRecordType', 'NextRecordIdentifier' @response[name] = value when 'IsTruncated' @response[name] = value == 'true' diff --git a/lib/fog/aws/requests/dns/list_resource_record_sets.rb b/lib/fog/aws/requests/dns/list_resource_record_sets.rb index 5b890278b..83643ea35 100644 --- a/lib/fog/aws/requests/dns/list_resource_record_sets.rb +++ b/lib/fog/aws/requests/dns/list_resource_record_sets.rb @@ -12,6 +12,7 @@ module Fog # * options<~Hash> # * type<~String> - # * name<~String> - + # * identifier<~String> - # * max_items<~Integer> - # # ==== Returns @@ -29,7 +30,8 @@ module Fog # * 'IsTruncated'<~String> - # * 'MaxItems'<~String> - # * 'NextRecordName'<~String> - # * 'NexRecordType'<~String> + # * 'NextRecordType'<~String> + # * 'NextRecordIdentifier'<~String> # * status<~Integer> - 201 when successful def list_resource_record_sets(zone_id, options = {}) @@ -40,7 +42,7 @@ module Fog parameters = {} options.each do |option, value| case option - when :type, :name + when :type, :name, :identifier parameters[option] = "#{value}" when :max_items parameters['maxitems'] = "#{value}"