Sha256: 781d518d1822dcfd9a84676e8a047414d7c3c59436d5cd76ecb747b407354e95

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

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

cs__scoped_require 'contrast/components/interface'

module Contrast
  module Utils
    # A utility class to detect the environment the agent is operating within
    class OperatingEnvironment
      include Contrast::Components::Interface
      access_component :logging

      def self.unsupported?
        sidekiq? || rake?
      end

      def self.sidekiq?
        return unless defined?(Sidekiq) && Sidekiq.cs__respond_to?(:server?) && Sidekiq.server?

        logger.debug(nil, "Detected the spawn of a Sidekiq process. Disabling Contrast for process #{ Process.pid }")
        true
      end

      def self.rake?
        return unless defined?(Rake) &&
            Rake.cs__respond_to?(:application) &&
            Rake.application.cs__respond_to?(:top_level_tasks)

        disabled_rake_tasks = Contrast::Agent::FeatureState.instance.disabled_agent_rake_tasks
        disabled_task = Rake.application.top_level_tasks.any? { |task| disabled_rake_tasks.include?(task) }
        return false unless disabled_task

        logger.debug(nil, "Detected startup within the rake task #{ disabled_task }. Disabling Contrast for process #{ Process.pid }")
        true
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
contrast-agent-3.8.5 lib/contrast/utils/operating_environment.rb
contrast-agent-3.8.4 lib/contrast/utils/operating_environment.rb