Module: Contrast::Components::ComponentBase
- Includes:
- Contrast::Config::Diagnostics::Tools
- Included in:
- Agent::Interface, Api::Interface, AppContext::Interface, Assess::Interface, AssessRules::Interface, HeapDump::ClassMethods, HeapDump::Interface, Inventory::Interface, Logger::Interface, Polling::Interface, Protect::Interface, Ruby::Interface, Sampling::ClassMethods, Sampling::InstanceMethods, SecurityLogger::Interface, Contrast::Config::CertificationConfiguration, Contrast::Config::ExceptionConfiguration, Contrast::Config::RequestAuditConfiguration, Contrast::Config::ServerConfiguration
- Defined in:
- lib/contrast/components/base.rb
Overview
All components should inherit from this, whether Interfaces, InstanceMethods or ClassMethods.
Constant Summary collapse
- ENABLE =
'enable'
Constants included from Contrast::Config::Diagnostics::Tools
Contrast::Config::Diagnostics::Tools::CHECK
Constants included from Contrast::Config::Diagnostics::SingletonTools
Contrast::Config::Diagnostics::SingletonTools::API_CREDENTIALS, Contrast::Config::Diagnostics::SingletonTools::CONTRAST_MARK
Instance Method Summary collapse
-
#canon_name ⇒ String
Used for config diagnostics.
-
#config_values ⇒ Array
Used for config diagnostics.
-
#false?(config_param) ⇒ Boolean
use this to determine if the configuration value is literally boolean false or some form of the word
false, regardless of case. -
#file_exists?(path) ⇒ Boolean
check if file exists at all.
-
#stringify_array(val, join_char = ',') ⇒ String, Object
attempts to stringify the config value if it is an array with the join char.
-
#to_effective_config(effective_config) ⇒ Object
Converts current configuration to effective config values class and appends them to EffectiveConfig class.
-
#true?(config_param) ⇒ Boolean
use this to determine if the configuration value is literally boolean true or some form of the word
true, regardless of case. -
#valid_cert?(config_path) ⇒ Boolean
this method will check if a path could be possibly used So for example if we pass a path to a file - we’ll check if there is actually that file and if it’s with certain extension.
Methods included from Contrast::Config::Diagnostics::Tools
#add_effective_config_values, #add_single_effective_value
Methods included from Contrast::Config::Diagnostics::SingletonTools
#flatten_settings, #to_config_values, #update_config, #value_to_s
Instance Method Details
#canon_name ⇒ String
Used for config diagnostics. Override per rule.
20 21 22 |
# File 'lib/contrast/components/base.rb', line 20 def canon_name Contrast::Utils::ObjectShare::EMPTY_STRING end |
#config_values ⇒ Array
Used for config diagnostics. Override per rule.
27 28 29 |
# File 'lib/contrast/components/base.rb', line 27 def config_values Contrast::Utils::ObjectShare::EMPTY_ARRAY end |
#false?(config_param) ⇒ Boolean
use this to determine if the configuration value is literally boolean false or some form of the word false, regardless of case. It should be used for those values which default to true as they should only treat a value explicitly set to false as such.
38 39 40 41 42 43 44 |
# File 'lib/contrast/components/base.rb', line 38 def false? config_param return false if config_param == true return true if config_param == false return false unless config_param.cs__is_a?(String) config_param.downcase == Contrast::Utils::ObjectShare::FALSE end |
#file_exists?(path) ⇒ Boolean
check if file exists at all
78 79 80 81 82 |
# File 'lib/contrast/components/base.rb', line 78 def file_exists? path return false unless path File.exist?(path) end |
#stringify_array(val, join_char = ',') ⇒ String, Object
attempts to stringify the config value if it is an array with the join char
97 98 99 100 101 |
# File 'lib/contrast/components/base.rb', line 97 def stringify_array val, join_char = ',' return val.join(join_char) if val.cs__is_a?(Array) && val.any? val end |
#to_effective_config(effective_config) ⇒ Object
Converts current configuration to effective config values class and appends them to EffectiveConfig class.
88 89 90 |
# File 'lib/contrast/components/base.rb', line 88 def to_effective_config effective_config add_effective_config_values(effective_config, config_values, canon_name) end |
#true?(config_param) ⇒ Boolean
use this to determine if the configuration value is literally boolean true or some form of the word true, regardless of case. It should be used for those values which default to false as they should only treat a value explicitly set to true as such.
53 54 55 56 57 58 59 |
# File 'lib/contrast/components/base.rb', line 53 def true? config_param return false if config_param == false return true if config_param == true return false unless config_param.cs__is_a?(String) config_param.downcase == Contrast::Utils::ObjectShare::TRUE end |
#valid_cert?(config_path) ⇒ Boolean
this method will check if a path could be possibly used So for example if we pass a path to a file - we’ll check if there is actually that file and if it’s with certain extension
67 68 69 70 71 72 73 74 |
# File 'lib/contrast/components/base.rb', line 67 def valid_cert? config_path return false if config_path.nil? exts = %w[.pem .crt .cer].cs__freeze return false unless exts.include?(File.extname(config_path)) true end |