mirror of
https://github.com/fog/fog-aws.git
synced 2022-11-09 13:50:52 -05:00
The :geo_location attribute needs to be xml formatted before calling aws
Without this, calling `record.destroy` on a record that has geolocation set will cause an exception with: Fog::DNS::AWS::Error: MalformedInput => Unexpected complex element termination
This commit is contained in:
parent
4e577827fa
commit
0dad896add
2 changed files with 103 additions and 78 deletions
|
@ -61,6 +61,20 @@ module Fog
|
|||
# change_resource_record_sets("ABCDEFGHIJKLMN", change_batch_options)
|
||||
#
|
||||
def change_resource_record_sets(zone_id, change_batch, options = {})
|
||||
body = AWS.change_resource_record_sets_data(zone_id, change_batch, options)
|
||||
request({
|
||||
:body => body,
|
||||
:idempotent => true,
|
||||
:parser => Fog::Parsers::DNS::AWS::ChangeResourceRecordSets.new,
|
||||
:expects => 200,
|
||||
:method => 'POST',
|
||||
:path => "hostedzone/#{zone_id}/rrset"
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the xml request for a given changeset
|
||||
def self.change_resource_record_sets_data(zone_id, change_batch, options = {})
|
||||
# AWS methods return zone_ids that looks like '/hostedzone/id'. Let the caller either use
|
||||
# that form or just the actual id (which is what this request needs)
|
||||
zone_id = zone_id.sub('/hostedzone/', '')
|
||||
|
@ -104,7 +118,8 @@ module Fog
|
|||
end
|
||||
|
||||
geolocation_tag = if change_item[:geo_location]
|
||||
%Q{<GeoLocation>#{change_item[:geo_location]}</GeoLocation>}
|
||||
xml_geo = change_item[:geo_location].map { |k,v| "<#{k}>#{v}</#{k}>" }.join
|
||||
%Q{<GeoLocation>#{xml_geo}</GeoLocation>}
|
||||
end
|
||||
|
||||
resource_records = change_item[:resource_records] || []
|
||||
|
@ -139,15 +154,6 @@ module Fog
|
|||
end
|
||||
|
||||
body = %Q{<?xml version="1.0" encoding="UTF-8"?><ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/#{@version}/">#{changes}</ChangeResourceRecordSetsRequest>}
|
||||
request({
|
||||
:body => body,
|
||||
:idempotent => true,
|
||||
:parser => Fog::Parsers::DNS::AWS::ChangeResourceRecordSets.new,
|
||||
:expects => 200,
|
||||
:method => 'POST',
|
||||
:path => "hostedzone/#{zone_id}/rrset"
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
|
|
@ -7,4 +7,23 @@ Shindo.tests('Fog::DNS[:aws] | change_resource_record_sets', ['aws', 'dns']) do
|
|||
zone_id == Fog::DNS::AWS.elb_hosted_zone_mapping['eu-west-1']
|
||||
end
|
||||
end
|
||||
tests("#change_resource_record_sets_data formats geolocation properly") do
|
||||
change_batch = [{
|
||||
:action=>"CREATE",
|
||||
:name=>"ark.m.example.net.",
|
||||
:resource_records=>["1.1.1.1"],
|
||||
:ttl=>"300",
|
||||
:type=>"A",
|
||||
:set_identifier=>"ark",
|
||||
:geo_location=>{"CountryCode"=>"US", "SubdivisionCode"=>"AR"},
|
||||
}]
|
||||
|
||||
result = Fog::DNS::AWS.change_resource_record_sets_data('zone_id123', change_batch)
|
||||
.match(%r{<GeoLocation>.*</GeoLocation>})
|
||||
returns("<GeoLocation><CountryCode>US</CountryCode><SubdivisionCode>AR</SubdivisionCode></GeoLocation>") {
|
||||
result ? result[0] : ''
|
||||
}
|
||||
|
||||
result
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue