lib/contrast/utils/job_servers_running.rb in contrast-agent-6.15.1 vs lib/contrast/utils/job_servers_running.rb in contrast-agent-6.15.2
- old
+ new
@@ -1,28 +1,25 @@
# Copyright (c) 2023 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true
-require 'contrast/components/logger'
+require 'contrast/components/ruby_component'
module Contrast
module Utils
# A module that detects whether any job servers attached to
# the application are running
module JobServersRunning
- extend Contrast::Components::Logger::InstanceMethods
-
class << self
def job_servers_running?
sidekiq_running? || rake_running?
end
private
def sidekiq_running?
return unless defined?(Sidekiq) && Sidekiq.cs__respond_to?(:server?) && Sidekiq.server?
- logger.trace('Detected the spawn of a Sidekiq process')
true
end
def rake_running?
unless defined?(Rake) &&
@@ -30,16 +27,21 @@
Rake.application.cs__respond_to?(:top_level_tasks)
return
end
- disabled_rake_tasks = ::Contrast::APP_CONTEXT.disabled_agent_rake_tasks
+ # This might be called before component even exist, so we backup to
+ # default disabled rake tasks.
+ disabled_rake_tasks = if Contrast.const_defined?(:APP_CONTEXT) # rubocop:disable Security/Module/ConstDefined
+ Contrast::APP_CONTEXT.disabled_agent_rake_tasks
+ else
+ Contrast::Components::Ruby::Interface::DISABLED_RAKE_TASK_LIST
+ end
has_disabled_task = Rake.application.top_level_tasks.any? do |top_level_task|
disabled_rake_tasks.include?(top_level_task)
end
return false unless has_disabled_task
- logger.trace('Detected startup within Rake task')
true
end
end
end
end