lib/contrast/components/app_context.rb in contrast-agent-3.15.0 vs lib/contrast/components/app_context.rb in contrast-agent-3.16.0

- old
+ new

@@ -1,9 +1,10 @@ # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true require 'rubygems/version' +require 'contrast/utils/object_share' module Contrast module Components module AppContext # A wrapper build around the Common Agent Configuration project to allow @@ -13,11 +14,11 @@ # including the Client, Process, and Server information. class Interface include Contrast::Components::ComponentBase include Contrast::Components::Interface - access_component :agent, :analysis, :config + access_component :agent, :analysis, :config, :logging DEFAULT_APP_NAME = 'rails' DEFAULT_APP_PATH = '/' DEFAULT_SERVER_NAME = 'localhost' DEFAULT_SERVER_PATH = '/' @@ -26,55 +27,55 @@ original_pid end def server_type @_server_type ||= begin - tmp = CONFIG.root.server.type - tmp = Contrast::Agent.framework_manager.server_type unless Contrast::Utils::StringUtils.present?(tmp) - tmp - end + tmp = CONFIG.root.server.type + tmp = Contrast::Agent.framework_manager.server_type unless Contrast::Utils::StringUtils.present?(tmp) + tmp + end end def name @_name ||= begin - tmp = CONFIG.root.application.name - tmp = Contrast::Agent.framework_manager.app_name unless Contrast::Utils::StringUtils.present?(tmp) - tmp = File.basename(Dir.pwd) unless Contrast::Utils::StringUtils.present?(tmp) - Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_APP_NAME) - rescue StandardError - DEFAULT_APP_NAME - end + tmp = CONFIG.root.application.name + tmp = Contrast::Agent.framework_manager.app_name unless Contrast::Utils::StringUtils.present?(tmp) + tmp = File.basename(Dir.pwd) unless Contrast::Utils::StringUtils.present?(tmp) + Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_APP_NAME) + rescue StandardError + DEFAULT_APP_NAME + end end def path @_path ||= begin - tmp = CONFIG.root.application.path - Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_APP_PATH) - rescue StandardError - DEFAULT_APP_PATH - end + tmp = CONFIG.root.application.path + Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_APP_PATH) + rescue StandardError + DEFAULT_APP_PATH + end end def server_name @_server_name ||= begin - tmp = CONFIG.root.server.name - tmp = Socket.gethostname unless Contrast::Utils::StringUtils.present?(tmp) - tmp = Contrast::Utils::StringUtils.force_utf8(tmp) - Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_SERVER_NAME) - rescue StandardError - DEFAULT_SERVER_NAME - end + tmp = CONFIG.root.server.name + tmp = Socket.gethostname unless Contrast::Utils::StringUtils.present?(tmp) + tmp = Contrast::Utils::StringUtils.force_utf8(tmp) + Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_SERVER_NAME) + rescue StandardError + DEFAULT_SERVER_NAME + end end def server_path @_server_path ||= begin - tmp = CONFIG.root.server.path - tmp = Dir.pwd unless Contrast::Utils::StringUtils.present?(tmp) - Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_SERVER_PATH) - rescue StandardError - DEFAULT_SERVER_PATH - end + tmp = CONFIG.root.server.path + tmp = Dir.pwd unless Contrast::Utils::StringUtils.present?(tmp) + Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_SERVER_PATH) + rescue StandardError + DEFAULT_SERVER_PATH + end end def build_app_startup_message msg = Contrast::Api::Dtm::ApplicationCreate.new @@ -99,9 +100,17 @@ msg.environment = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.environment msg.server_tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.tags msg.application_tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.tags msg.library_tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.inventory.tags msg.finding_tags = Contrast::Utils::StringUtils.protobuf_format ASSESS.tags + logger.info('Application context', + server_name: msg.server_name, + server_path: msg.server_path, + server_type: msg.server_type, + application_name: name, + application_path: path, + application_language: Contrast::Utils::ObjectShare::RUBY) + msg end def pid Process.pid