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.
Files changed (306) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +0 -1
  3. data/.gitignore +1 -1
  4. data/.simplecov +1 -1
  5. data/Rakefile +31 -0
  6. data/exe/contrast_service +1 -7
  7. data/ext/build_funchook.rb +0 -2
  8. data/ext/cs__assess_active_record_named/cs__active_record_named.c +8 -7
  9. data/ext/cs__assess_array/cs__assess_array.c +6 -5
  10. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +5 -5
  11. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +4 -9
  12. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.h +0 -1
  13. data/ext/cs__assess_hash/cs__assess_hash.c +18 -17
  14. data/ext/cs__assess_hash/cs__assess_hash.h +2 -1
  15. data/ext/cs__assess_kernel/cs__assess_kernel.c +7 -8
  16. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +18 -16
  17. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +1 -0
  18. data/ext/cs__assess_module/cs__assess_module.c +6 -6
  19. data/ext/cs__assess_regexp/cs__assess_regexp.c +4 -4
  20. data/ext/cs__assess_string/cs__assess_string.c +31 -16
  21. data/ext/cs__assess_string/cs__assess_string.h +6 -1
  22. data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +4 -7
  23. data/ext/cs__assess_yield_track/cs__assess_yield_track.c +3 -7
  24. data/ext/cs__assess_yield_track/cs__assess_yield_track.h +0 -1
  25. data/ext/cs__common/cs__common.c +63 -30
  26. data/ext/cs__common/cs__common.h +19 -21
  27. data/ext/cs__common/extconf.rb +0 -14
  28. data/ext/cs__contrast_patch/cs__contrast_patch.c +27 -25
  29. data/ext/cs__contrast_patch/cs__contrast_patch.h +5 -7
  30. data/ext/cs__protect_kernel/cs__protect_kernel.c +11 -12
  31. data/ext/cs__protect_kernel/cs__protect_kernel.h +2 -2
  32. data/ext/extconf_common.rb +0 -28
  33. data/lib/contrast-agent.rb +1 -1
  34. data/lib/contrast.rb +15 -23
  35. data/lib/contrast/agent.rb +51 -39
  36. data/lib/contrast/agent/assess.rb +12 -12
  37. data/lib/contrast/agent/assess/contrast_event.rb +40 -185
  38. data/lib/contrast/agent/assess/events/event_factory.rb +2 -2
  39. data/lib/contrast/agent/assess/events/source_event.rb +5 -9
  40. data/lib/contrast/agent/assess/finalizers/freeze.rb +15 -0
  41. data/lib/contrast/agent/assess/finalizers/hash.rb +97 -0
  42. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +2 -2
  43. data/lib/contrast/agent/assess/policy/patcher.rb +6 -6
  44. data/lib/contrast/agent/assess/policy/policy.rb +9 -11
  45. data/lib/contrast/agent/assess/policy/policy_node.rb +5 -99
  46. data/lib/contrast/agent/assess/policy/policy_scanner.rb +2 -3
  47. data/lib/contrast/agent/assess/policy/preshift.rb +13 -7
  48. data/lib/contrast/agent/assess/policy/propagation_method.rb +64 -45
  49. data/lib/contrast/agent/assess/policy/propagation_node.rb +6 -2
  50. data/lib/contrast/agent/assess/policy/propagator.rb +18 -18
  51. data/lib/contrast/agent/assess/policy/propagator/append.rb +8 -5
  52. data/lib/contrast/agent/assess/policy/propagator/base.rb +2 -2
  53. data/lib/contrast/agent/assess/policy/propagator/center.rb +9 -5
  54. data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
  55. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +6 -4
  56. data/lib/contrast/agent/assess/policy/propagator/insert.rb +7 -7
  57. data/lib/contrast/agent/assess/policy/propagator/keep.rb +4 -1
  58. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +18 -9
  59. data/lib/contrast/agent/assess/policy/propagator/next.rb +7 -5
  60. data/lib/contrast/agent/assess/policy/propagator/prepend.rb +13 -5
  61. data/lib/contrast/agent/assess/policy/propagator/remove.rb +14 -15
  62. data/lib/contrast/agent/assess/policy/propagator/replace.rb +5 -2
  63. data/lib/contrast/agent/assess/policy/propagator/reverse.rb +7 -5
  64. data/lib/contrast/agent/assess/policy/propagator/select.rb +19 -11
  65. data/lib/contrast/agent/assess/policy/propagator/splat.rb +14 -8
  66. data/lib/contrast/agent/assess/policy/propagator/split.rb +19 -13
  67. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +36 -26
  68. data/lib/contrast/agent/assess/policy/propagator/trim.rb +17 -15
  69. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +5 -5
  70. data/lib/contrast/agent/assess/policy/source_method.rb +90 -73
  71. data/lib/contrast/agent/assess/policy/source_validation/cross_site_validator.rb +1 -1
  72. data/lib/contrast/agent/assess/policy/source_validation/source_validation.rb +1 -1
  73. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +16 -11
  74. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +2 -2
  75. data/lib/contrast/agent/assess/policy/trigger_method.rb +41 -26
  76. data/lib/contrast/agent/assess/policy/trigger_node.rb +30 -17
  77. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -1
  78. data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +2 -2
  79. data/lib/contrast/agent/assess/properties.rb +15 -383
  80. data/lib/contrast/agent/assess/property/evented.rb +78 -0
  81. data/lib/contrast/agent/assess/property/tagged.rb +339 -0
  82. data/lib/contrast/agent/assess/property/updated.rb +136 -0
  83. data/lib/contrast/agent/assess/rule.rb +2 -2
  84. data/lib/contrast/agent/assess/rule/base.rb +3 -4
  85. data/lib/contrast/agent/assess/rule/provider.rb +3 -3
  86. data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +1 -1
  87. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +4 -22
  88. data/lib/contrast/agent/assess/tag.rb +27 -12
  89. data/lib/contrast/agent/assess/tracker.rb +66 -0
  90. data/lib/contrast/agent/at_exit_hook.rb +4 -2
  91. data/lib/contrast/agent/class_reopener.rb +14 -11
  92. data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +1 -1
  93. data/lib/contrast/agent/deadzone/policy/policy.rb +2 -2
  94. data/lib/contrast/agent/disable_reaction.rb +1 -1
  95. data/lib/contrast/agent/exclusion_matcher.rb +3 -3
  96. data/lib/contrast/agent/inventory/policy/datastores.rb +2 -3
  97. data/lib/contrast/agent/inventory/policy/policy.rb +3 -3
  98. data/lib/contrast/agent/inventory/policy/trigger_node.rb +1 -1
  99. data/lib/contrast/agent/middleware.rb +36 -48
  100. data/lib/contrast/agent/patching/policy/after_load_patch.rb +4 -4
  101. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +6 -5
  102. data/lib/contrast/agent/patching/policy/module_policy.rb +1 -1
  103. data/lib/contrast/agent/patching/policy/patch.rb +16 -16
  104. data/lib/contrast/agent/patching/policy/patcher.rb +43 -44
  105. data/lib/contrast/agent/patching/policy/policy.rb +10 -13
  106. data/lib/contrast/agent/patching/policy/policy_node.rb +3 -3
  107. data/lib/contrast/agent/patching/policy/trigger_node.rb +2 -2
  108. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +3 -3
  109. data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +2 -2
  110. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -2
  111. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +3 -3
  112. data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +2 -2
  113. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +3 -3
  114. data/lib/contrast/agent/protect/policy/policy.rb +8 -8
  115. data/lib/contrast/agent/protect/policy/rule_applicator.rb +3 -3
  116. data/lib/contrast/agent/protect/policy/trigger_node.rb +1 -1
  117. data/lib/contrast/agent/protect/rule.rb +18 -18
  118. data/lib/contrast/agent/protect/rule/base.rb +21 -32
  119. data/lib/contrast/agent/protect/rule/base_service.rb +2 -2
  120. data/lib/contrast/agent/protect/rule/cmd_injection.rb +5 -5
  121. data/lib/contrast/agent/protect/rule/deserialization.rb +1 -1
  122. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +3 -8
  123. data/lib/contrast/agent/protect/rule/no_sqli.rb +1 -1
  124. data/lib/contrast/agent/protect/rule/path_traversal.rb +4 -5
  125. data/lib/contrast/agent/protect/rule/sqli.rb +2 -2
  126. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +1 -1
  127. data/lib/contrast/agent/protect/rule/xss.rb +1 -1
  128. data/lib/contrast/agent/protect/rule/xxe.rb +4 -5
  129. data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +2 -2
  130. data/lib/contrast/agent/railtie.rb +1 -1
  131. data/lib/contrast/agent/reaction_processor.rb +5 -5
  132. data/lib/contrast/agent/request.rb +103 -340
  133. data/lib/contrast/agent/request_context.rb +25 -21
  134. data/lib/contrast/agent/request_handler.rb +1 -1
  135. data/lib/contrast/agent/response.rb +25 -26
  136. data/lib/contrast/agent/rewriter.rb +6 -9
  137. data/lib/contrast/agent/scope.rb +1 -1
  138. data/lib/contrast/agent/service_heartbeat.rb +8 -10
  139. data/lib/contrast/agent/static_analysis.rb +4 -4
  140. data/lib/contrast/agent/thread.rb +1 -1
  141. data/lib/contrast/agent/thread_watcher.rb +49 -0
  142. data/lib/contrast/agent/tracepoint_hook.rb +1 -1
  143. data/lib/contrast/agent/version.rb +1 -1
  144. data/lib/contrast/agent/worker_thread.rb +24 -0
  145. data/lib/contrast/api.rb +4 -6
  146. data/lib/contrast/api/communication.rb +20 -0
  147. data/lib/contrast/api/communication/connection_status.rb +41 -0
  148. data/lib/contrast/api/communication/messaging_queue.rb +76 -0
  149. data/lib/contrast/{utils/service_response_util.rb → api/communication/response_processor.rb} +10 -19
  150. data/lib/contrast/api/communication/service_lifecycle.rb +61 -0
  151. data/lib/contrast/api/communication/socket.rb +45 -0
  152. data/lib/contrast/api/communication/socket_client.rb +76 -0
  153. data/lib/contrast/api/communication/speedracer.rb +111 -0
  154. data/lib/contrast/api/communication/tcp_socket.rb +31 -0
  155. data/lib/contrast/api/communication/unix_socket.rb +27 -0
  156. data/lib/contrast/api/decorators.rb +14 -4
  157. data/lib/contrast/api/decorators/address.rb +61 -0
  158. data/lib/contrast/api/decorators/application_settings.rb +10 -5
  159. data/lib/contrast/api/decorators/application_update.rb +7 -17
  160. data/lib/contrast/api/decorators/http_request.rb +140 -0
  161. data/lib/contrast/api/decorators/input_analysis.rb +3 -2
  162. data/lib/contrast/api/decorators/message.rb +76 -0
  163. data/lib/contrast/api/decorators/rasp_rule_sample.rb +29 -0
  164. data/lib/contrast/api/decorators/route_coverage.rb +58 -0
  165. data/lib/contrast/api/decorators/server_features.rb +3 -2
  166. data/lib/contrast/api/decorators/trace_event.rb +100 -0
  167. data/lib/contrast/api/decorators/trace_event_object.rb +58 -0
  168. data/lib/contrast/api/decorators/trace_event_signature.rb +47 -0
  169. data/lib/contrast/api/decorators/trace_taint_range.rb +52 -0
  170. data/lib/contrast/api/decorators/trace_taint_range_tags.rb +109 -0
  171. data/lib/contrast/api/decorators/user_input.rb +40 -0
  172. data/lib/contrast/common_agent_configuration.rb +2 -2
  173. data/lib/contrast/components/agent.rb +2 -2
  174. data/lib/contrast/components/app_context.rb +12 -17
  175. data/lib/contrast/components/config.rb +8 -23
  176. data/lib/contrast/components/contrast_service.rb +3 -3
  177. data/lib/contrast/components/interface.rb +16 -16
  178. data/lib/contrast/components/logger.rb +1 -1
  179. data/lib/contrast/components/scope.rb +3 -3
  180. data/lib/contrast/components/settings.rb +0 -6
  181. data/lib/contrast/config.rb +18 -18
  182. data/lib/contrast/config/application_configuration.rb +5 -2
  183. data/lib/contrast/config/base_configuration.rb +2 -2
  184. data/lib/contrast/config/protect_rule_configuration.rb +1 -1
  185. data/lib/contrast/config/service_configuration.rb +8 -2
  186. data/lib/contrast/configuration.rb +93 -52
  187. data/lib/contrast/extension/assess.rb +21 -23
  188. data/lib/contrast/extension/assess/array.rb +12 -9
  189. data/lib/contrast/extension/assess/erb.rb +6 -3
  190. data/lib/contrast/extension/assess/eval_trigger.rb +3 -3
  191. data/lib/contrast/extension/assess/exec_trigger.rb +1 -1
  192. data/lib/contrast/extension/assess/fiber.rb +12 -12
  193. data/lib/contrast/extension/assess/hash.rb +5 -4
  194. data/lib/contrast/extension/assess/kernel.rb +19 -11
  195. data/lib/contrast/extension/assess/marshal.rb +63 -0
  196. data/lib/contrast/extension/assess/regexp.rb +8 -7
  197. data/lib/contrast/extension/assess/string.rb +13 -15
  198. data/lib/contrast/extension/inventory.rb +4 -5
  199. data/lib/contrast/extension/kernel.rb +1 -1
  200. data/lib/contrast/extension/module.rb +1 -1
  201. data/lib/contrast/extension/protect.rb +3 -3
  202. data/lib/contrast/extension/protect/kernel.rb +2 -2
  203. data/lib/contrast/extension/protect/psych.rb +2 -2
  204. data/lib/contrast/framework/base_support.rb +0 -23
  205. data/lib/contrast/framework/manager.rb +7 -17
  206. data/lib/contrast/framework/rack/patch/session_cookie.rb +13 -19
  207. data/lib/contrast/framework/rack/patch/support.rb +1 -1
  208. data/lib/contrast/framework/rack/support.rb +2 -2
  209. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +1 -3
  210. data/lib/contrast/framework/rails/patch/assess_configuration.rb +6 -13
  211. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +1 -1
  212. data/lib/contrast/framework/rails/patch/support.rb +3 -3
  213. data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +2 -2
  214. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +2 -2
  215. data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +2 -2
  216. data/lib/contrast/framework/rails/support.rb +58 -37
  217. data/lib/contrast/framework/sinatra/patch/base.rb +2 -2
  218. data/lib/contrast/framework/sinatra/patch/support.rb +1 -1
  219. data/lib/contrast/framework/sinatra/support.rb +13 -24
  220. data/lib/contrast/funchook/funchook.rb +45 -0
  221. data/lib/contrast/logger/application.rb +13 -5
  222. data/lib/contrast/logger/format.rb +64 -0
  223. data/lib/contrast/logger/log.rb +17 -9
  224. data/lib/contrast/logger/request.rb +30 -0
  225. data/lib/contrast/tasks/config.rb +1 -1
  226. data/lib/contrast/tasks/service.rb +2 -2
  227. data/lib/contrast/utils/assess/sampling_util.rb +2 -2
  228. data/lib/contrast/utils/assess/tracking_util.rb +89 -19
  229. data/lib/contrast/utils/boolean_util.rb +1 -1
  230. data/lib/contrast/utils/class_util.rb +2 -2
  231. data/lib/contrast/utils/duck_utils.rb +0 -10
  232. data/lib/contrast/utils/env_configuration_item.rb +2 -1
  233. data/lib/contrast/utils/gemfile_reader.rb +5 -5
  234. data/lib/contrast/utils/hash_digest.rb +13 -3
  235. data/lib/contrast/utils/heap_dump_util.rb +2 -2
  236. data/lib/contrast/utils/invalid_configuration_util.rb +21 -35
  237. data/lib/contrast/utils/inventory_util.rb +6 -11
  238. data/lib/contrast/utils/io_util.rb +1 -1
  239. data/lib/contrast/utils/object_share.rb +0 -1
  240. data/lib/contrast/utils/os.rb +16 -4
  241. data/lib/contrast/utils/ruby_ast_rewriter.rb +1 -1
  242. data/lib/contrast/utils/sha256_builder.rb +2 -2
  243. data/lib/contrast/utils/stack_trace_utils.rb +2 -3
  244. data/lib/contrast/utils/string_utils.rb +11 -6
  245. data/lib/contrast/utils/tag_util.rb +1 -1
  246. data/lib/contrast/utils/thread_tracker.rb +1 -14
  247. data/lib/contrast/utils/timer.rb +1 -17
  248. data/resources/assess/policy.json +0 -10
  249. data/resources/deadzone/policy.json +5 -0
  250. data/ruby-agent.gemspec +24 -23
  251. data/service_executables/VERSION +1 -1
  252. data/service_executables/linux/contrast-service +0 -0
  253. data/service_executables/mac/contrast-service +0 -0
  254. metadata +92 -92
  255. data/funchook/Makefile +0 -29
  256. data/funchook/autom4te.cache/output.0 +0 -4964
  257. data/funchook/autom4te.cache/requests +0 -77
  258. data/funchook/autom4te.cache/traces.0 +0 -361
  259. data/funchook/config.log +0 -651
  260. data/funchook/config.status +0 -1015
  261. data/funchook/configure +0 -4964
  262. data/funchook/src/Makefile +0 -70
  263. data/funchook/src/config.h +0 -101
  264. data/funchook/src/config.h.in +0 -100
  265. data/funchook/src/decoder.o +0 -0
  266. data/funchook/src/distorm.o +0 -0
  267. data/funchook/src/funchook.o +0 -0
  268. data/funchook/src/funchook_io.o +0 -0
  269. data/funchook/src/funchook_syscall.o +0 -0
  270. data/funchook/src/funchook_unix.o +0 -0
  271. data/funchook/src/funchook_x86.o +0 -0
  272. data/funchook/src/instructions.o +0 -0
  273. data/funchook/src/insts.o +0 -0
  274. data/funchook/src/libfunchook.dylib +0 -0
  275. data/funchook/src/mnemonics.o +0 -0
  276. data/funchook/src/operands.o +0 -0
  277. data/funchook/src/os_func.o +0 -0
  278. data/funchook/src/os_func_unix.o +0 -0
  279. data/funchook/src/prefix.o +0 -0
  280. data/funchook/src/printf_base.o +0 -0
  281. data/funchook/src/textdefs.o +0 -0
  282. data/funchook/src/wstring.o +0 -0
  283. data/funchook/test/Makefile +0 -43
  284. data/funchook/test/funchook_test +0 -0
  285. data/funchook/test/libfunchook_test.so +0 -0
  286. data/funchook/test/libfunchook_test.so.dSYM/Contents/Info.plist +0 -20
  287. data/funchook/test/libfunchook_test.so.dSYM/Contents/Resources/DWARF/libfunchook_test.so +0 -0
  288. data/funchook/test/test_main.o +0 -0
  289. data/funchook/test/x86_64_test.o +0 -0
  290. data/lib/contrast/agent/assess/adjusted_span.rb +0 -27
  291. data/lib/contrast/agent/assess/insulator.rb +0 -49
  292. data/lib/contrast/agent/require_state.rb +0 -61
  293. data/lib/contrast/agent/socket_client.rb +0 -134
  294. data/lib/contrast/api/connection_status.rb +0 -49
  295. data/lib/contrast/api/socket.rb +0 -43
  296. data/lib/contrast/api/speedracer.rb +0 -188
  297. data/lib/contrast/api/tcp_socket.rb +0 -29
  298. data/lib/contrast/api/unix_socket.rb +0 -25
  299. data/lib/contrast/extension/assess/assess_extension.rb +0 -148
  300. data/lib/contrast/framework/sinatra/application_helper.rb +0 -51
  301. data/lib/contrast/framework/view_technologies_descriptor.rb +0 -21
  302. data/lib/contrast/internal_exception.rb +0 -8
  303. data/lib/contrast/utils/cache.rb +0 -58
  304. data/lib/contrast/utils/freeze_util.rb +0 -32
  305. data/lib/contrast/utils/service_sender_util.rb +0 -167
  306. 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/MethodMissingSuper, Style/MissingRespondToMissing
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/MethodMissingSuper, Style/MissingRespondToMissing
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
- cs__scoped_require 'rubygems/version'
5
- cs__scoped_require 'contrast/agent/rule_set'
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
- cs__scoped_require 'contrast/utils/sinatra_helper'
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 = Contrast::Utils::StringUtils.protobuf_format server_name
103
- msg.server_path = Contrast::Utils::StringUtils.protobuf_format server_path
104
- msg.server_type = Contrast::Utils::StringUtils.protobuf_format server_type
105
- msg.server_version = Contrast::Agent::VERSION
106
- msg.version = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.version
107
- msg.environment = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.environment
108
- msg.tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.tags
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
- cs__scoped_require 'contrast/utils/boolean_util'
5
- cs__scoped_require 'contrast/utils/env_configuration_item'
6
- cs__scoped_require 'contrast/configuration'
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
- defaults
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 ||= begin
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 ||= begin
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
- cs__scoped_require 'monitor'
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 ||= (CONFIG.root.agent.service.host || Contrast::Configuration::DEFAULT_HOST).to_s
39
+ @_host ||= CONFIG.root.agent.service.host.to_s
40
40
  end
41
41
 
42
42
  def port
43
- @_port ||= (CONFIG.root.agent.service.port || DEFAULT_PORT).to_i
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
- cs__scoped_require 'delegate'
5
- cs__scoped_require 'contrast/extension/module'
6
- cs__scoped_require 'contrast/utils/boolean_util'
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 NotImplementedError, "#{ self } asked to access undefined component '#{ sym }'."
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
- cs__scoped_require 'contrast/components/scope'
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
- cs__scoped_require 'contrast/components/config'
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
- cs__scoped_require 'contrast/components/settings'
143
+ require 'contrast/components/settings'
144
144
  Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:settings] = [Contrast::Components::Settings]
145
145
 
146
- cs__scoped_require 'contrast/components/assess'
147
- cs__scoped_require 'contrast/components/protect'
148
- cs__scoped_require 'contrast/components/inventory'
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
- cs__scoped_require 'contrast/components/logger'
153
+ require 'contrast/components/logger'
154
154
  Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:logging] = [Contrast::Components::Logger]
155
155
 
156
- cs__scoped_require 'contrast/components/agent'
156
+ require 'contrast/components/agent'
157
157
  Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:agent] = [Contrast::Components::Agent]
158
158
 
159
- cs__scoped_require 'contrast/components/contrast_service'
159
+ require 'contrast/components/contrast_service'
160
160
  Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:contrast_service] = [Contrast::Components::ContrastService]
161
161
 
162
- cs__scoped_require 'contrast/components/app_context'
162
+ require 'contrast/components/app_context'
163
163
  Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:app_context] = [Contrast::Components::AppContext]
164
164
 
165
- cs__scoped_require 'contrast/components/heap_dump'
165
+ require 'contrast/components/heap_dump'
166
166
  Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:heap_dump] = [Contrast::Components::HeapDump]
167
167
 
168
- cs__scoped_require 'contrast/components/sampling'
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
- cs__scoped_require 'contrast/logger/log'
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
- cs__scoped_require 'fiber'
5
- cs__scoped_require 'monitor'
6
- cs__scoped_require 'contrast/agent/scope'
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
@@ -10,24 +10,24 @@ module Contrast
10
10
  end
11
11
  end
12
12
 
13
- cs__scoped_require 'contrast/config/base_configuration'
14
- cs__scoped_require 'contrast/config/default_value'
13
+ require 'contrast/config/base_configuration'
14
+ require 'contrast/config/default_value'
15
15
 
16
- cs__scoped_require 'contrast/config/logger_configuration'
16
+ require 'contrast/config/logger_configuration'
17
17
 
18
- cs__scoped_require 'contrast/config/heap_dump_configuration'
19
- cs__scoped_require 'contrast/config/service_configuration'
20
- cs__scoped_require 'contrast/config/exception_configuration'
21
- cs__scoped_require 'contrast/config/assess_rules_configuration'
22
- cs__scoped_require 'contrast/config/protect_rule_configuration'
23
- cs__scoped_require 'contrast/config/protect_rules_configuration'
24
- cs__scoped_require 'contrast/config/sampling_configuration'
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
- cs__scoped_require 'contrast/config/ruby_configuration'
27
- cs__scoped_require 'contrast/config/agent_configuration'
28
- cs__scoped_require 'contrast/config/application_configuration'
29
- cs__scoped_require 'contrast/config/server_configuration'
30
- cs__scoped_require 'contrast/config/assess_configuration'
31
- cs__scoped_require 'contrast/config/inventory_configuration'
32
- cs__scoped_require 'contrast/config/protect_configuration'
33
- cs__scoped_require 'contrast/config/root_configuration'
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: EMPTY_VALUE,
19
- session_metadata: EMPTY_VALUE
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
- cs__scoped_require 'forwardable'
5
- cs__scoped_require 'contrast/utils/object_share'
4
+ require 'forwardable'
5
+ require 'contrast/utils/object_share'
6
6
 
7
7
  module Contrast
8
8
  module Config
@@ -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
- cs__scoped_require 'set'
4
+ require 'set'
5
5
 
6
6
  module Contrast
7
7
  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: EMPTY_VALUE,
12
- port: EMPTY_VALUE,
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
- cs__scoped_require 'yaml'
5
- cs__scoped_require 'fileutils'
4
+ require 'yaml'
5
+ require 'fileutils'
6
6
 
7
- cs__scoped_require 'contrast/config'
8
- cs__scoped_require 'contrast/utils/object_share'
9
- cs__scoped_require 'contrast/components/interface'
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
- found = File.exist?(path)
84
- next unless found
84
+ next unless File.exist?(path)
85
85
 
86
- readable = File.readable?(path)
87
- unless readable
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 "ERROR: unable to load configuration from path due to #{ e }"
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
- next if old_value.nil?
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