Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The :geo_location attribute needs to be xml formatted before calling aws #142

Merged
merged 2 commits into from
Jun 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions lib/fog/aws/requests/dns/change_resource_record_sets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ class Real
# 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/', '')
Expand Down Expand Up @@ -104,7 +118,8 @@ def change_resource_record_sets(zone_id, change_batch, options = {})
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] || []
Expand Down Expand Up @@ -139,15 +154,6 @@ def change_resource_record_sets(zone_id, change_batch, options = {})
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
Expand Down
19 changes: 19 additions & 0 deletions tests/requests/dns/change_resource_record_sets_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,23 @@
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)
geo = result.match(%r{<GeoLocation>.*</GeoLocation>})
returns("<GeoLocation><CountryCode>US</CountryCode><SubdivisionCode>AR</SubdivisionCode></GeoLocation>") {
geo ? geo[0] : ''
}

result
end
end