Module: Contrast::Utils::InvalidConfigurationUtil
- Includes:
- Components::Interface
- Defined in:
- lib/contrast/utils/invalid_configuration_util.rb
Overview
This utility allows us to report invalid configurations detected in customer applications, as determined by Configuration Rules at runtime.
Constant Summary collapse
- CS__PATH =
'path'- CS__SESSION_ID =
'sessionId'- CS__SNIPPET =
'snippet'
Instance Method Summary collapse
-
#cs__report_finding(rule_id, user_provided_options, call_location) ⇒ Object
Build and report a finding for the given rule.
Methods included from Components::Interface
Instance Method Details
#cs__report_finding(rule_id, user_provided_options, call_location) ⇒ Object
Build and report a finding for the given rule
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/contrast/utils/invalid_configuration_util.rb', line 26 def cs__report_finding rule_id, , call_location with_contrast_scope do finding = Contrast::Api::Dtm::Finding.new finding.rule_id = rule_id path = call_location.path # just get the file name, not the full path path = path.split(Contrast::Utils::ObjectShare::SLASH).last session_id = [:key].to_s if finding.version = Contrast::Agent::Assess::Policy::TriggerMethod::CURRENT_FINDING_VERSION finding.properties[CS__SESSION_ID] = Contrast::Utils::StringUtils.force_utf8(session_id) finding.properties[CS__PATH] = Contrast::Utils::StringUtils.force_utf8(path) file_path = call_location.absolute_path snippet = file_snippet(file_path, call_location) finding.properties[CS__SNIPPET] = Contrast::Utils::StringUtils.force_utf8(snippet) hash = Contrast::Utils::HashDigest.generate_config_hash(finding) finding.hash_code = Contrast::Utils::StringUtils.force_utf8(hash) finding.preflight = Contrast::Utils::PreflightUtil.create_preflight(finding) Contrast::Agent::Assess::Policy::TriggerMethod.report_finding(finding) end rescue StandardError => e logger.error('Unable to build a finding', e, rule: rule_id) end |