# File lib/fog/aws/dns.rb, line 29 def self.data @data ||= Hash.new do |hash, region| hash[region] = Hash.new do |region_hash, key| region_hash[key] = { :buckets => {}, :limits => { :duplicate_domains => 5 }, :zones => {} } end end end
# 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
# File lib/fog/aws/requests/dns/create_hosted_zone.rb, line 62 def create_hosted_zone(name, options = {}) response = Excon::Response.new if list_hosted_zones.body['HostedZones'].find_all {|z| z['Name'] == name}.size < self.data[:limits][:duplicate_domains] response.status = 201 if options[:caller_ref] caller_ref = options[:caller_ref] else #make sure we have a unique call reference caller_ref = "ref-#{rand(1000000).to_s}" end zone_id = "/hostedzone/#{Fog::AWS::Mock.zone_id}" self.data[:zones][zone_id] = { :id => zone_id, :name => name, :reference => caller_ref, :comment => options[:comment], :records => {} } response.body = { 'HostedZone' => { 'Id' => zone_id, 'Name' => name, 'CallerReference' => caller_ref, 'Comment' => options[:comment] }, 'ChangeInfo' => { 'Id' => "/change/#{Fog::AWS::Mock.change_id}", 'Status' => 'INSYNC', 'SubmittedAt' => Time.now.utc.iso8601 }, 'NameServers' => Fog::AWS::Mock.nameservers } response else response.status = 400 response.body = "<?xml version=\"1.0\"?><Response><Errors><Error><Code>DelegationSetNotAvailable</Code><Message>Amazon Route 53 allows some duplication, but Amazon Route 53 has a maximum threshold of duplicated domains. This error is generated when you reach that threshold. In this case, the error indicates that too many hosted zones with the given domain name exist. If you want to create a hosted zone and Amazon Route 53 generates this error, contact Customer Support.</Message></Error></Errors><RequestID>#{Fog::AWS::Mock.request_id}</RequestID></Response>" raise(Excon::Errors.status_error({:expects => 200}, response)) end end
# File lib/fog/aws/dns.rb, line 54 def data self.class.data[@region][@aws_access_key_id] end
# File lib/fog/aws/requests/dns/get_hosted_zone.rb, line 42 def get_hosted_zone(zone_id) response = Excon::Response.new if (zone = self.data[:zones][zone_id]) response.status = 200 response.body = { 'HostedZone' => { 'Id' => zone[:id], 'Name' => zone[:name], 'CallerReference' => zone[:reference], 'Comment' => zone[:comment] }, 'NameServers' => Fog::AWS::Mock.nameservers } response 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
# File lib/fog/aws/requests/dns/list_hosted_zones.rb, line 55 def list_hosted_zones(options = {}) if options[:max_items].nil? maxitems = 100 else maxitems = options[:max_items] end if options[:marker].nil? start = 0 else start = self.data[:zones].find_index {|z| z[:id] == options[:marker]} end zones = self.data[:zones].values[start, maxitems] next_zone = self.data[:zones].values[start + maxitems] truncated = !next_zone.nil? response = Excon::Response.new response.status = 200 response.body = { 'HostedZones' => zones.map do |z| { 'Id' => z[:id], 'Name' => z[:name], 'CallerReference' => z[:reference], 'Comment' => z[:comment], } end, 'Marker' => options[:marker].to_s, 'MaxItems' => options[:max_items].to_s, 'IsTruncated' => truncated.to_s } if truncated response.body['NextMarker'] = next_zone[:id] end response end
# File lib/fog/aws/dns.rb, line 58 def reset_data self.class.data[@region].delete(@aws_access_key_id) end
Generated with the Darkfish Rdoc Generator 2.