Sha256: ae9dd5ee477fa69e4d278eedc23cf52972e9c76c5e1203b6c13369ba7fc9df02

Contents?: true

Size: 1.55 KB

Versions: 18

Compression:

Stored size: 1.55 KB

Contents

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

module Contrast
  module Components
    # A wrapper build around the Common Agent Configuration project to allow
    # for access of the values contained in its
    # parent_configuration_spec.yaml.
    # Specifically, this allows for querying the state of the Application,
    # including the Client, Process, and Server information.
    module AppContextExtend
      SUPPORTED_FRAMEWORKS = %w[rails sinatra grape rack].cs__freeze
      SUPPORTED_SERVERS = %w[passenger puma thin unicorn].cs__freeze

      def pid
        Process.pid
      end

      def ppid
        Process.ppid
      end

      def app_and_server_information
        {
            application_info: find_gem_information(SUPPORTED_FRAMEWORKS),
            server_info: find_gem_information(SUPPORTED_SERVERS)
        }
      end

      def find_gem_information arr
        arr.each do |framework|
          next unless Gem.loaded_specs.key?(framework)

          loaded = Gem.loaded_specs[framework]
          next unless loaded

          name = loaded.instance_variable_get(:@name)
          version = loaded.instance_variable_get(:@version).to_s
          return [name, version].join(' ')
        end
        nil
      end

      def instrument_middleware_stack?
        !Contrast::Utils::JobServersRunning.job_servers_running?
      end

      def disabled_agent_rake_tasks
        ::Contrast::CONFIG.agent.ruby.disabled_agent_rake_tasks
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
contrast-agent-7.6.1 lib/contrast/components/app_context_extend.rb
contrast-agent-7.6.0 lib/contrast/components/app_context_extend.rb
contrast-agent-7.5.0 lib/contrast/components/app_context_extend.rb
contrast-agent-7.4.1 lib/contrast/components/app_context_extend.rb
contrast-agent-7.4.0 lib/contrast/components/app_context_extend.rb
contrast-agent-7.3.2 lib/contrast/components/app_context_extend.rb
contrast-agent-7.3.1 lib/contrast/components/app_context_extend.rb
contrast-agent-7.3.0 lib/contrast/components/app_context_extend.rb
contrast-agent-7.2.0 lib/contrast/components/app_context_extend.rb
contrast-agent-7.1.0 lib/contrast/components/app_context_extend.rb
contrast-agent-7.0.0 lib/contrast/components/app_context_extend.rb
contrast-agent-6.15.3 lib/contrast/components/app_context_extend.rb
contrast-agent-6.15.2 lib/contrast/components/app_context_extend.rb
contrast-agent-6.15.1 lib/contrast/components/app_context_extend.rb
contrast-agent-6.15.0 lib/contrast/components/app_context_extend.rb
contrast-agent-6.14.0 lib/contrast/components/app_context_extend.rb
contrast-agent-6.13.0 lib/contrast/components/app_context_extend.rb
contrast-agent-6.12.0 lib/contrast/components/app_context_extend.rb