Module: ChefConfig::Mixin::FuzzyHostnameMatcher

Included in:
Config
Defined in:
lib/chef-config/mixin/fuzzy_hostname_matcher.rb

Instance Method Summary collapse

Instance Method Details

#fuzzy_hostname_match?(hostname, match) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
45
# File 'lib/chef-config/mixin/fuzzy_hostname_matcher.rb', line 41

def fuzzy_hostname_match?(hostname, match)
  # Do greedy matching by adding wildcard if it is not specified
  match = "*" + match unless match.start_with?("*")
  Fuzzyurl.matches?(Fuzzyurl.mask(hostname: match), hostname)
end

#fuzzy_hostname_match_any?(hostname, matches) ⇒ Boolean

Check to see if a hostname matches a match string. Used to see if hosts fall under our no_proxy config

Parameters:

  • hostname (String)

    the hostname to check

  • matches (String)

    the pattern to match

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
# File 'lib/chef-config/mixin/fuzzy_hostname_matcher.rb', line 31

def fuzzy_hostname_match_any?(hostname, matches)
  if hostname && matches
    return matches.to_s.split(/\s*,\s*/).compact.any? do |m|
      fuzzy_hostname_match?(hostname, m)
    end
  end

  false
end