Class: SemgrepWebApp::PolicyMode

Inherits:
Object
  • Object
show all
Defined in:
lib/semgrep_web_app/models/policy_mode.rb

Overview

Mode behavior: Monitor / Comment / Block / Disabled | value | description | |-------|---------------| | MODE_MONITOR | Monitor mode, silently report findings | | MODE_COMMENT | Comment mode, leaves PR comments but does not block | | MODE_BLOCK | Block mode, leaves PR comments and blocks PR | | MODE_DISABLED | Disabled mode, not active |

Constant Summary collapse

POLICY_MODE =
[
  # TODO: Write general description for MODE_MONITOR
  MODE_MONITOR = 'MODE_MONITOR'.freeze,

  # TODO: Write general description for MODE_COMMENT
  MODE_COMMENT = 'MODE_COMMENT'.freeze,

  # TODO: Write general description for MODE_BLOCK
  MODE_BLOCK = 'MODE_BLOCK'.freeze,

  # TODO: Write general description for MODE_DISABLED
  MODE_DISABLED = 'MODE_DISABLED'.freeze
].freeze

Class Method Summary collapse

Class Method Details

.from_value(value, default_value = MODE_MONITOR) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/semgrep_web_app/models/policy_mode.rb', line 33

def self.from_value(value, default_value = MODE_MONITOR)
  return default_value if value.nil?

  str = value.to_s.strip

  case str.downcase
  when 'mode_monitor' then MODE_MONITOR
  when 'mode_comment' then MODE_COMMENT
  when 'mode_block' then MODE_BLOCK
  when 'mode_disabled' then MODE_DISABLED
  else
    default_value
  end
end

.validate(value) ⇒ Object



27
28
29
30
31
# File 'lib/semgrep_web_app/models/policy_mode.rb', line 27

def self.validate(value)
  return false if value.nil?

  POLICY_MODE.include?(value)
end