Class: AcmeNsupdate::Nsupdate

Inherits:
Object
  • Object
show all
Defined in:
lib/acme_nsupdate/nsupdate.rb

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ Nsupdate

Returns a new instance of Nsupdate.



8
9
10
11
# File 'lib/acme_nsupdate/nsupdate.rb', line 8

def initialize(logger)
  @logger = logger
  @commands = []
end

Instance Method Details

#add(label, type, data, ttl) ⇒ Object



21
22
23
# File 'lib/acme_nsupdate/nsupdate.rb', line 21

def add label, type, data, ttl
  @commands << "update add #{label} #{ttl} #{type} #{data}"
end

#del(label, type = nil, data = nil) ⇒ Object



25
26
27
# File 'lib/acme_nsupdate/nsupdate.rb', line 25

def del label, type=nil, data=nil
  @commands << "update del #{label}#{" #{type}" if type}#{" #{data}" if data}"
end

#sendObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/acme_nsupdate/nsupdate.rb', line 29

def send
  @logger.debug("Starting nsupdate:")
  Open3.popen3("nsupdate") do |stdin, stdout, stderr, wait_thr|
    @commands.each do |command|
      @logger.debug "  #{command}"
      stdin.puts command
    end
    @logger.debug("  send")
    stdin.puts "send"
    stdin.close
    errors = stdout.readlines.map {|line| line[/^>\s*(.*)$/, 1].strip }.reject(&:empty?)
    errors.concat stderr.readlines.map(&:strip).reject(&:empty?)
    stdout.close
    stderr.close
    unless errors.empty?
      errors = errors.join(" ")
      @logger.error "DNS update transaction failed: #{errors}"
      @logger.info "Transaction:"
      @commands.each do |command|
        @logger.info "  #{command}"
      end
      raise Error.new errors
    end
  end
end

#server(server) ⇒ Object



13
14
15
# File 'lib/acme_nsupdate/nsupdate.rb', line 13

def server server
  @commands << "server #{server}"
end

#tsig(name, key) ⇒ Object



17
18
19
# File 'lib/acme_nsupdate/nsupdate.rb', line 17

def tsig name, key
  @commands << "key #{name} #{key}"
end