Class: Simp::Cli::Config::Item::DNSSearch

Inherits:
ListItem show all
Defined in:
lib/simp/cli/config/item/dns_search.rb

Instance Attribute Summary collapse

Attributes inherited from ListItem

#allow_empty_list

Attributes inherited from Simp::Cli::Config::Item

#allow_user_apply, #config_items, #description, #die_on_apply_fail, #fact, #fail_on_missing_answer, #key, #next_items_tree, #silent, #skip_apply, #skip_query, #skip_yaml, #value

Instance Method Summary collapse

Methods inherited from ListItem

#highline_question_type, #not_valid_message, #query_extras, #validate

Methods inherited from Simp::Cli::Config::Item

#apply, #default_value, #highline_question_type, #next_items, #not_valid_message, #print_banner, #print_summary, #puppet_value, #query, #query_ask, #query_extras, #query_status, #safe_apply, #say_blue, #say_green, #say_red, #say_yellow, #to_yaml_s, #validate

Constructor Details

#initializeDNSSearch

Returns a new instance of DNSSearch.



10
11
12
13
14
15
# File 'lib/simp/cli/config/item/dns_search.rb', line 10

def initialize
  super
  @key         = 'dns::search'
  @description = %Q{The DNS domain search string.\nRemember to put these in the appropriate order for your environment!}
  @file        = '/etc/resolv.conf'
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



9
10
11
# File 'lib/simp/cli/config/item/dns_search.rb', line 9

def file
  @file
end

Instance Method Details

#os_valueObject



17
18
19
20
21
# File 'lib/simp/cli/config/item/dns_search.rb', line 17

def os_value
  # TODO: make this a custom fact?
  # NOTE: the resolver only uses the last of multiple search declarations
  File.readlines( @file ).select{ |x| x =~ /^search\s+/ }.last.to_s.gsub( /\bsearch\s+/, '').split( /\s+/ )
end

recommend:

- os_value  when present, or:
- ipaddress when present, or:
- a must-change value


27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/simp/cli/config/item/dns_search.rb', line 27

def recommended_value
  os = os_value
  if os.empty?
    if fqdn = @config_items.fetch( 'hostname', nil )
      [fqdn.value.split('.')[1..-1].join('.')]
    else
      ['domain.name (change this)']
    end
  else
    os
  end
end

#validate_item(item) ⇒ Object

Each item must be a valid dns domain TODO: def validate should notice if the search string will contain > 6 items or 256 chars



43
44
45
46
# File 'lib/simp/cli/config/item/dns_search.rb', line 43

def validate_item item
  # return false if !fqdn.is_a? String
  Simp::Cli::Config::Utils.validate_fqdn item
end