Class: DNSUpdater::Updaters::PowerDNS

Inherits:
Updater
  • Object
show all
Defined in:
lib/dnsupdater/updaters/powerdns.rb

Overview

PowerDNS updater

Defined Under Namespace

Classes: Error

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Updater

#initialize

Constructor Details

This class inherits a constructor from DNSUpdater::Updaters::Updater

Class Method Details

.getHostPort(config) ⇒ Object



46
47
48
49
50
51
# File 'lib/dnsupdater/updaters/powerdns.rb', line 46

def self.getHostPort(config)
    [
        config['PowerDNS']['API']['Host'],
        config['PowerDNS']['API']['Port']
    ]
end

Instance Method Details

#update(params) ⇒ Object

Raises:

See Also:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/dnsupdater/updaters/powerdns.rb', line 19

def update(params)
    fillParams(params)

    raise Error, "Domain can't be empty!" if params[:Domain].to_s.empty?

    zone = getZone(params[:Server], params[:Port], params[:Domain])

    records = []
    getIPs(params[:IPs]).each do |ipAddr|
        type = ipAddr.ipv6? ? 'AAAA' : 'A'
        records << {
            name: Addressable::IDNA.to_ascii(params[:Domain]) + '.',
            type: type,
            records: ipAddr.to_s,
            ttl: params[:TTL]
        }
    end

    result = zone.update(*records)
    return unless result.key?(:error)

    errorMessage = result[:error]
    errorMessage = result[:result] if errorMessage =~ /Non-JSON/
    raise Error, self.class.name + ': ' + errorMessage
end