Class: Boris::Options
- Inherits:
-
Object
- Object
- Boris::Options
- Includes:
- Lumberjack
- Defined in:
- lib/boris/options.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Attributes included from Lumberjack
Instance Method Summary collapse
-
#[](key) ⇒ Object
Getter method for grabbing a value from the Options.
- #[]=(key, val) ⇒ Object
-
#add_credential(cred) ⇒ Object
Provides a simple mechanism for adding credentials to the credentials array of Options.
-
#initialize(options = {}) ⇒ Options
constructor
Creates our options hash where the user can pass in an optional hash to immediately override the default values.
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)
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(={}) @logger = Boris.logger = {} # set our defaults [:auto_scrub_data] ||= true [:credentials] ||= [] if ![:profilers] [:profilers] = [ Profilers::RHEL5, Profilers::RHEL6, Profilers::Solaris10, Profilers::Solaris11 ] if PLATFORM == :win32 [:profilers].concat([ Profilers::Windows2003, Profilers::Windows2008, Profilers::Windows2012 ]) end end [:snmp_options] ||= {} [:ssh_options] ||= {} = .keys - .keys if .any? raise ArgumentError, "invalid options specified (#{invalid_options.join(", ")})" end # override the defaults with passed in Options .merge!() end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
19 20 21 |
# File 'lib/boris/options.rb', line 19 def end |
Instance Method Details
#[](key) ⇒ Object
Getter method for grabbing a value from the Options. puts options #=> [Profilers::RedHat]
83 84 85 |
# File 'lib/boris/options.rb', line 83 def [](key) [key] end |
#[]=(key, val) ⇒ Object
92 93 94 95 |
# File 'lib/boris/options.rb', line 92 def []=(key, val) raise ArgumentError, 'invalid option provided' if !.has_key?(key) [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])
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 = cred[:connection_types] - VALID_CONNECTION_TYPES if .any? raise ArgumentError, "invalid connection method specified (#{invalid_options.join(', ')})" end [:credentials] << cred unless [:credentials].include?(cred) end |