Class: Bifrossht::HostFilter::SearchDomain

Inherits:
Base
  • Object
show all
Defined in:
lib/bifrossht/host_filter/search_domain.rb

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Bifrossht::HostFilter::Base

Instance Method Details

#apply(host) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bifrossht/host_filter/search_domain.rb', line 10

def apply(host)
  prefixes = [''] + config.prefixes

  config.domains.each do |domain|
    prefixes.each do |prefix|
      record = "#{prefix}#{host}.#{domain}"

      begin
        address = Resolv.getaddress record
      rescue Resolv::ResolvError => e
        Logger.debug "SearchDomain: #{e.message}"
      end

      unless address.nil?
        Logger.debug "SearchDomain: using #{record}"
        return record
      end
    end
  end

  host
end

#match(host) ⇒ Object



6
7
8
# File 'lib/bifrossht/host_filter/search_domain.rb', line 6

def match(host)
  host !~ /\./
end