Class: CloudParty::Nodes::DNSRecords

Inherits:
Object
  • Object
show all
Includes:
Context, HTTParty
Defined in:
lib/cloud_party/nodes/dns_records.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Context

included

Constructor Details

#initialize(options = {}) ⇒ DNSRecords

Returns a new instance of DNSRecords.



46
47
48
49
# File 'lib/cloud_party/nodes/dns_records.rb', line 46

def initialize(options = {})
  super()
  @options = options
end

Class Method Details

.zone_id_by_name(zone) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cloud_party/nodes/dns_records.rb', line 24

def self.zone_id_by_name(zone)
  options = {
      match: 'all',
      name: zone,
      order: 'name'
  }
  if @options.nil?
    @options = options
  else
    @options.merge!(options)
  end
  zone = CloudParty::Responses::Zones.new(:get, '/zones',
  get('/zones', query: @options), @options).result
    if zone.is_a?(Array)
          if zone.size > 1
            raise CloudParty::Errors::ResultError.new()
          else
            zone.first.fetch(:id, nil)
          end
    end

end

Instance Method Details

#add(type, name, content, opts, zone:) ⇒ CloudParty::Responses::DNSRecords

Add a new DNS record to the specified zone

Parameters:

  • type (String)

    DNS record type

  • name (String)

    DNS record name

  • content (String)

    DNS record content

  • opts (Hash)

    Additional options

  • zone (String)

    Zone to add DNS record to

Options Hash (opts):

  • :ttl (Integer)

    Time to live

  • :priority (Integer)

    Priority

  • :proxied (Boolean)

    Whether the record is proxied

Returns:



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/cloud_party/nodes/dns_records.rb', line 162

def add(type, name, content, opts, zone:)
  zone_id = nil
  options = {
      type: type,
      name: name,
      content: content
  }
  ttl = opts.fetch('ttl', nil)
  priority = opts.fetch('priority', nil)
  proxied = opts.fetch('proxied', nil)
  options.merge!(ttl: ttl) unless ttl.nil?
  options.merge!(priority: priority) unless priority.nil?
  options.merge!(proxied: proxied) unless proxied.nil?
  zone_id = zone_id_by_name(zone)
  CloudParty::Responses::DNSRecords.new(
      :post,
      '/zones/:id/dns_records',
      self.class.post("/zones/#{zone_id}/dns_records", body: options.to_json),
      @options)
end

#batch(records, zone: nil) ⇒ Object



195
196
197
# File 'lib/cloud_party/nodes/dns_records.rb', line 195

def batch(records, zone: nil)
  zone_id = zone_id_by_name(zone)
end

#get(zone, id) ⇒ Object



144
145
146
147
# File 'lib/cloud_party/nodes/dns_records.rb', line 144

def get(zone, id)
  zone_id = DNSRecords.zone_id_by_name(zone)
  CloudParty::Responses::DNSRecords.new(:get, '/zones/:id/dns_records', self.class.get("/zones/#{zone_id}/dns_records", @options), @options)
end

#list(zone, opts) ⇒ CloudParty::Responses::DNSRecords

Retrieve a list of DNS records for the given zone

Example: Hello, world Example: ello, worl Example: o, world Example: Hello, world Example: Hello, w Example: 127.0.0.1 Example: 7.0.0. Example: .0.1 Example: 127.0.0.1 Example: 127.0. Allowed values: asc, desc Default: asc Example: desc Allowed values: any, all Default: all Example: any Example: www.example.com Example: w.example. Example: .example.com Example: www.example.com Example: www.example Allowed values: type, name, content, ttl, proxied Default: type Example: name >= 1 Default: 1 >= 1 <= 5000000 Default: 100 Default: false Example: true Example: www.cloudflare.com Example: important Example: important Example: greeting:ello, world Example: greeting:ello, world Example: greeting:ello, world Example: greeting:ello, world Allowed values: A, AAAA, CAA, CERT, CNAME, DNSKEY, DS, HTTPS, LOC, MX, NAPTR, NS, OPENPGPKEY, PTR, SMIMEA, SRV, SSHFP, SVCB, TLSA, TXT, URI Default: A Example: A

Parameters:

  • zone (String)

    Zone to retrieve DNS records for

  • opts (Hash)

    Additional query options

Options Hash (opts):

  • :name (String)

    Name of DNS record to search for

  • :type (String)

    Type of DNS record to search for

  • :page (Integer)

    Page number to retrieve

  • :per_page (Integer)

    Number of items per page

  • :order (String)

    Direction of results

  • :comment (String)

    Exact value of the DNS record comment. This is a convenience alias for comment.exact.

  • :"comment.absent" (String)

    If this parameter is present, only records without a comment are returned.

  • :"comment.contains" (String)

    Substring of the DNS record comment. Comment filters are case-insensitive.

  • :"comment.endswith" (String)

    Suffix of the DNS record comment. Comment filters are case-insensitive.

  • :"comment.present" (String)

    If this parameter is present, only records with a comment are returned.

  • :"comment.exact" (String)

    Exact value of the DNS record comment. Comment filters are case-insensitive.

  • :"comment.startswith" (String)

    Prefix of the DNS record comment. Comment filters are case-insensitive.

  • :content (String)

    Exact value of the DNS record content. This is a convenience alias for content.exact.

  • :"content.contains" (String)

    Substring of the DNS record content. Content filters are case-insensitive.

  • :"content.endswith" (String)

    Suffix of the DNS record content. Content filters are case-insensitive.

  • :"content.exact" (String)

    Exact value of the DNS record content. Content filters are case-insensitive.

  • :"content.startswith" (String)

    Prefix of the DNS record content. Content filters are case-insensitive.

  • :direction (String)

    Direction to order DNS records in.

  • :match (String)

    Whether to match all search requirements or at least one (any). If set to all, acts like a logical AND between filters. If set to any, acts like a logical OR instead. Note that the interaction between tag filters is controlled by the tag-match parameter instead.

  • :name (String)

    Exact value of the DNS record name. This is a convenience alias for name.exact.

  • :name.contains (String)

    Substring of the DNS record name. Name filters are case-insensitive.

  • :name.endswith (String)

    Suffix of the DNS record name. Name filters are case-insensitive.

  • :name.exact (String)

    Exact value of the DNS record name. Name filters are case-insensitive.

  • :name.startswith (String)

    Prefix of the DNS record name. Name filters are case-insensitive.

  • :order (String)

    Field to order DNS records by.

  • :page (String)

    Page number of paginated results.

  • :per_page (Integer)

    Number of DNS records per page.

  • :proxied (String)

    Whether the record is receiving the performance and security benefits of Cloudflare.

  • :search (String)

    Allows searching in multiple properties of a DNS record simultaneously. This parameter is intended for human users, not automation. Its exact behavior is intentionally left unspecified and is subject to change in the future. This parameter works independently of the match setting. For automated searches, please use the other available parameters.

  • :tag (String)

    Name of a tag which must not be present on the DNS record. Tag filters are case-insensitive.

  • :tag.absent (String)

    Name of a tag which must not be present on the DNS record. Tag filters are case-insensitive.

  • :tag.contains (String)

    A tag and value, of the form <tag-name>:<tag-value>. The API will only return DNS records that have a tag named <tag-name> whose value contains <tag-value>. Tag filters are case-insensitive.

  • :tag.endswith (String)

    Name of a tag whose value must end with the given value. Tag filters are case-insensitive.

  • :tag.exact (String)

    Name of a tag whose value must exactly match the given value. Tag filters are case-insensitive.

  • :tag.startswith (String)

    Name of a tag whose value must start with the given value. Tag filters are case-insensitive.

  • :type (String)

    Type of the DNS record.

Returns:



133
134
135
136
137
# File 'lib/cloud_party/nodes/dns_records.rb', line 133

def list(zone, opts)
  zone_id = DNSRecords.zone_id_by_name(zone)
  
  CloudParty::Responses::DNSRecords.new(:get, '/zones/:id/dns_records', self.class.get("/zones/#{zone_id}/dns_records", query: opts), @options)
end

#rem(id, zone: nil) ⇒ Object



182
183
184
185
186
187
188
189
# File 'lib/cloud_party/nodes/dns_records.rb', line 182

def rem(id, zone: nil)
  zone_id = zone_id_by_name(zone)
  CloudParty::Responses::DNSRecords.new(
      :delete,
      '/zones/:id/dns_records/:identifier',
      self.class.delete("/zones/#{zone_id}/dns_records/#{id}")
      )
end

#search(zone, query) ⇒ Object



139
140
141
142
# File 'lib/cloud_party/nodes/dns_records.rb', line 139

def search(zone, query)
  zone_id = DNSRecords.zone_id_by_name(zone)
  CloudParty::Responses::DNSRecords.new(:get, '/zones/:id/dns_records', self.class.get("/zones/#{zone_id}/dns_records", @options), @options)
end

#update(id, type, name, content, opts, zone: nil) ⇒ Object



190
191
192
193
# File 'lib/cloud_party/nodes/dns_records.rb', line 190

def update(id, type, name, content, opts, zone: nil)
  zone_id = zone_id_by_name(zone)

end