Sha256: e4611bf340a9d5950e1f0cc4c178cd3793b1cc6d8d2166b3a091d5ecd1ebcacc

Contents?: true

Size: 1.93 KB

Versions: 6

Compression:

Stored size: 1.93 KB

Contents

# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

require 'contrast/agent/disable_reaction'
require 'contrast/components/interface'

module Contrast
  module Agent
    # Because communication between the Agent/Service and TeamServer can only
    # be initiated by outbound connections from the Agent/Service, we must
    # provide a mechanism for the TeamServer to direct the Agent to take a
    # specific action. This action is referred to as a Reaction. This class is
    # how we handle those Reaction messages.
    class ReactionProcessor
      include Contrast::Components::Interface
      access_component :logging

      # Process the given Reactions from the application settings based on what
      # TeamServer has indicated. Each Reaction will result in a log message
      # and, optionally, an action.
      #
      # @param application_settings [Contrast::Api::Settings::ApplicationSettings]
      #   those settings which the Service has relayed from TeamServer.
      def self.process application_settings
        return nil unless application_settings&.reactions&.any?

        application_settings.reactions.each do |reaction|
          # the enums are all uppercase, we need to downcase them before attempting to log
          level = reaction.log_level.nil? ? :error : reaction.log_level.name.downcase

          logger.with_level(level, reaction.message) if reaction.message

          case reaction.operation
          when Contrast::Api::Settings::Reaction::Operation::DISABLE
            Contrast::Agent::DisableReaction.run reaction, level
          when Contrast::Api::Settings::Reaction::Operation::NOOP
            # NOOP
          else
            logger.warn(
                'ReactionProcessor received a reaction with an unknown operation',
                operation: reaction.operation)
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
contrast-agent-4.2.0 lib/contrast/agent/reaction_processor.rb
contrast-agent-4.1.0 lib/contrast/agent/reaction_processor.rb
contrast-agent-4.0.0 lib/contrast/agent/reaction_processor.rb
contrast-agent-3.16.0 lib/contrast/agent/reaction_processor.rb
contrast-agent-3.15.0 lib/contrast/agent/reaction_processor.rb
contrast-agent-3.14.0 lib/contrast/agent/reaction_processor.rb