1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[aws|dns] Fixed #all iteration

It was not possible to iterate all records using #all because of lack
of NextRecordIdentifier.
This commit is contained in:
George Scott 2012-03-31 10:01:45 -07:00
parent 1f80a347d2
commit fd36a788cd
3 changed files with 20 additions and 11 deletions

View file

@ -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)

View file

@ -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'

View file

@ -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}"