Sha256: 609cc53f81186df1f4624a4890d90f0b977826c1b92dcaa48be5b2b5bbd447b7

Contents?: true

Size: 1.98 KB

Versions: 12

Compression:

Stored size: 1.98 KB

Contents

require 'nettica/client'
module Rubber
  module Dns

    class Nettica < Base

      def initialize(env)
        super(env)
        @nettica_env = @env.dns_providers.nettica
        @client = ::Nettica::Client.new(@nettica_env.user, @nettica_env.password)
        @ttl = (@nettica_env.ttl || 300).to_i
        @record_type = @nettica_env.record_type || "A"
      end

      def nameserver
        "dns1.nettica.com"
      end

      def host_exists?(host)
        domain_info = @client.list_domain(env.domain)
        raise "Domain needs to exist in nettica before records can be updated" unless domain_info.record
        return domain_info.record.any? { |r| r.hostName == host }
      end

      def create_host_record(host, ip)
        new = @client.create_domain_record(env.domain, host, @record_type, ip, @ttl, 0)
        @client.add_record(new)
      end

      def destroy_host_record(host)
        old_record = @client.list_domain(env.domain).record.find {|r| r.hostName == host }
        old = @client.create_domain_record(env.domain, host, old_record.recordType, old_record.data, old_record.tTL, old_record.priority)
        @client.delete_record(old)
      end

      def update_host_record(host, ip)
        old_record = @client.list_domain(env.domain).record.find {|r| r.hostName == host }
        update_record(host, ip, old_record)
      end

      # update the top level domain record which has an empty hostName
      def update_domain_record(ip)
        old_record = @client.list_domain(env.domain).record.find {|r| r.hostName == '' and r.recordType == 'A' and r.data =~ /\A\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/}
        update_record('', ip, old_record)
      end

      def update_record(host, ip, old_record)
        old = @client.create_domain_record(env.domain, host, old_record.recordType, old_record.data, old_record.tTL, old_record.priority)
        new = @client.create_domain_record(env.domain, host, @record_type, ip, @ttl, 0)
        @client.update_record(old, new)
      end

    end

  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
sml-rubber-0.9.10 lib/rubber/dns/nettica.rb
sml-rubber-0.9.11 lib/rubber/dns/nettica.rb
sml-rubber-0.9.13 lib/rubber/dns/nettica.rb
sml-rubber-0.9.3 lib/rubber/dns/nettica.rb
sml-rubber-0.9.4 lib/rubber/dns/nettica.rb
sml-rubber-0.9.5 lib/rubber/dns/nettica.rb
sml-rubber-0.9.6 lib/rubber/dns/nettica.rb
sml-rubber-0.9.7 lib/rubber/dns/nettica.rb
sml-rubber-0.9.8 lib/rubber/dns/nettica.rb
sml-rubber-0.9.9 lib/rubber/dns/nettica.rb
wr0ngway-rubber-1.0.0 lib/rubber/dns/nettica.rb
wr0ngway-rubber-1.0.1 lib/rubber/dns/nettica.rb