class DNSUpdater::Updaters::PowerDNS
PowerDNS
updater
Public Class Methods
getHostPort(config)
click to toggle source
@see Updater.getHostPort
# File lib/dnsupdater/updaters/powerdns.rb, line 46 def self.getHostPort(config) [ config['PowerDNS']['API']['Host'], config['PowerDNS']['API']['Port'] ] end
Public Instance Methods
update(params)
click to toggle source
@see Updater#update
# 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
Private Instance Methods
fillParams(params)
click to toggle source
# File lib/dnsupdater/updaters/powerdns.rb, line 87 def fillParams(params) apiConfig = @Config['PowerDNS']['API'] params[:Server] = apiConfig['Host'] unless params[:Server] params[:Port] = apiConfig['Port'] unless params[:Port] params[:TTL] = @Config['PowerDNS']['TTL'] params end
getClient(key, host = 'localhost', port = 8081)
click to toggle source
# File lib/dnsupdater/updaters/powerdns.rb, line 55 def getClient(key, host = 'localhost', port = 8081) require 'pdns_api' @pdns ||= PDNS::Client.new( host: host, port: port, key: key, version: 1 ) @pdns end
getServer(server, port)
click to toggle source
# File lib/dnsupdater/updaters/powerdns.rb, line 68 def getServer(server, port) apiConfig = @Config['PowerDNS']['API'] if apiConfig['Shared'] host = apiConfig['Host'] port = apiConfig['Port'] else host = server server = 'localhost' end key = apiConfig['Key'] getClient(key, host, port).server(server) end
getZone(server, port, domain)
click to toggle source
# File lib/dnsupdater/updaters/powerdns.rb, line 81 def getZone(server, port, domain) zoneDomain = PublicSuffix.domain(domain) getServer(server, port).zone(Addressable::IDNA.to_ascii(zoneDomain)) end