contrast-agent 3.12.2 → 3.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.dockerignore +0 -1
- data/.gitignore +1 -1
- data/.simplecov +1 -1
- data/Rakefile +31 -0
- data/exe/contrast_service +1 -7
- data/ext/build_funchook.rb +0 -2
- data/ext/cs__assess_active_record_named/cs__active_record_named.c +8 -7
- data/ext/cs__assess_array/cs__assess_array.c +6 -5
- data/ext/cs__assess_basic_object/cs__assess_basic_object.c +5 -5
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +4 -9
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.h +0 -1
- data/ext/cs__assess_hash/cs__assess_hash.c +18 -17
- data/ext/cs__assess_hash/cs__assess_hash.h +2 -1
- data/ext/cs__assess_kernel/cs__assess_kernel.c +7 -8
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +18 -16
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +1 -0
- data/ext/cs__assess_module/cs__assess_module.c +6 -6
- data/ext/cs__assess_regexp/cs__assess_regexp.c +4 -4
- data/ext/cs__assess_string/cs__assess_string.c +31 -16
- data/ext/cs__assess_string/cs__assess_string.h +6 -1
- data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +4 -7
- data/ext/cs__assess_yield_track/cs__assess_yield_track.c +3 -7
- data/ext/cs__assess_yield_track/cs__assess_yield_track.h +0 -1
- data/ext/cs__common/cs__common.c +63 -30
- data/ext/cs__common/cs__common.h +19 -21
- data/ext/cs__common/extconf.rb +0 -14
- data/ext/cs__contrast_patch/cs__contrast_patch.c +27 -25
- data/ext/cs__contrast_patch/cs__contrast_patch.h +5 -7
- data/ext/cs__protect_kernel/cs__protect_kernel.c +11 -12
- data/ext/cs__protect_kernel/cs__protect_kernel.h +2 -2
- data/ext/extconf_common.rb +0 -28
- data/lib/contrast-agent.rb +1 -1
- data/lib/contrast.rb +15 -23
- data/lib/contrast/agent.rb +51 -39
- data/lib/contrast/agent/assess.rb +12 -12
- data/lib/contrast/agent/assess/contrast_event.rb +40 -185
- data/lib/contrast/agent/assess/events/event_factory.rb +2 -2
- data/lib/contrast/agent/assess/events/source_event.rb +5 -9
- data/lib/contrast/agent/assess/finalizers/freeze.rb +15 -0
- data/lib/contrast/agent/assess/finalizers/hash.rb +97 -0
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +2 -2
- data/lib/contrast/agent/assess/policy/patcher.rb +6 -6
- data/lib/contrast/agent/assess/policy/policy.rb +9 -11
- data/lib/contrast/agent/assess/policy/policy_node.rb +5 -99
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +2 -3
- data/lib/contrast/agent/assess/policy/preshift.rb +13 -7
- data/lib/contrast/agent/assess/policy/propagation_method.rb +64 -45
- data/lib/contrast/agent/assess/policy/propagation_node.rb +6 -2
- data/lib/contrast/agent/assess/policy/propagator.rb +18 -18
- data/lib/contrast/agent/assess/policy/propagator/append.rb +8 -5
- data/lib/contrast/agent/assess/policy/propagator/base.rb +2 -2
- data/lib/contrast/agent/assess/policy/propagator/center.rb +9 -5
- data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +6 -4
- data/lib/contrast/agent/assess/policy/propagator/insert.rb +7 -7
- data/lib/contrast/agent/assess/policy/propagator/keep.rb +4 -1
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +18 -9
- data/lib/contrast/agent/assess/policy/propagator/next.rb +7 -5
- data/lib/contrast/agent/assess/policy/propagator/prepend.rb +13 -5
- data/lib/contrast/agent/assess/policy/propagator/remove.rb +14 -15
- data/lib/contrast/agent/assess/policy/propagator/replace.rb +5 -2
- data/lib/contrast/agent/assess/policy/propagator/reverse.rb +7 -5
- data/lib/contrast/agent/assess/policy/propagator/select.rb +19 -11
- data/lib/contrast/agent/assess/policy/propagator/splat.rb +14 -8
- data/lib/contrast/agent/assess/policy/propagator/split.rb +19 -13
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +36 -26
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +17 -15
- data/lib/contrast/agent/assess/policy/rewriter_patch.rb +5 -5
- data/lib/contrast/agent/assess/policy/source_method.rb +90 -73
- data/lib/contrast/agent/assess/policy/source_validation/cross_site_validator.rb +1 -1
- data/lib/contrast/agent/assess/policy/source_validation/source_validation.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +16 -11
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +2 -2
- data/lib/contrast/agent/assess/policy/trigger_method.rb +41 -26
- data/lib/contrast/agent/assess/policy/trigger_node.rb +30 -17
- data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -1
- data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +2 -2
- data/lib/contrast/agent/assess/properties.rb +15 -383
- data/lib/contrast/agent/assess/property/evented.rb +78 -0
- data/lib/contrast/agent/assess/property/tagged.rb +339 -0
- data/lib/contrast/agent/assess/property/updated.rb +136 -0
- data/lib/contrast/agent/assess/rule.rb +2 -2
- data/lib/contrast/agent/assess/rule/base.rb +3 -4
- data/lib/contrast/agent/assess/rule/provider.rb +3 -3
- data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +1 -1
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +4 -22
- data/lib/contrast/agent/assess/tag.rb +27 -12
- data/lib/contrast/agent/assess/tracker.rb +66 -0
- data/lib/contrast/agent/at_exit_hook.rb +4 -2
- data/lib/contrast/agent/class_reopener.rb +14 -11
- data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +1 -1
- data/lib/contrast/agent/deadzone/policy/policy.rb +2 -2
- data/lib/contrast/agent/disable_reaction.rb +1 -1
- data/lib/contrast/agent/exclusion_matcher.rb +3 -3
- data/lib/contrast/agent/inventory/policy/datastores.rb +2 -3
- data/lib/contrast/agent/inventory/policy/policy.rb +3 -3
- data/lib/contrast/agent/inventory/policy/trigger_node.rb +1 -1
- data/lib/contrast/agent/middleware.rb +36 -48
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +4 -4
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +6 -5
- data/lib/contrast/agent/patching/policy/module_policy.rb +1 -1
- data/lib/contrast/agent/patching/policy/patch.rb +16 -16
- data/lib/contrast/agent/patching/policy/patcher.rb +43 -44
- data/lib/contrast/agent/patching/policy/policy.rb +10 -13
- data/lib/contrast/agent/patching/policy/policy_node.rb +3 -3
- data/lib/contrast/agent/patching/policy/trigger_node.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +3 -3
- data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +3 -3
- data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +3 -3
- data/lib/contrast/agent/protect/policy/policy.rb +8 -8
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +3 -3
- data/lib/contrast/agent/protect/policy/trigger_node.rb +1 -1
- data/lib/contrast/agent/protect/rule.rb +18 -18
- data/lib/contrast/agent/protect/rule/base.rb +21 -32
- data/lib/contrast/agent/protect/rule/base_service.rb +2 -2
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +5 -5
- data/lib/contrast/agent/protect/rule/deserialization.rb +1 -1
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +3 -8
- data/lib/contrast/agent/protect/rule/no_sqli.rb +1 -1
- data/lib/contrast/agent/protect/rule/path_traversal.rb +4 -5
- data/lib/contrast/agent/protect/rule/sqli.rb +2 -2
- data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +1 -1
- data/lib/contrast/agent/protect/rule/xss.rb +1 -1
- data/lib/contrast/agent/protect/rule/xxe.rb +4 -5
- data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +2 -2
- data/lib/contrast/agent/railtie.rb +1 -1
- data/lib/contrast/agent/reaction_processor.rb +5 -5
- data/lib/contrast/agent/request.rb +103 -340
- data/lib/contrast/agent/request_context.rb +25 -21
- data/lib/contrast/agent/request_handler.rb +1 -1
- data/lib/contrast/agent/response.rb +25 -26
- data/lib/contrast/agent/rewriter.rb +6 -9
- data/lib/contrast/agent/scope.rb +1 -1
- data/lib/contrast/agent/service_heartbeat.rb +8 -10
- data/lib/contrast/agent/static_analysis.rb +4 -4
- data/lib/contrast/agent/thread.rb +1 -1
- data/lib/contrast/agent/thread_watcher.rb +49 -0
- data/lib/contrast/agent/tracepoint_hook.rb +1 -1
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/agent/worker_thread.rb +24 -0
- data/lib/contrast/api.rb +4 -6
- data/lib/contrast/api/communication.rb +20 -0
- data/lib/contrast/api/communication/connection_status.rb +41 -0
- data/lib/contrast/api/communication/messaging_queue.rb +76 -0
- data/lib/contrast/{utils/service_response_util.rb → api/communication/response_processor.rb} +10 -19
- data/lib/contrast/api/communication/service_lifecycle.rb +61 -0
- data/lib/contrast/api/communication/socket.rb +45 -0
- data/lib/contrast/api/communication/socket_client.rb +76 -0
- data/lib/contrast/api/communication/speedracer.rb +111 -0
- data/lib/contrast/api/communication/tcp_socket.rb +31 -0
- data/lib/contrast/api/communication/unix_socket.rb +27 -0
- data/lib/contrast/api/decorators.rb +14 -4
- data/lib/contrast/api/decorators/address.rb +61 -0
- data/lib/contrast/api/decorators/application_settings.rb +10 -5
- data/lib/contrast/api/decorators/application_update.rb +7 -17
- data/lib/contrast/api/decorators/http_request.rb +140 -0
- data/lib/contrast/api/decorators/input_analysis.rb +3 -2
- data/lib/contrast/api/decorators/message.rb +76 -0
- data/lib/contrast/api/decorators/rasp_rule_sample.rb +29 -0
- data/lib/contrast/api/decorators/route_coverage.rb +58 -0
- data/lib/contrast/api/decorators/server_features.rb +3 -2
- data/lib/contrast/api/decorators/trace_event.rb +100 -0
- data/lib/contrast/api/decorators/trace_event_object.rb +58 -0
- data/lib/contrast/api/decorators/trace_event_signature.rb +47 -0
- data/lib/contrast/api/decorators/trace_taint_range.rb +52 -0
- data/lib/contrast/api/decorators/trace_taint_range_tags.rb +109 -0
- data/lib/contrast/api/decorators/user_input.rb +40 -0
- data/lib/contrast/common_agent_configuration.rb +2 -2
- data/lib/contrast/components/agent.rb +2 -2
- data/lib/contrast/components/app_context.rb +12 -17
- data/lib/contrast/components/config.rb +8 -23
- data/lib/contrast/components/contrast_service.rb +3 -3
- data/lib/contrast/components/interface.rb +16 -16
- data/lib/contrast/components/logger.rb +1 -1
- data/lib/contrast/components/scope.rb +3 -3
- data/lib/contrast/components/settings.rb +0 -6
- data/lib/contrast/config.rb +18 -18
- data/lib/contrast/config/application_configuration.rb +5 -2
- data/lib/contrast/config/base_configuration.rb +2 -2
- data/lib/contrast/config/protect_rule_configuration.rb +1 -1
- data/lib/contrast/config/service_configuration.rb +8 -2
- data/lib/contrast/configuration.rb +93 -52
- data/lib/contrast/extension/assess.rb +21 -23
- data/lib/contrast/extension/assess/array.rb +12 -9
- data/lib/contrast/extension/assess/erb.rb +6 -3
- data/lib/contrast/extension/assess/eval_trigger.rb +3 -3
- data/lib/contrast/extension/assess/exec_trigger.rb +1 -1
- data/lib/contrast/extension/assess/fiber.rb +12 -12
- data/lib/contrast/extension/assess/hash.rb +5 -4
- data/lib/contrast/extension/assess/kernel.rb +19 -11
- data/lib/contrast/extension/assess/marshal.rb +63 -0
- data/lib/contrast/extension/assess/regexp.rb +8 -7
- data/lib/contrast/extension/assess/string.rb +13 -15
- data/lib/contrast/extension/inventory.rb +4 -5
- data/lib/contrast/extension/kernel.rb +1 -1
- data/lib/contrast/extension/module.rb +1 -1
- data/lib/contrast/extension/protect.rb +3 -3
- data/lib/contrast/extension/protect/kernel.rb +2 -2
- data/lib/contrast/extension/protect/psych.rb +2 -2
- data/lib/contrast/framework/base_support.rb +0 -23
- data/lib/contrast/framework/manager.rb +7 -17
- data/lib/contrast/framework/rack/patch/session_cookie.rb +13 -19
- data/lib/contrast/framework/rack/patch/support.rb +1 -1
- data/lib/contrast/framework/rack/support.rb +2 -2
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +1 -3
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +6 -13
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +1 -1
- data/lib/contrast/framework/rails/patch/support.rb +3 -3
- data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +2 -2
- data/lib/contrast/framework/rails/rewrite/active_record_named.rb +2 -2
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +2 -2
- data/lib/contrast/framework/rails/support.rb +58 -37
- data/lib/contrast/framework/sinatra/patch/base.rb +2 -2
- data/lib/contrast/framework/sinatra/patch/support.rb +1 -1
- data/lib/contrast/framework/sinatra/support.rb +13 -24
- data/lib/contrast/funchook/funchook.rb +45 -0
- data/lib/contrast/logger/application.rb +13 -5
- data/lib/contrast/logger/format.rb +64 -0
- data/lib/contrast/logger/log.rb +17 -9
- data/lib/contrast/logger/request.rb +30 -0
- data/lib/contrast/tasks/config.rb +1 -1
- data/lib/contrast/tasks/service.rb +2 -2
- data/lib/contrast/utils/assess/sampling_util.rb +2 -2
- data/lib/contrast/utils/assess/tracking_util.rb +89 -19
- data/lib/contrast/utils/boolean_util.rb +1 -1
- data/lib/contrast/utils/class_util.rb +2 -2
- data/lib/contrast/utils/duck_utils.rb +0 -10
- data/lib/contrast/utils/env_configuration_item.rb +2 -1
- data/lib/contrast/utils/gemfile_reader.rb +5 -5
- data/lib/contrast/utils/hash_digest.rb +13 -3
- data/lib/contrast/utils/heap_dump_util.rb +2 -2
- data/lib/contrast/utils/invalid_configuration_util.rb +21 -35
- data/lib/contrast/utils/inventory_util.rb +6 -11
- data/lib/contrast/utils/io_util.rb +1 -1
- data/lib/contrast/utils/object_share.rb +0 -1
- data/lib/contrast/utils/os.rb +16 -4
- data/lib/contrast/utils/ruby_ast_rewriter.rb +1 -1
- data/lib/contrast/utils/sha256_builder.rb +2 -2
- data/lib/contrast/utils/stack_trace_utils.rb +2 -3
- data/lib/contrast/utils/string_utils.rb +11 -6
- data/lib/contrast/utils/tag_util.rb +1 -1
- data/lib/contrast/utils/thread_tracker.rb +1 -14
- data/lib/contrast/utils/timer.rb +1 -17
- data/resources/assess/policy.json +0 -10
- data/resources/deadzone/policy.json +5 -0
- data/ruby-agent.gemspec +24 -23
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +92 -92
- data/funchook/Makefile +0 -29
- data/funchook/autom4te.cache/output.0 +0 -4964
- data/funchook/autom4te.cache/requests +0 -77
- data/funchook/autom4te.cache/traces.0 +0 -361
- data/funchook/config.log +0 -651
- data/funchook/config.status +0 -1015
- data/funchook/configure +0 -4964
- data/funchook/src/Makefile +0 -70
- data/funchook/src/config.h +0 -101
- data/funchook/src/config.h.in +0 -100
- data/funchook/src/decoder.o +0 -0
- data/funchook/src/distorm.o +0 -0
- data/funchook/src/funchook.o +0 -0
- data/funchook/src/funchook_io.o +0 -0
- data/funchook/src/funchook_syscall.o +0 -0
- data/funchook/src/funchook_unix.o +0 -0
- data/funchook/src/funchook_x86.o +0 -0
- data/funchook/src/instructions.o +0 -0
- data/funchook/src/insts.o +0 -0
- data/funchook/src/libfunchook.dylib +0 -0
- data/funchook/src/mnemonics.o +0 -0
- data/funchook/src/operands.o +0 -0
- data/funchook/src/os_func.o +0 -0
- data/funchook/src/os_func_unix.o +0 -0
- data/funchook/src/prefix.o +0 -0
- data/funchook/src/printf_base.o +0 -0
- data/funchook/src/textdefs.o +0 -0
- data/funchook/src/wstring.o +0 -0
- data/funchook/test/Makefile +0 -43
- data/funchook/test/funchook_test +0 -0
- data/funchook/test/libfunchook_test.so +0 -0
- data/funchook/test/libfunchook_test.so.dSYM/Contents/Info.plist +0 -20
- data/funchook/test/libfunchook_test.so.dSYM/Contents/Resources/DWARF/libfunchook_test.so +0 -0
- data/funchook/test/test_main.o +0 -0
- data/funchook/test/x86_64_test.o +0 -0
- data/lib/contrast/agent/assess/adjusted_span.rb +0 -27
- data/lib/contrast/agent/assess/insulator.rb +0 -49
- data/lib/contrast/agent/require_state.rb +0 -61
- data/lib/contrast/agent/socket_client.rb +0 -134
- data/lib/contrast/api/connection_status.rb +0 -49
- data/lib/contrast/api/socket.rb +0 -43
- data/lib/contrast/api/speedracer.rb +0 -188
- data/lib/contrast/api/tcp_socket.rb +0 -29
- data/lib/contrast/api/unix_socket.rb +0 -25
- data/lib/contrast/extension/assess/assess_extension.rb +0 -148
- data/lib/contrast/framework/sinatra/application_helper.rb +0 -51
- data/lib/contrast/framework/view_technologies_descriptor.rb +0 -21
- data/lib/contrast/internal_exception.rb +0 -8
- data/lib/contrast/utils/cache.rb +0 -58
- data/lib/contrast/utils/freeze_util.rb +0 -32
- data/lib/contrast/utils/service_sender_util.rb +0 -167
- data/lib/contrast/utils/sinatra_helper.rb +0 -49
@@ -0,0 +1,40 @@
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'contrast/utils/string_utils'
|
5
|
+
require 'contrast/utils/assess/tracking_util'
|
6
|
+
require 'base64'
|
7
|
+
|
8
|
+
module Contrast
|
9
|
+
module Api
|
10
|
+
module Decorators
|
11
|
+
# Used to decorate the {Contrast::Api::Dtm::UserInput} protobuf model.
|
12
|
+
module UserInput
|
13
|
+
UNKNOWN_USER_INPUT = Contrast::Api::Dtm::UserInput.new.tap do |user_input|
|
14
|
+
user_input.input_type = :UNKNOWN
|
15
|
+
end.cs__freeze
|
16
|
+
|
17
|
+
def self.included klass
|
18
|
+
klass.extend(ClassMethods)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Used to add class methods to UserInput
|
22
|
+
module ClassMethods
|
23
|
+
def build_from_ia_result ia_result
|
24
|
+
return UNKNOWN_USER_INPUT.dup unless ia_result
|
25
|
+
|
26
|
+
user_input = new
|
27
|
+
user_input.input_type = ia_result.input_type.to_i
|
28
|
+
user_input.matcher_ids = ia_result.ids
|
29
|
+
user_input.path = ia_result.path.to_s
|
30
|
+
user_input.key = ia_result.key.to_s
|
31
|
+
user_input.value = ia_result.value.to_s
|
32
|
+
user_input
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
Contrast::Api::Dtm::UserInput.include(Contrast::Api::Decorators::UserInput)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
# rubocop:disable Style/
|
4
|
+
# rubocop:disable Style/MissingRespondToMissing
|
5
5
|
module Contrast
|
6
6
|
# A wrapper build around the Common Agent Configuration project to allow for
|
7
7
|
# access of the values contained in its parent_configuration_spec.yaml
|
@@ -83,4 +83,4 @@ module Contrast
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
86
|
-
# rubocop:enable Style/
|
86
|
+
# rubocop:enable Style/MissingRespondToMissing
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
require 'rubygems/version'
|
5
|
+
require 'contrast/agent/rule_set'
|
6
6
|
|
7
7
|
module Contrast
|
8
8
|
module Components
|
@@ -1,8 +1,7 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
cs__scoped_require 'rubygems/version'
|
4
|
+
require 'rubygems/version'
|
6
5
|
|
7
6
|
module Contrast
|
8
7
|
module Components
|
@@ -16,19 +15,13 @@ module Contrast
|
|
16
15
|
include Contrast::Components::ComponentBase
|
17
16
|
include Contrast::Components::Interface
|
18
17
|
|
19
|
-
access_component :agent, :config
|
18
|
+
access_component :agent, :analysis, :config
|
20
19
|
|
21
20
|
DEFAULT_APP_NAME = 'rails'
|
22
21
|
DEFAULT_APP_PATH = '/'
|
23
22
|
DEFAULT_SERVER_NAME = 'localhost'
|
24
23
|
DEFAULT_SERVER_PATH = '/'
|
25
24
|
|
26
|
-
def ready?
|
27
|
-
@_ready ||= AGENT.enabled? &&
|
28
|
-
Contrast::Utils::ServiceSenderUtil.connection_established? &&
|
29
|
-
Contrast::Utils::ServiceResponseUtil.update_received?
|
30
|
-
end
|
31
|
-
|
32
25
|
def initialize
|
33
26
|
original_pid
|
34
27
|
end
|
@@ -86,7 +79,6 @@ module Contrast
|
|
86
79
|
msg = Contrast::Api::Dtm::ApplicationCreate.new
|
87
80
|
|
88
81
|
msg.group = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.group
|
89
|
-
msg.tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.tags
|
90
82
|
msg.app_version = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.version.to_s
|
91
83
|
msg.code = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.code
|
92
84
|
msg.metadata = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.metadata
|
@@ -99,13 +91,16 @@ module Contrast
|
|
99
91
|
|
100
92
|
def build_agent_startup_message
|
101
93
|
msg = Contrast::Api::Dtm::AgentStartup.new
|
102
|
-
msg.server_name
|
103
|
-
msg.server_path
|
104
|
-
msg.server_type
|
105
|
-
msg.server_version
|
106
|
-
msg.version
|
107
|
-
msg.environment
|
108
|
-
msg.
|
94
|
+
msg.server_name = Contrast::Utils::StringUtils.protobuf_format server_name
|
95
|
+
msg.server_path = Contrast::Utils::StringUtils.protobuf_format server_path
|
96
|
+
msg.server_type = Contrast::Utils::StringUtils.protobuf_format server_type
|
97
|
+
msg.server_version = Contrast::Agent::VERSION
|
98
|
+
msg.version = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.version
|
99
|
+
msg.environment = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.environment
|
100
|
+
msg.server_tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.tags
|
101
|
+
msg.application_tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.tags
|
102
|
+
msg.library_tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.inventory.tags
|
103
|
+
msg.finding_tags = Contrast::Utils::StringUtils.protobuf_format ASSESS.tags
|
109
104
|
msg
|
110
105
|
end
|
111
106
|
|
@@ -1,9 +1,10 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
require 'contrast/utils/boolean_util'
|
5
|
+
require 'contrast/utils/env_configuration_item'
|
6
|
+
require 'contrast/utils/object_share'
|
7
|
+
require 'contrast/configuration'
|
7
8
|
|
8
9
|
module Contrast
|
9
10
|
module Components
|
@@ -33,8 +34,7 @@ module Contrast
|
|
33
34
|
def build log: true
|
34
35
|
@_valid = nil
|
35
36
|
@config = Contrast::Configuration.new
|
36
|
-
|
37
|
-
overrides
|
37
|
+
env_overrides
|
38
38
|
validate(log: log)
|
39
39
|
end
|
40
40
|
alias_method :rebuild, :build
|
@@ -69,17 +69,11 @@ module Contrast
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def session_id
|
72
|
-
@_session_id ||=
|
73
|
-
s = raw.application.session_id || ''
|
74
|
-
s.empty? ? nil : s
|
75
|
-
end
|
72
|
+
@_session_id ||= raw.application.session_id
|
76
73
|
end
|
77
74
|
|
78
75
|
def session_metadata
|
79
|
-
@_session_metadata ||=
|
80
|
-
s = raw.application.session_metadata || ''
|
81
|
-
s.empty? ? nil : s
|
82
|
-
end
|
76
|
+
@_session_metadata ||= raw.application.session_metadata
|
83
77
|
end
|
84
78
|
|
85
79
|
def valid?
|
@@ -98,7 +92,7 @@ module Contrast
|
|
98
92
|
# If the config is invalid, and you want to know about it, then
|
99
93
|
# you have a circular dependency if you try to log it,
|
100
94
|
# hence `log: false`.
|
101
|
-
if session_id && session_metadata
|
95
|
+
if !session_id.empty? && !session_metadata.empty?
|
102
96
|
if log
|
103
97
|
cs__class.log_error(SESSION_VARIABLES)
|
104
98
|
else
|
@@ -110,15 +104,6 @@ module Contrast
|
|
110
104
|
true
|
111
105
|
end
|
112
106
|
|
113
|
-
def defaults
|
114
|
-
raw.agent.service.host ||= Contrast::Configuration::DEFAULT_HOST
|
115
|
-
raw.agent.service.port ||= Contrast::Configuration::DEFAULT_PORT
|
116
|
-
end
|
117
|
-
|
118
|
-
def overrides
|
119
|
-
env_overrides
|
120
|
-
end
|
121
|
-
|
122
107
|
def env_overrides
|
123
108
|
# For env variables resembling CONTRAST__WHATEVER__NESTED_VALUE
|
124
109
|
# override raw.whatever.nested_value
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
4
|
+
require 'monitor'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Components
|
@@ -36,11 +36,11 @@ module Contrast
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def host
|
39
|
-
@_host ||=
|
39
|
+
@_host ||= CONFIG.root.agent.service.host.to_s
|
40
40
|
end
|
41
41
|
|
42
42
|
def port
|
43
|
-
@_port ||=
|
43
|
+
@_port ||= CONFIG.root.agent.service.port.to_i
|
44
44
|
end
|
45
45
|
|
46
46
|
def socket_path
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
require 'delegate'
|
5
|
+
require 'contrast/extension/module'
|
6
|
+
require 'contrast/utils/boolean_util'
|
7
7
|
|
8
8
|
module Contrast
|
9
9
|
# This is the base module for our components classes. It is intended to
|
@@ -120,7 +120,7 @@ module Contrast
|
|
120
120
|
|
121
121
|
@_access_component[sym] = true
|
122
122
|
else
|
123
|
-
raise
|
123
|
+
raise NoMethodError, "#{ self } asked to access undefined component '#{ sym }'."
|
124
124
|
end
|
125
125
|
end
|
126
126
|
end
|
@@ -132,40 +132,40 @@ end
|
|
132
132
|
# directed acyclic graph.
|
133
133
|
|
134
134
|
# Scope shouldn't depend on anything.
|
135
|
-
|
135
|
+
require 'contrast/components/scope'
|
136
136
|
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:scope] = [Contrast::Components::Scope]
|
137
137
|
|
138
138
|
# Config depends on Scope.
|
139
|
-
|
139
|
+
require 'contrast/components/config'
|
140
140
|
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:config] = [Contrast::Components::Config]
|
141
141
|
|
142
142
|
# Settings should not depend on anything but Config.
|
143
|
-
|
143
|
+
require 'contrast/components/settings'
|
144
144
|
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:settings] = [Contrast::Components::Settings]
|
145
145
|
|
146
|
-
|
147
|
-
|
148
|
-
|
146
|
+
require 'contrast/components/assess'
|
147
|
+
require 'contrast/components/protect'
|
148
|
+
require 'contrast/components/inventory'
|
149
149
|
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:analysis] = [Contrast::Components::Protect,
|
150
150
|
Contrast::Components::Assess,
|
151
151
|
Contrast::Components::Inventory]
|
152
152
|
|
153
|
-
|
153
|
+
require 'contrast/components/logger'
|
154
154
|
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:logging] = [Contrast::Components::Logger]
|
155
155
|
|
156
|
-
|
156
|
+
require 'contrast/components/agent'
|
157
157
|
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:agent] = [Contrast::Components::Agent]
|
158
158
|
|
159
|
-
|
159
|
+
require 'contrast/components/contrast_service'
|
160
160
|
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:contrast_service] = [Contrast::Components::ContrastService]
|
161
161
|
|
162
|
-
|
162
|
+
require 'contrast/components/app_context'
|
163
163
|
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:app_context] = [Contrast::Components::AppContext]
|
164
164
|
|
165
|
-
|
165
|
+
require 'contrast/components/heap_dump'
|
166
166
|
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:heap_dump] = [Contrast::Components::HeapDump]
|
167
167
|
|
168
|
-
|
168
|
+
require 'contrast/components/sampling'
|
169
169
|
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:sampling] = [Contrast::Components::Sampling]
|
170
170
|
|
171
171
|
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP.cs__freeze
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
4
|
+
require 'contrast/logger/log'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Components
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
require 'fiber'
|
5
|
+
require 'monitor'
|
6
|
+
require 'contrast/agent/scope'
|
7
7
|
|
8
8
|
# This is the Scope component.
|
9
9
|
#
|
@@ -75,12 +75,6 @@ module Contrast
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
-
def session_id
|
79
|
-
# TODO: RUBY-900 we shouldn't send things w/o having session id,
|
80
|
-
# figure out how this happened and fix it.
|
81
|
-
application_state[:session_id] || Contrast::Utils::ObjectShare::EMPTY_STRING
|
82
|
-
end
|
83
|
-
|
84
78
|
def initialize
|
85
79
|
reset_state
|
86
80
|
end
|
data/lib/contrast/config.rb
CHANGED
@@ -10,24 +10,24 @@ module Contrast
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
require 'contrast/config/base_configuration'
|
14
|
+
require 'contrast/config/default_value'
|
15
15
|
|
16
|
-
|
16
|
+
require 'contrast/config/logger_configuration'
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
require 'contrast/config/heap_dump_configuration'
|
19
|
+
require 'contrast/config/service_configuration'
|
20
|
+
require 'contrast/config/exception_configuration'
|
21
|
+
require 'contrast/config/assess_rules_configuration'
|
22
|
+
require 'contrast/config/protect_rule_configuration'
|
23
|
+
require 'contrast/config/protect_rules_configuration'
|
24
|
+
require 'contrast/config/sampling_configuration'
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
require 'contrast/config/ruby_configuration'
|
27
|
+
require 'contrast/config/agent_configuration'
|
28
|
+
require 'contrast/config/application_configuration'
|
29
|
+
require 'contrast/config/server_configuration'
|
30
|
+
require 'contrast/config/assess_configuration'
|
31
|
+
require 'contrast/config/inventory_configuration'
|
32
|
+
require 'contrast/config/protect_configuration'
|
33
|
+
require 'contrast/config/root_configuration'
|
@@ -1,6 +1,9 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require 'contrast/config/default_value'
|
5
|
+
require 'contrast/utils/object_share'
|
6
|
+
|
4
7
|
module Contrast
|
5
8
|
module Config
|
6
9
|
# Common Configuration settings. Those in this section pertain to the
|
@@ -15,8 +18,8 @@ module Contrast
|
|
15
18
|
tags: EMPTY_VALUE,
|
16
19
|
code: EMPTY_VALUE,
|
17
20
|
metadata: EMPTY_VALUE,
|
18
|
-
session_id:
|
19
|
-
session_metadata:
|
21
|
+
session_id: Contrast::Config::DefaultValue.new(Contrast::Utils::ObjectShare::EMPTY_STRING),
|
22
|
+
session_metadata: Contrast::Config::DefaultValue.new(Contrast::Utils::ObjectShare::EMPTY_STRING)
|
20
23
|
}.cs__freeze
|
21
24
|
|
22
25
|
def initialize hsh
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
require 'forwardable'
|
5
|
+
require 'contrast/utils/object_share'
|
6
6
|
|
7
7
|
module Contrast
|
8
8
|
module Config
|
@@ -1,15 +1,21 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require 'contrast/config/default_value'
|
5
|
+
require 'contrast/config/logger_configuration'
|
6
|
+
|
4
7
|
module Contrast
|
5
8
|
module Config
|
6
9
|
# Common Configuration settings. Those in this section pertain to the
|
7
10
|
# communication between the Agent & the Service.
|
8
11
|
class ServiceConfiguration < BaseConfiguration
|
12
|
+
DEFAULT_HOST = '127.0.0.1'
|
13
|
+
DEFAULT_PORT = '30555'
|
14
|
+
|
9
15
|
KEYS = {
|
10
16
|
enable: EMPTY_VALUE,
|
11
|
-
host:
|
12
|
-
port:
|
17
|
+
host: Contrast::Config::DefaultValue.new(DEFAULT_HOST),
|
18
|
+
port: Contrast::Config::DefaultValue.new(DEFAULT_PORT),
|
13
19
|
socket: EMPTY_VALUE,
|
14
20
|
logger: Contrast::Config::LoggerConfiguration
|
15
21
|
}.cs__freeze
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
require 'yaml'
|
5
|
+
require 'fileutils'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
require 'contrast/config'
|
8
|
+
require 'contrast/utils/object_share'
|
9
|
+
require 'contrast/components/interface'
|
10
10
|
|
11
11
|
module Contrast
|
12
12
|
# This is how we read in the local settings for the Agent, both ENV/ CMD line
|
@@ -24,8 +24,6 @@ module Contrast
|
|
24
24
|
attr_reader :default_name, :root
|
25
25
|
|
26
26
|
DEFAULT_YAML_PATH = 'contrast_security.yaml'
|
27
|
-
DEFAULT_HOST = '127.0.0.1'
|
28
|
-
DEFAULT_PORT = '30555'
|
29
27
|
MILLISECOND_MARKER = '_ms'
|
30
28
|
CONVERSION = {
|
31
29
|
'agent.service.enable' => 'agent.start_bundled_service'
|
@@ -37,9 +35,6 @@ module Contrast
|
|
37
35
|
'/etc/contrast/',
|
38
36
|
'/etc/'
|
39
37
|
].cs__freeze
|
40
|
-
REMOVE_FIELDS = [
|
41
|
-
'contrast'
|
42
|
-
].cs__freeze
|
43
38
|
|
44
39
|
def initialize cli_options = nil, default_name = DEFAULT_YAML_PATH
|
45
40
|
@default_name = default_name
|
@@ -53,7 +48,6 @@ module Contrast
|
|
53
48
|
|
54
49
|
# Some in-flight rewrites to maintain backwards compatibility
|
55
50
|
config_kv = update_prop_keys(config_kv)
|
56
|
-
config_kv = deprecate_fields(config_kv)
|
57
51
|
|
58
52
|
@root = Contrast::Config::RootConfiguration.new(config_kv)
|
59
53
|
end
|
@@ -73,6 +67,13 @@ module Contrast
|
|
73
67
|
root&.cs__respond_to?(method_name) || super
|
74
68
|
end
|
75
69
|
|
70
|
+
# Get a loggable YAML format of this configuration
|
71
|
+
# @return [String] the current active configuration of the Agent,
|
72
|
+
# represented as a YAML string
|
73
|
+
def loggable
|
74
|
+
convert_to_hash.to_yaml
|
75
|
+
end
|
76
|
+
|
76
77
|
protected
|
77
78
|
|
78
79
|
# TODO: RUBY-546 move utility methods to auxiliary classes
|
@@ -80,26 +81,16 @@ module Contrast
|
|
80
81
|
def load_config
|
81
82
|
config = {}
|
82
83
|
configuration_paths.find do |path|
|
83
|
-
|
84
|
-
next unless found
|
84
|
+
next unless File.exist?(path)
|
85
85
|
|
86
|
-
|
87
|
-
|
88
|
-
puts "!!! Contrast - Configuration file at #{ path } is not readable by current user"
|
86
|
+
unless File.readable?(path)
|
87
|
+
log_file_read_error(path)
|
89
88
|
next
|
90
89
|
end
|
91
90
|
config = yaml_to_hash(path) || {}
|
92
91
|
break
|
93
92
|
end
|
94
93
|
|
95
|
-
if config.empty?
|
96
|
-
puts "!!! Contrast - working directory: #{ Dir.pwd }"
|
97
|
-
puts '!!! Contrast - valid configuration file could not be found at any of the search paths'
|
98
|
-
puts 'Valid configuration paths are: '
|
99
|
-
configuration_paths.each do |path|
|
100
|
-
puts(path)
|
101
|
-
end
|
102
|
-
end
|
103
94
|
config
|
104
95
|
end
|
105
96
|
|
@@ -109,9 +100,10 @@ module Contrast
|
|
109
100
|
yaml = IO.read(path)
|
110
101
|
yaml = ERB.new(yaml).result if defined?(ERB)
|
111
102
|
return YAML.safe_load(yaml)
|
103
|
+
rescue Psych::Exception => e
|
104
|
+
log_yaml_parse_error(path, e)
|
112
105
|
rescue RuntimeError => e
|
113
|
-
puts "
|
114
|
-
puts "ERROR: path=#{ path } pwd=#{ Dir.pwd }"
|
106
|
+
puts "WARN: Unable to load configuration. #{ e }; path: #{ path }, pwd: #{ Dir.pwd }"
|
115
107
|
end
|
116
108
|
end
|
117
109
|
|
@@ -122,29 +114,20 @@ module Contrast
|
|
122
114
|
# files to match the new agreed upon standard configuration
|
123
115
|
# names, so that one file works for all agents
|
124
116
|
def update_prop_keys config
|
125
|
-
converted = false
|
126
117
|
CONVERSION.each_pair do |old_method, new_method|
|
127
118
|
# See if the old value was set and needs to be translated
|
128
119
|
deprecated_keys = old_method.split('.')
|
129
|
-
|
130
120
|
old_value = config
|
131
121
|
deprecated_keys.each do |key|
|
132
122
|
old_value = old_value[key]
|
133
123
|
break if old_value.nil?
|
134
124
|
end
|
125
|
+
next if old_value.nil? # have to account for literal false
|
135
126
|
|
136
|
-
|
137
|
-
|
138
|
-
converted = true
|
139
|
-
|
140
|
-
puts "The deprecated property #{ old_method } is being set."
|
141
|
-
puts "Please update your config to use the property #{ new_method } instead."
|
142
|
-
|
127
|
+
log_deprecated_property(old_method, new_method)
|
143
128
|
new_keys = new_method.split('.')
|
144
|
-
|
145
129
|
# We changed the seconds values into ms values. Multiply them accordingly
|
146
130
|
old_value = old_value.to_i * 1000 if new_method.end_with?(MILLISECOND_MARKER)
|
147
|
-
|
148
131
|
new_value = config
|
149
132
|
end_idx = new_keys.length - 1
|
150
133
|
new_keys.each_with_index do |new_key, index|
|
@@ -161,21 +144,6 @@ module Contrast
|
|
161
144
|
config
|
162
145
|
end
|
163
146
|
|
164
|
-
def deprecate_fields hash
|
165
|
-
REMOVE_FIELDS.each do |field|
|
166
|
-
path = field.split('.')
|
167
|
-
active_path = hash
|
168
|
-
path.each_with_index do |delete_path, index|
|
169
|
-
if index == path.length - 1 && active_path
|
170
|
-
active_path.delete(delete_path)
|
171
|
-
elsif active_path
|
172
|
-
active_path = active_path[delete_path]
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
hash
|
177
|
-
end
|
178
|
-
|
179
147
|
# Base paths to check for the contrast configuration file, sorted by
|
180
148
|
# reverse order of precedence (first is most important).
|
181
149
|
def configuration_paths
|
@@ -208,5 +176,78 @@ module Contrast
|
|
208
176
|
end
|
209
177
|
new_hash
|
210
178
|
end
|
179
|
+
|
180
|
+
private
|
181
|
+
|
182
|
+
# We cannot use all access components at this point, unfortunately, as they
|
183
|
+
# may not have been initialized. Instead, we need to access the logger
|
184
|
+
# directly.
|
185
|
+
def logger
|
186
|
+
@_logger ||= (Contrast::Logger::Log.instance.logger if defined?(Contrast::Logger::Log))
|
187
|
+
end
|
188
|
+
|
189
|
+
# When we fail to parse a configuration because it is misformatted, log an
|
190
|
+
# appropriate message based on the Agent Onboarding specification
|
191
|
+
def log_yaml_parse_error path, exception
|
192
|
+
hash = {
|
193
|
+
path: path,
|
194
|
+
pwd: Dir.pwd
|
195
|
+
}
|
196
|
+
if exception.is_a?(Psych::SyntaxError)
|
197
|
+
hash[:context] = exception.context
|
198
|
+
hash[:column] = exception.column
|
199
|
+
hash[:line] = exception.line
|
200
|
+
hash[:offset] = exception.offset
|
201
|
+
hash[:problem] = exception.problem
|
202
|
+
end
|
203
|
+
|
204
|
+
if logger
|
205
|
+
logger.warn('YAML validator found an error', hash)
|
206
|
+
else
|
207
|
+
puts "CONTRAST - WARN: YAML validator found an error. #{ hash.inspect }"
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
def log_file_read_error path
|
212
|
+
if logger
|
213
|
+
logger.warn('Configuration file is not readable by current user', path: path)
|
214
|
+
else
|
215
|
+
puts "CONTRAST - WARN: Configuration file is not readable by current user; path: #{ path }"
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
def log_deprecated_property old_method, new_method
|
220
|
+
if logger
|
221
|
+
logger.warn('Deprecated property in use', old_method: old_method, new_method: new_method)
|
222
|
+
else
|
223
|
+
puts "CONTRAST - WARN: Deprecated property in use; old_method: #{ old_method }, new_method: #{ new_method }"
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
# Convert this entire configuration into a hash, walking down the entries
|
228
|
+
# in the thing to convert and setting them in the given hash. For now, this
|
229
|
+
# logs every possible key, whether set or not. If we want to change that
|
230
|
+
# behavior, we can skip adding keys to the hash if the value is nil, blank,
|
231
|
+
# or Contrast::Config::DefaultValue depending on desired behavior
|
232
|
+
#
|
233
|
+
# @param hash [Hash] the hash to populate
|
234
|
+
# @param convert [Contrast::Config::BaseConfiguration, Object] the level of
|
235
|
+
# configuration from which to convert. Note that at least one top level
|
236
|
+
# Contrast::Config::BaseConfiguration is required for anything to be set
|
237
|
+
# in the hash
|
238
|
+
# @return [Hash, Object] the leaf of each
|
239
|
+
# Contrast::Config::BaseConfiguration will be returned in the N > 0 steps
|
240
|
+
# the Hash will be returned at the end of the 0 level
|
241
|
+
def convert_to_hash convert=root, hash={}
|
242
|
+
case convert
|
243
|
+
when Contrast::Config::BaseConfiguration
|
244
|
+
convert.cs__class::KEYS.each_key do |key|
|
245
|
+
hash[key] = convert_to_hash(convert.send(key), {})
|
246
|
+
end
|
247
|
+
hash
|
248
|
+
else
|
249
|
+
convert
|
250
|
+
end
|
251
|
+
end
|
211
252
|
end
|
212
253
|
end
|