Class: Fog::DNS::AWS::Records
- Inherits:
-
Collection
- Object
- Array
- Collection
- Fog::DNS::AWS::Records
- Defined in:
- lib/fog/aws/models/dns/records.rb
Instance Attribute Summary
Attributes inherited from Collection
Instance Method Summary collapse
- #all(options = {}) ⇒ Object
-
#all! ⇒ Object
Load all zone records into the collection.
-
#get(record_name, record_type = nil, record_identifier = nil) ⇒ Object
AWS Route 53 records are uniquely identified by a compound key of name, type, and identifier.
- #new(attributes = {}) ⇒ Object
Methods inherited from Collection
#clear, #create, #destroy, #initialize, #inspect, #load, model, #model, #reload, #table, #to_json
Methods included from Attributes::ClassMethods
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
Methods included from Attributes::InstanceMethods
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one
Constructor Details
This class inherits a constructor from Fog::Collection
Instance Method Details
#all(options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fog/aws/models/dns/records.rb', line 23 def all( = {}) requires :zone [:max_items] ||= max_items [:name] ||= name [:type] ||= type [:identifier] ||= identifier data = connection.list_resource_record_sets(zone.id, ).body # 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) end |
#all! ⇒ Object
Load all zone records into the collection.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fog/aws/models/dns/records.rb', line 43 def all! data = [] begin = { :name => next_record_name, :type => next_record_type, :identifier => next_record_identifier } batch = connection.list_resource_record_sets(zone.id, ).body # NextRecordIdentifier is completely absent instead of nil, so set to nil, or iteration breaks. batch['NextRecordIdentifier'] = nil unless batch.has_key?('NextRecordIdentifier') merge_attributes(batch.reject {|key, value| !['IsTruncated', 'MaxItems', 'NextRecordName', 'NextRecordType', 'NextRecordIdentifier'].include?(key)}) data.concat(batch['ResourceRecordSets']) end while is_truncated load(data) end |
#get(record_name, record_type = nil, record_identifier = nil) ⇒ Object
AWS Route 53 records are uniquely identified by a compound key of name, type, and identifier. #get allows one to retrieve a record using one or more of those key components.
Parameters
-
record_name - The name of the record to retrieve.
-
record_type - The type of record to retrieve, if nil, then the first matching record is returned.
-
record_identifier - The record set identifier to retrieve, if nil, then the first matching record is returned.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/fog/aws/models/dns/records.rb', line 73 def get(record_name, record_type = nil, record_identifier = nil) requires :zone # Append a trailing period to the record_name if absent. record_name = record_name + "." unless record_name.end_with?(".") record_type = record_type.upcase unless record_type.nil? = { :max_items => 1, :name => record_name, :type => record_type, :identifier => record_identifier } data = connection.list_resource_record_sets(zone.id, ).body # Get first record data = data['ResourceRecordSets'].shift if data record = new(data) # make sure everything matches if record.name == record_name if (!record_type.nil? && record.type != record_type) || (!record_identifier.nil? && record.set_identifier != record_identifier) nil else record end end else nil end rescue Excon::Errors::NotFound nil end |
#new(attributes = {}) ⇒ Object
108 109 110 111 |
# File 'lib/fog/aws/models/dns/records.rb', line 108 def new(attributes = {}) requires :zone super({ :zone => zone }.merge!(attributes)) end |