Class: OVH::Provisioner::APIObject::DomainZone

Inherits:
APIObject
  • Object
show all
Defined in:
lib/ovh/provisioner/api_object/domain_zone.rb

Overview

Represent a Domain

Instance Attribute Summary collapse

Attributes inherited from APIObject

#id

Instance Method Summary collapse

Methods inherited from APIObject

#<=>, attr_reader, attributes, #attributes, classname, #config, #delete, entrypoint, #get, #init_properties, #initialize, #post, underscore

Constructor Details

This class inherits a constructor from OVH::Provisioner::APIObject::APIObject

Instance Attribute Details

#dnssecObject (readonly)

Returns the value of attribute dnssec.



24
25
26
# File 'lib/ovh/provisioner/api_object/domain_zone.rb', line 24

def dnssec
  @dnssec
end

#dnssec_supportedObject (readonly)

Returns the value of attribute dnssec_supported.



24
25
26
# File 'lib/ovh/provisioner/api_object/domain_zone.rb', line 24

def dnssec_supported
  @dnssec_supported
end

#nameserversObject (readonly)

Returns the value of attribute nameservers.



24
25
26
# File 'lib/ovh/provisioner/api_object/domain_zone.rb', line 24

def nameservers
  @nameservers
end

#recordsObject (readonly)

Returns the value of attribute records.



24
25
26
# File 'lib/ovh/provisioner/api_object/domain_zone.rb', line 24

def records
  @records
end

Instance Method Details

#add_record(subdomain, type, target, ttl = 0) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ovh/provisioner/api_object/domain_zone.rb', line 35

def add_record(subdomain, type, target, ttl = 0)
  body = {
    'fieldType' => type.upcase,
    'target' => target,
    'ttl' => ttl.to_i
  }
  sub = subdomain
  body['subDomain'] = sub unless sub.nil? || sub.empty?
  answer = post('record', body)
  post('refresh')
  format(answer)
end

#details(record_lists = records) ⇒ Object



30
31
32
33
# File 'lib/ovh/provisioner/api_object/domain_zone.rb', line 30

def details(record_lists = records)
  "#{id} - dnssec: #{dnssec_to_s}\n"\
    "#{(record_lists.format('type').lines[1..-1] || []).join('')}"
end

#filter_records(config) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ovh/provisioner/api_object/domain_zone.rb', line 59

def filter_records(config)
  filter = generate_filter(
    config['subdomain'] || '',
    config['type'] || '',
    config['target'] || '',
    config['ttl'] || ''
  )
  targets = records.list.dup.keep_if do |record|
    filter.call(record)
  end.map(&:id)
  Actor[Spawner::NAME].get('Record', *targets, parent: @url)
end

#rm_record(record) ⇒ Object



48
49
50
51
52
# File 'lib/ovh/provisioner/api_object/domain_zone.rb', line 48

def rm_record(record)
  out = delete("record/#{record.id}")
  post('refresh')
  "  #{record}#{out.nil? ? '' : ": #{out}"}"
end

#rm_records(records) ⇒ Object



54
55
56
57
# File 'lib/ovh/provisioner/api_object/domain_zone.rb', line 54

def rm_records(records)
  outputs = records.parallel_map(:rm_record, [], Actor.current)
  (["#{id}, remove records:"] + outputs.sort).join("\n")
end

#to_sObject



26
27
28
# File 'lib/ovh/provisioner/api_object/domain_zone.rb', line 26

def to_s
  "#{id}, dnssec #{dnssec_to_s}, #{records.list.size} records"
end