Class: Inspec::Resources::PhpConfig
- Inherits:
-
Object
- Object
- Inspec::Resources::PhpConfig
- Defined in:
- lib/inspec/resources/php_config.rb
Instance Attribute Summary collapse
-
#config_file_or_path ⇒ Object
readonly
Resource initialization.
-
#config_param ⇒ Object
readonly
Resource initialization.
Instance Method Summary collapse
-
#initialize(config_param, config_file_or_path = {}) ⇒ PhpConfig
constructor
A new instance of PhpConfig.
-
#resource_id ⇒ Object
Unique resource id.
-
#to_s ⇒ Object
Resource appearance in test reports.
-
#value ⇒ Object
Returns the value evaluated for the initialized config parameter.
Constructor Details
#initialize(config_param, config_file_or_path = {}) ⇒ PhpConfig
Returns a new instance of PhpConfig.
23 24 25 26 |
# File 'lib/inspec/resources/php_config.rb', line 23 def initialize(config_param, config_file_or_path = {}) @config_param = config_param @config_file_or_path = config_file_or_path end |
Instance Attribute Details
#config_file_or_path ⇒ Object (readonly)
Resource initialization.
22 23 24 |
# File 'lib/inspec/resources/php_config.rb', line 22 def config_file_or_path @config_file_or_path end |
#config_param ⇒ Object (readonly)
Resource initialization.
22 23 24 |
# File 'lib/inspec/resources/php_config.rb', line 22 def config_param @config_param end |
Instance Method Details
#resource_id ⇒ Object
Unique resource id
29 30 31 |
# File 'lib/inspec/resources/php_config.rb', line 29 def resource_id config_param end |
#to_s ⇒ Object
Resource appearance in test reports.
34 35 36 |
# File 'lib/inspec/resources/php_config.rb', line 34 def to_s "php_config #{resource_id}" end |
#value ⇒ Object
Returns the value evaluated for the initialized config parameter
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/inspec/resources/php_config.rb', line 39 def value php_utility = find_utility_or_error # The keys in the hash provided by user can be string or symbols. # Converting the key to symbols to handle scenario when "ini" key is provided as string. config_file_or_path.transform_keys(&:to_sym) # Assign the path with -c option for ini file provided by the user if any. php_ini_file = !config_file_or_path.empty? && config_file_or_path.key?(:ini) ? "-c #{config_file_or_path[:ini]}" : "" # The below command `get_cfg_var` is used to fetch the value for any config parameter. php_cmd = "#{php_utility} #{php_ini_file} -r 'echo get_cfg_var(\"#{config_param}\");'" config_value_cmd = inspec.command(php_cmd) raise Inspec::Exceptions::ResourceFailed, "Executing #{php_cmd} failed: #{config_value_cmd.stderr}" if config_value_cmd.exit_status.to_i != 0 config_value = config_value_cmd.stdout.strip # Convert value to integer if the config value are digits. config_value.match(/^(\d)+$/) ? config_value.to_i : config_value end |