137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
# File 'lib/fog/aws/requests/dns/change_resource_record_sets.rb', line 137
def change_resource_record_sets(zone_id, change_batch, options = {})
response = Excon::Response.new
errors = []
if (zone = self.data[:zones][zone_id])
response.status = 200
change_batch.each do |change|
case change[:action]
when "CREATE"
if zone[:records][change[:type]].nil?
zone[:records][change[:type]] = {}
end
if zone[:records][change[:type]][change[:name]].nil?
zone[:records][change[:type]][change[:name]] = {
:name => change[:name],
:type => change[:type],
:ttl => change[:ttl],
:resource_records => change[:resource_records]
}
else
errors << "Tried to create resource record set #{change[:name]}. type #{change[:type]}, but it already exists"
end
when "DELETE"
if zone[:records][change[:type]].nil? || zone[:records][change[:type]].delete(change[:name]).nil?
errors << "Tried to delete resource record set #{change[:name]}. type #{change[:type]}, but it was not found"
end
end
end
if errors.empty?
response.body = {
'ChangeInfo' => {
'Id' => "/change/#{Fog::AWS::Mock.change_id}",
'Status' => 'INSYNC',
'SubmittedAt' => Time.now.utc.iso8601
}
}
response
else
response.status = 400
response.body = "<?xml version=\"1.0\"?><InvalidChangeBatch xmlns=\"https://route53.amazonaws.com/doc/2012-02-29/\"><Messages>#{errors.map {|e| "<Message>#{e}</Message>"}.join()}</Messages></InvalidChangeBatch>"
raise(Excon::Errors.status_error({:expects => 200}, response))
end
else
response.status = 404
response.body = "<?xml version=\"1.0\"?><Response><Errors><Error><Code>NoSuchHostedZone</Code><Message>A hosted zone with the specified hosted zone ID does not exist.</Message></Error></Errors><RequestID>#{Fog::AWS::Mock.request_id}</RequestID></Response>"
raise(Excon::Errors.status_error({:expects => 200}, response))
end
end
|