module Console1984::Shield::Modes

Console 1984 operates in two modes:

Tampering attempts (such as deleting audit trails) is prevented in both modes.

Constants

PROTECTED_MODE
UNPROTECTED_MODE

Public Instance Methods

enable_protected_mode(silent: false) click to toggle source

Switch to unprotected mode

Pass +silent: true+ to hide an informative message when switching to this mode.

# File lib/console1984/shield/modes.rb, line 32
def enable_protected_mode(silent: false)
  command_executor.run_as_system do
    show_warning Console1984.enter_protected_mode_warning if !silent && unprotected_mode?
    session_logger.end_sensitive_access
    nil
  end
ensure
  @mode = PROTECTED_MODE
  nil
end
enable_unprotected_mode(silent: false) click to toggle source

Switch to protected mode

Pass +silent: true+ to hide an informative message when switching to this mode.

# File lib/console1984/shield/modes.rb, line 17
def enable_unprotected_mode(silent: false)
  command_executor.run_as_system do
    show_warning Console1984.enter_unprotected_encryption_mode_warning if !silent && protected_mode?
    justification = ask_for_value "\nBefore you can access personal information, you need to ask for and get explicit consent from the user(s). #{current_username}, where can we find this consent (a URL would be great)?"
    session_logger.start_sensitive_access justification
    nil
  end
ensure
  @mode = UNPROTECTED_MODE
  nil
end
protected_mode?() click to toggle source
# File lib/console1984/shield/modes.rb, line 52
def protected_mode?
  !unprotected_mode?
end
unprotected_mode?() click to toggle source
# File lib/console1984/shield/modes.rb, line 48
def unprotected_mode?
  @mode.is_a?(Unprotected)
end
with_protected_mode(&block) click to toggle source

Executes the passed block in the configured mode (protected or unprotected).

# File lib/console1984/shield/modes.rb, line 44
def with_protected_mode(&block)
  @mode.execute(&block)
end

Private Instance Methods

current_username() click to toggle source
# File lib/console1984/shield/modes.rb, line 57
def current_username
  username_resolver.current
end