Class: Boris::Options

Inherits:
Object
  • Object
show all
Includes:
Lumberjack
Defined in:
lib/boris/options.rb

Instance Attribute Summary collapse

Attributes included from Lumberjack

#logger

Instance Method Summary collapse

Methods included from Lumberjack

#debug, #error, #fatal, #info, #warn

Constructor Details

#initialize(options = {}) ⇒ Options

Creates our options hash where the user can pass in an optional hash to immediately override the default values.

credentials = [:password=>'mypassword', :connection_types=>[:ssh, :wmi]] ssh_keys = ['/home/joe/private_key'] options = Boris::Options.new(:log_level=>:debug, :credentials=>credentials, :ssh_options=>:keys=>ssh_keys)

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :auto_scrub_data (Boolean)

    should the target's data be scrubbed after running #retrieve_all?

  • :credentials (Array)

    an array of credentials in the format of :user, :password, :connection_types. Only :user is mandatory.

  • profilers (Array)

    An array of module names of the profilers we wish to have available for use on this target. Profilers::RedHat and Profilers::Solaris are always the defaults, and Windows profilers are included as defaults as well if Boris is running on a Windows host (where WMI connections are available)

  • snmp_options (Hash)

    A hash of options supported by ruby-snmp.

  • ssh_options (Hash)

    A hash of options supported by net-ssh.

Raises:

  • ArgumentError when invalid arguments are passed



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/boris/options.rb', line 41

def initialize(options={})
  @logger = Boris.logger
  @options = {}

  # set our defaults

  @options[:auto_scrub_data] ||= true
  @options[:credentials] ||= []
  if !@options[:profilers]
    
    @options[:profilers] = [
      Profilers::RHEL5,
      Profilers::RHEL6,
      Profilers::Solaris10,
      Profilers::Solaris11
    ]

    if PLATFORM == :win32
      @options[:profilers].concat([
        Profilers::Windows2003,
        Profilers::Windows2008,
        Profilers::Windows2012
      ])
    end
    
  end
  @options[:snmp_options] ||= {}
  @options[:ssh_options] ||= {}

  invalid_options = options.keys - @options.keys
  if invalid_options.any?
    raise ArgumentError, "invalid options specified (#{invalid_options.join(", ")})"
  end

  # override the defaults with passed in Options

  @options.merge!(options)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



19
20
21
# File 'lib/boris/options.rb', line 19

def options
  @options
end

Instance Method Details

#[](key) ⇒ Object

Getter method for grabbing a value from the Options. puts options #=> [Profilers::RedHat]

Parameters:

  • key

    symbol of the key-value pair

Returns:

  • returns the value of specified key from Options



83
84
85
# File 'lib/boris/options.rb', line 83

def [](key)
  @options[key]
end

#[]=(key, val) ⇒ Object

Setter method for setting the value in the options hash puts options #=> [Profilers::RedHat] options << Bases::Solaris puts options #=> [Profilers::RedHat, Profilers::Solaris]

Raises:

  • ArgumentError when invalid options are provided



92
93
94
95
# File 'lib/boris/options.rb', line 92

def []=(key, val)
  raise ArgumentError, 'invalid option provided' if !@options.has_key?(key)
  @options[key] = val
end

#add_credential(cred) ⇒ Object

Provides a simple mechanism for adding credentials to the credentials array of Options. The connection types provided here tell Boris which connection methods this credential should be used for. If no connection types are provided, Boris will try to connect using all available connection types with this credential.

@target.options.add_credential(:password=>'mypassword', :connection_types=>[:ssh, :wmi])

Parameters:

  • cred (Hash)

    a credential hash. Values include :user, :password, and :connection_types. :user is mandatory, and :connection_types should be an Array.

Raises:

  • ArgumentError when invalid credentials or connection_types are supplied



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/boris/options.rb', line 106

def add_credential(cred)
  raise ArgumentError, 'invalid credential supplied (must be Hash)' if !cred.kind_of?(Hash)
  raise ArgumentError, 'user required' if !cred[:user]

  cred[:connection_types] ||= VALID_CONNECTION_TYPES

  invalid_options = cred[:connection_types] - VALID_CONNECTION_TYPES
  if invalid_options.any?
    raise ArgumentError, "invalid connection method specified (#{invalid_options.join(', ')})"
  end

  @options[:credentials] << cred unless @options[:credentials].include?(cred)
end