fluentd-hubspot 0.14.14.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.github/ISSUE_TEMPLATE.md +6 -0
- data/.gitignore +28 -0
- data/.travis.yml +51 -0
- data/AUTHORS +2 -0
- data/CONTRIBUTING.md +42 -0
- data/COPYING +14 -0
- data/ChangeLog +593 -0
- data/Gemfile +9 -0
- data/README.md +76 -0
- data/Rakefile +74 -0
- data/Vagrantfile +17 -0
- data/appveyor.yml +43 -0
- data/bin/fluent-binlog-reader +7 -0
- data/bin/fluent-debug +5 -0
- data/bin/fluent-plugin-config-format +5 -0
- data/bin/fluent-plugin-generate +5 -0
- data/code-of-conduct.md +3 -0
- data/example/copy_roundrobin.conf +39 -0
- data/example/filter_stdout.conf +22 -0
- data/example/in_dummy_blocks.conf +17 -0
- data/example/in_dummy_with_compression.conf +23 -0
- data/example/in_forward.conf +14 -0
- data/example/in_forward_client.conf +37 -0
- data/example/in_forward_shared_key.conf +15 -0
- data/example/in_forward_tls.conf +14 -0
- data/example/in_forward_users.conf +24 -0
- data/example/in_forward_workers.conf +21 -0
- data/example/in_http.conf +14 -0
- data/example/in_out_forward.conf +17 -0
- data/example/in_syslog.conf +15 -0
- data/example/in_tail.conf +14 -0
- data/example/in_tcp.conf +13 -0
- data/example/in_udp.conf +13 -0
- data/example/logevents.conf +25 -0
- data/example/multi_filters.conf +61 -0
- data/example/out_copy.conf +20 -0
- data/example/out_exec_filter.conf +42 -0
- data/example/out_file.conf +13 -0
- data/example/out_forward.conf +35 -0
- data/example/out_forward_buf_file.conf +23 -0
- data/example/out_forward_client.conf +109 -0
- data/example/out_forward_heartbeat_none.conf +16 -0
- data/example/out_forward_shared_key.conf +36 -0
- data/example/out_forward_tls.conf +18 -0
- data/example/out_forward_users.conf +65 -0
- data/example/out_null.conf +36 -0
- data/example/secondary_file.conf +41 -0
- data/example/suppress_config_dump.conf +7 -0
- data/example/v0_12_filter.conf +78 -0
- data/example/v1_literal_example.conf +36 -0
- data/fluent.conf +139 -0
- data/fluentd.gemspec +51 -0
- data/lib/fluent/agent.rb +163 -0
- data/lib/fluent/clock.rb +62 -0
- data/lib/fluent/command/binlog_reader.rb +234 -0
- data/lib/fluent/command/bundler_injection.rb +45 -0
- data/lib/fluent/command/cat.rb +330 -0
- data/lib/fluent/command/debug.rb +102 -0
- data/lib/fluent/command/fluentd.rb +301 -0
- data/lib/fluent/command/plugin_config_formatter.rb +258 -0
- data/lib/fluent/command/plugin_generator.rb +301 -0
- data/lib/fluent/compat/call_super_mixin.rb +67 -0
- data/lib/fluent/compat/detach_process_mixin.rb +25 -0
- data/lib/fluent/compat/exec_util.rb +129 -0
- data/lib/fluent/compat/file_util.rb +54 -0
- data/lib/fluent/compat/filter.rb +68 -0
- data/lib/fluent/compat/formatter.rb +111 -0
- data/lib/fluent/compat/formatter_utils.rb +85 -0
- data/lib/fluent/compat/handle_tag_and_time_mixin.rb +62 -0
- data/lib/fluent/compat/handle_tag_name_mixin.rb +53 -0
- data/lib/fluent/compat/input.rb +59 -0
- data/lib/fluent/compat/output.rb +728 -0
- data/lib/fluent/compat/output_chain.rb +60 -0
- data/lib/fluent/compat/parser.rb +310 -0
- data/lib/fluent/compat/parser_utils.rb +40 -0
- data/lib/fluent/compat/propagate_default.rb +62 -0
- data/lib/fluent/compat/record_filter_mixin.rb +34 -0
- data/lib/fluent/compat/set_tag_key_mixin.rb +50 -0
- data/lib/fluent/compat/set_time_key_mixin.rb +69 -0
- data/lib/fluent/compat/socket_util.rb +165 -0
- data/lib/fluent/compat/string_util.rb +34 -0
- data/lib/fluent/compat/structured_format_mixin.rb +26 -0
- data/lib/fluent/compat/type_converter.rb +90 -0
- data/lib/fluent/config.rb +56 -0
- data/lib/fluent/config/basic_parser.rb +123 -0
- data/lib/fluent/config/configure_proxy.rb +418 -0
- data/lib/fluent/config/dsl.rb +149 -0
- data/lib/fluent/config/element.rb +218 -0
- data/lib/fluent/config/error.rb +26 -0
- data/lib/fluent/config/literal_parser.rb +251 -0
- data/lib/fluent/config/parser.rb +107 -0
- data/lib/fluent/config/section.rb +223 -0
- data/lib/fluent/config/types.rb +136 -0
- data/lib/fluent/config/v1_parser.rb +190 -0
- data/lib/fluent/configurable.rb +200 -0
- data/lib/fluent/daemon.rb +15 -0
- data/lib/fluent/engine.rb +266 -0
- data/lib/fluent/env.rb +28 -0
- data/lib/fluent/error.rb +30 -0
- data/lib/fluent/event.rb +334 -0
- data/lib/fluent/event_router.rb +269 -0
- data/lib/fluent/filter.rb +21 -0
- data/lib/fluent/formatter.rb +23 -0
- data/lib/fluent/input.rb +21 -0
- data/lib/fluent/label.rb +46 -0
- data/lib/fluent/load.rb +35 -0
- data/lib/fluent/log.rb +546 -0
- data/lib/fluent/match.rb +178 -0
- data/lib/fluent/mixin.rb +31 -0
- data/lib/fluent/msgpack_factory.rb +62 -0
- data/lib/fluent/output.rb +29 -0
- data/lib/fluent/output_chain.rb +23 -0
- data/lib/fluent/parser.rb +23 -0
- data/lib/fluent/plugin.rb +183 -0
- data/lib/fluent/plugin/bare_output.rb +63 -0
- data/lib/fluent/plugin/base.rb +165 -0
- data/lib/fluent/plugin/buf_file.rb +184 -0
- data/lib/fluent/plugin/buf_memory.rb +34 -0
- data/lib/fluent/plugin/buffer.rb +617 -0
- data/lib/fluent/plugin/buffer/chunk.rb +221 -0
- data/lib/fluent/plugin/buffer/file_chunk.rb +364 -0
- data/lib/fluent/plugin/buffer/memory_chunk.rb +90 -0
- data/lib/fluent/plugin/compressable.rb +92 -0
- data/lib/fluent/plugin/exec_util.rb +22 -0
- data/lib/fluent/plugin/file_util.rb +22 -0
- data/lib/fluent/plugin/file_wrapper.rb +120 -0
- data/lib/fluent/plugin/filter.rb +93 -0
- data/lib/fluent/plugin/filter_grep.rb +75 -0
- data/lib/fluent/plugin/filter_parser.rb +119 -0
- data/lib/fluent/plugin/filter_record_transformer.rb +322 -0
- data/lib/fluent/plugin/filter_stdout.rb +53 -0
- data/lib/fluent/plugin/formatter.rb +50 -0
- data/lib/fluent/plugin/formatter_csv.rb +52 -0
- data/lib/fluent/plugin/formatter_hash.rb +33 -0
- data/lib/fluent/plugin/formatter_json.rb +55 -0
- data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
- data/lib/fluent/plugin/formatter_msgpack.rb +33 -0
- data/lib/fluent/plugin/formatter_out_file.rb +51 -0
- data/lib/fluent/plugin/formatter_single_value.rb +34 -0
- data/lib/fluent/plugin/formatter_stdout.rb +75 -0
- data/lib/fluent/plugin/formatter_tsv.rb +34 -0
- data/lib/fluent/plugin/in_debug_agent.rb +64 -0
- data/lib/fluent/plugin/in_dummy.rb +139 -0
- data/lib/fluent/plugin/in_exec.rb +108 -0
- data/lib/fluent/plugin/in_forward.rb +455 -0
- data/lib/fluent/plugin/in_gc_stat.rb +56 -0
- data/lib/fluent/plugin/in_http.rb +433 -0
- data/lib/fluent/plugin/in_monitor_agent.rb +448 -0
- data/lib/fluent/plugin/in_object_space.rb +93 -0
- data/lib/fluent/plugin/in_syslog.rb +209 -0
- data/lib/fluent/plugin/in_tail.rb +905 -0
- data/lib/fluent/plugin/in_tcp.rb +85 -0
- data/lib/fluent/plugin/in_udp.rb +81 -0
- data/lib/fluent/plugin/in_unix.rb +201 -0
- data/lib/fluent/plugin/input.rb +37 -0
- data/lib/fluent/plugin/multi_output.rb +157 -0
- data/lib/fluent/plugin/out_copy.rb +46 -0
- data/lib/fluent/plugin/out_exec.rb +105 -0
- data/lib/fluent/plugin/out_exec_filter.rb +317 -0
- data/lib/fluent/plugin/out_file.rb +302 -0
- data/lib/fluent/plugin/out_forward.rb +912 -0
- data/lib/fluent/plugin/out_null.rb +74 -0
- data/lib/fluent/plugin/out_relabel.rb +32 -0
- data/lib/fluent/plugin/out_roundrobin.rb +84 -0
- data/lib/fluent/plugin/out_secondary_file.rb +133 -0
- data/lib/fluent/plugin/out_stdout.rb +75 -0
- data/lib/fluent/plugin/out_stream.rb +130 -0
- data/lib/fluent/plugin/output.rb +1291 -0
- data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
- data/lib/fluent/plugin/parser.rb +191 -0
- data/lib/fluent/plugin/parser_apache.rb +28 -0
- data/lib/fluent/plugin/parser_apache2.rb +84 -0
- data/lib/fluent/plugin/parser_apache_error.rb +26 -0
- data/lib/fluent/plugin/parser_csv.rb +39 -0
- data/lib/fluent/plugin/parser_json.rb +81 -0
- data/lib/fluent/plugin/parser_ltsv.rb +42 -0
- data/lib/fluent/plugin/parser_msgpack.rb +50 -0
- data/lib/fluent/plugin/parser_multiline.rb +105 -0
- data/lib/fluent/plugin/parser_nginx.rb +28 -0
- data/lib/fluent/plugin/parser_none.rb +36 -0
- data/lib/fluent/plugin/parser_regexp.rb +63 -0
- data/lib/fluent/plugin/parser_syslog.rb +121 -0
- data/lib/fluent/plugin/parser_tsv.rb +42 -0
- data/lib/fluent/plugin/socket_util.rb +22 -0
- data/lib/fluent/plugin/storage.rb +84 -0
- data/lib/fluent/plugin/storage_local.rb +159 -0
- data/lib/fluent/plugin/string_util.rb +22 -0
- data/lib/fluent/plugin_helper.rb +70 -0
- data/lib/fluent/plugin_helper/cert_option.rb +159 -0
- data/lib/fluent/plugin_helper/child_process.rb +364 -0
- data/lib/fluent/plugin_helper/compat_parameters.rb +331 -0
- data/lib/fluent/plugin_helper/event_emitter.rb +93 -0
- data/lib/fluent/plugin_helper/event_loop.rb +161 -0
- data/lib/fluent/plugin_helper/extract.rb +104 -0
- data/lib/fluent/plugin_helper/formatter.rb +147 -0
- data/lib/fluent/plugin_helper/inject.rb +151 -0
- data/lib/fluent/plugin_helper/parser.rb +147 -0
- data/lib/fluent/plugin_helper/retry_state.rb +201 -0
- data/lib/fluent/plugin_helper/server.rb +738 -0
- data/lib/fluent/plugin_helper/socket.rb +241 -0
- data/lib/fluent/plugin_helper/socket_option.rb +69 -0
- data/lib/fluent/plugin_helper/storage.rb +349 -0
- data/lib/fluent/plugin_helper/thread.rb +179 -0
- data/lib/fluent/plugin_helper/timer.rb +91 -0
- data/lib/fluent/plugin_id.rb +80 -0
- data/lib/fluent/process.rb +22 -0
- data/lib/fluent/registry.rb +116 -0
- data/lib/fluent/root_agent.rb +323 -0
- data/lib/fluent/rpc.rb +94 -0
- data/lib/fluent/supervisor.rb +741 -0
- data/lib/fluent/system_config.rb +159 -0
- data/lib/fluent/test.rb +58 -0
- data/lib/fluent/test/base.rb +78 -0
- data/lib/fluent/test/driver/base.rb +224 -0
- data/lib/fluent/test/driver/base_owned.rb +70 -0
- data/lib/fluent/test/driver/base_owner.rb +135 -0
- data/lib/fluent/test/driver/event_feeder.rb +98 -0
- data/lib/fluent/test/driver/filter.rb +57 -0
- data/lib/fluent/test/driver/formatter.rb +30 -0
- data/lib/fluent/test/driver/input.rb +31 -0
- data/lib/fluent/test/driver/multi_output.rb +53 -0
- data/lib/fluent/test/driver/output.rb +102 -0
- data/lib/fluent/test/driver/parser.rb +30 -0
- data/lib/fluent/test/driver/test_event_router.rb +45 -0
- data/lib/fluent/test/filter_test.rb +77 -0
- data/lib/fluent/test/formatter_test.rb +65 -0
- data/lib/fluent/test/helpers.rb +134 -0
- data/lib/fluent/test/input_test.rb +174 -0
- data/lib/fluent/test/log.rb +79 -0
- data/lib/fluent/test/output_test.rb +156 -0
- data/lib/fluent/test/parser_test.rb +70 -0
- data/lib/fluent/test/startup_shutdown.rb +46 -0
- data/lib/fluent/time.rb +412 -0
- data/lib/fluent/timezone.rb +133 -0
- data/lib/fluent/unique_id.rb +39 -0
- data/lib/fluent/version.rb +21 -0
- data/lib/fluent/winsvc.rb +71 -0
- data/templates/new_gem/Gemfile +3 -0
- data/templates/new_gem/README.md.erb +43 -0
- data/templates/new_gem/Rakefile +13 -0
- data/templates/new_gem/fluent-plugin.gemspec.erb +27 -0
- data/templates/new_gem/lib/fluent/plugin/filter.rb.erb +14 -0
- data/templates/new_gem/lib/fluent/plugin/formatter.rb.erb +14 -0
- data/templates/new_gem/lib/fluent/plugin/input.rb.erb +11 -0
- data/templates/new_gem/lib/fluent/plugin/output.rb.erb +11 -0
- data/templates/new_gem/lib/fluent/plugin/parser.rb.erb +15 -0
- data/templates/new_gem/test/helper.rb.erb +8 -0
- data/templates/new_gem/test/plugin/test_filter.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_formatter.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_input.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_output.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_parser.rb.erb +18 -0
- data/templates/plugin_config_formatter/param.md-compact.erb +25 -0
- data/templates/plugin_config_formatter/param.md.erb +34 -0
- data/templates/plugin_config_formatter/section.md.erb +12 -0
- data/test/command/test_binlog_reader.rb +346 -0
- data/test/command/test_fluentd.rb +618 -0
- data/test/command/test_plugin_config_formatter.rb +275 -0
- data/test/command/test_plugin_generator.rb +66 -0
- data/test/compat/test_calls_super.rb +166 -0
- data/test/compat/test_parser.rb +92 -0
- data/test/config/assertions.rb +42 -0
- data/test/config/test_config_parser.rb +513 -0
- data/test/config/test_configurable.rb +1587 -0
- data/test/config/test_configure_proxy.rb +566 -0
- data/test/config/test_dsl.rb +415 -0
- data/test/config/test_element.rb +403 -0
- data/test/config/test_literal_parser.rb +297 -0
- data/test/config/test_section.rb +184 -0
- data/test/config/test_system_config.rb +168 -0
- data/test/config/test_types.rb +191 -0
- data/test/helper.rb +153 -0
- data/test/plugin/data/2010/01/20100102-030405.log +0 -0
- data/test/plugin/data/2010/01/20100102-030406.log +0 -0
- data/test/plugin/data/2010/01/20100102.log +0 -0
- data/test/plugin/data/log/bar +0 -0
- data/test/plugin/data/log/foo/bar.log +0 -0
- data/test/plugin/data/log/foo/bar2 +0 -0
- data/test/plugin/data/log/test.log +0 -0
- data/test/plugin/test_bare_output.rb +118 -0
- data/test/plugin/test_base.rb +115 -0
- data/test/plugin/test_buf_file.rb +843 -0
- data/test/plugin/test_buf_memory.rb +42 -0
- data/test/plugin/test_buffer.rb +1220 -0
- data/test/plugin/test_buffer_chunk.rb +198 -0
- data/test/plugin/test_buffer_file_chunk.rb +844 -0
- data/test/plugin/test_buffer_memory_chunk.rb +338 -0
- data/test/plugin/test_compressable.rb +84 -0
- data/test/plugin/test_file_util.rb +96 -0
- data/test/plugin/test_filter.rb +357 -0
- data/test/plugin/test_filter_grep.rb +119 -0
- data/test/plugin/test_filter_parser.rb +700 -0
- data/test/plugin/test_filter_record_transformer.rb +556 -0
- data/test/plugin/test_filter_stdout.rb +202 -0
- data/test/plugin/test_formatter_csv.rb +111 -0
- data/test/plugin/test_formatter_hash.rb +35 -0
- data/test/plugin/test_formatter_json.rb +51 -0
- data/test/plugin/test_formatter_ltsv.rb +59 -0
- data/test/plugin/test_formatter_msgpack.rb +28 -0
- data/test/plugin/test_formatter_out_file.rb +95 -0
- data/test/plugin/test_formatter_single_value.rb +38 -0
- data/test/plugin/test_in_debug_agent.rb +28 -0
- data/test/plugin/test_in_dummy.rb +192 -0
- data/test/plugin/test_in_exec.rb +245 -0
- data/test/plugin/test_in_forward.rb +1120 -0
- data/test/plugin/test_in_gc_stat.rb +39 -0
- data/test/plugin/test_in_http.rb +588 -0
- data/test/plugin/test_in_monitor_agent.rb +516 -0
- data/test/plugin/test_in_object_space.rb +64 -0
- data/test/plugin/test_in_syslog.rb +271 -0
- data/test/plugin/test_in_tail.rb +1216 -0
- data/test/plugin/test_in_tcp.rb +118 -0
- data/test/plugin/test_in_udp.rb +152 -0
- data/test/plugin/test_in_unix.rb +126 -0
- data/test/plugin/test_input.rb +126 -0
- data/test/plugin/test_multi_output.rb +180 -0
- data/test/plugin/test_out_copy.rb +160 -0
- data/test/plugin/test_out_exec.rb +310 -0
- data/test/plugin/test_out_exec_filter.rb +613 -0
- data/test/plugin/test_out_file.rb +873 -0
- data/test/plugin/test_out_forward.rb +685 -0
- data/test/plugin/test_out_null.rb +105 -0
- data/test/plugin/test_out_relabel.rb +28 -0
- data/test/plugin/test_out_roundrobin.rb +146 -0
- data/test/plugin/test_out_secondary_file.rb +442 -0
- data/test/plugin/test_out_stdout.rb +170 -0
- data/test/plugin/test_out_stream.rb +93 -0
- data/test/plugin/test_output.rb +870 -0
- data/test/plugin/test_output_as_buffered.rb +1932 -0
- data/test/plugin/test_output_as_buffered_compress.rb +165 -0
- data/test/plugin/test_output_as_buffered_overflow.rb +250 -0
- data/test/plugin/test_output_as_buffered_retries.rb +839 -0
- data/test/plugin/test_output_as_buffered_secondary.rb +877 -0
- data/test/plugin/test_output_as_standard.rb +374 -0
- data/test/plugin/test_owned_by.rb +35 -0
- data/test/plugin/test_parser.rb +359 -0
- data/test/plugin/test_parser_apache.rb +42 -0
- data/test/plugin/test_parser_apache2.rb +46 -0
- data/test/plugin/test_parser_apache_error.rb +45 -0
- data/test/plugin/test_parser_csv.rb +103 -0
- data/test/plugin/test_parser_json.rb +114 -0
- data/test/plugin/test_parser_labeled_tsv.rb +128 -0
- data/test/plugin/test_parser_multiline.rb +100 -0
- data/test/plugin/test_parser_nginx.rb +48 -0
- data/test/plugin/test_parser_none.rb +52 -0
- data/test/plugin/test_parser_regexp.rb +281 -0
- data/test/plugin/test_parser_syslog.rb +242 -0
- data/test/plugin/test_parser_tsv.rb +122 -0
- data/test/plugin/test_storage.rb +167 -0
- data/test/plugin/test_storage_local.rb +335 -0
- data/test/plugin/test_string_util.rb +26 -0
- data/test/plugin_helper/test_child_process.rb +794 -0
- data/test/plugin_helper/test_compat_parameters.rb +331 -0
- data/test/plugin_helper/test_event_emitter.rb +51 -0
- data/test/plugin_helper/test_event_loop.rb +52 -0
- data/test/plugin_helper/test_extract.rb +194 -0
- data/test/plugin_helper/test_formatter.rb +255 -0
- data/test/plugin_helper/test_inject.rb +519 -0
- data/test/plugin_helper/test_parser.rb +264 -0
- data/test/plugin_helper/test_retry_state.rb +422 -0
- data/test/plugin_helper/test_server.rb +1677 -0
- data/test/plugin_helper/test_storage.rb +542 -0
- data/test/plugin_helper/test_thread.rb +164 -0
- data/test/plugin_helper/test_timer.rb +132 -0
- data/test/scripts/exec_script.rb +32 -0
- data/test/scripts/fluent/plugin/formatter1/formatter_test1.rb +7 -0
- data/test/scripts/fluent/plugin/formatter2/formatter_test2.rb +7 -0
- data/test/scripts/fluent/plugin/formatter_known.rb +8 -0
- data/test/scripts/fluent/plugin/out_test.rb +81 -0
- data/test/scripts/fluent/plugin/out_test2.rb +80 -0
- data/test/scripts/fluent/plugin/parser_known.rb +4 -0
- data/test/test_clock.rb +164 -0
- data/test/test_config.rb +179 -0
- data/test/test_configdsl.rb +148 -0
- data/test/test_event.rb +515 -0
- data/test/test_event_router.rb +331 -0
- data/test/test_event_time.rb +186 -0
- data/test/test_filter.rb +121 -0
- data/test/test_formatter.rb +312 -0
- data/test/test_input.rb +31 -0
- data/test/test_log.rb +828 -0
- data/test/test_match.rb +137 -0
- data/test/test_mixin.rb +351 -0
- data/test/test_output.rb +273 -0
- data/test/test_plugin.rb +251 -0
- data/test/test_plugin_classes.rb +253 -0
- data/test/test_plugin_helper.rb +81 -0
- data/test/test_plugin_id.rb +101 -0
- data/test/test_process.rb +14 -0
- data/test/test_root_agent.rb +611 -0
- data/test/test_supervisor.rb +373 -0
- data/test/test_test_drivers.rb +135 -0
- data/test/test_time_formatter.rb +282 -0
- data/test/test_time_parser.rb +211 -0
- data/test/test_unique_id.rb +47 -0
- metadata +898 -0
@@ -0,0 +1,149 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'json'
|
18
|
+
|
19
|
+
require 'fluent/config'
|
20
|
+
require 'fluent/config/element'
|
21
|
+
|
22
|
+
module Fluent
|
23
|
+
module Config
|
24
|
+
module DSL
|
25
|
+
module Parser
|
26
|
+
def self.read(path)
|
27
|
+
path = File.expand_path(path)
|
28
|
+
data = File.read(path)
|
29
|
+
parse(data, path)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.parse(source, source_path="config.rb")
|
33
|
+
Proxy.new('ROOT', nil).eval(source, source_path).to_config_element
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Proxy
|
38
|
+
def initialize(name, arg, include_basepath = Dir.pwd)
|
39
|
+
@element = Element.new(name, arg, self)
|
40
|
+
@include_basepath = include_basepath
|
41
|
+
end
|
42
|
+
|
43
|
+
def element
|
44
|
+
@element
|
45
|
+
end
|
46
|
+
|
47
|
+
def include_basepath
|
48
|
+
@include_basepath
|
49
|
+
end
|
50
|
+
|
51
|
+
def eval(source, source_path)
|
52
|
+
@element.instance_eval(source, source_path)
|
53
|
+
self
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_config_element
|
57
|
+
@element.instance_eval do
|
58
|
+
Config::Element.new(@name, @arg, @attrs, @elements)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def add_element(name, arg, block)
|
63
|
+
::Kernel.raise ::ArgumentError, "#{name} block must be specified" if block.nil?
|
64
|
+
|
65
|
+
proxy = self.class.new(name.to_s, arg)
|
66
|
+
proxy.element.instance_exec(&block)
|
67
|
+
|
68
|
+
@element.instance_eval do
|
69
|
+
@elements.push(proxy.to_config_element)
|
70
|
+
end
|
71
|
+
|
72
|
+
self
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class Element < BasicObject
|
77
|
+
def initialize(name, arg, proxy)
|
78
|
+
@name = name
|
79
|
+
@arg = arg || ''
|
80
|
+
@attrs = {}
|
81
|
+
@elements = []
|
82
|
+
@proxy = proxy
|
83
|
+
end
|
84
|
+
|
85
|
+
def to_int
|
86
|
+
__id__
|
87
|
+
end
|
88
|
+
|
89
|
+
def method_missing(name, *args, &block)
|
90
|
+
::Kernel.raise ::ArgumentError, "Configuration DSL Syntax Error: only one argument allowed" if args.size > 1
|
91
|
+
value = args.first
|
92
|
+
|
93
|
+
if block
|
94
|
+
proxy = Proxy.new(name.to_s, value)
|
95
|
+
proxy.element.instance_exec(&block)
|
96
|
+
@elements.push(proxy.to_config_element)
|
97
|
+
else
|
98
|
+
@attrs[name.to_s] = if value.is_a?(Array) || value.is_a?(Hash)
|
99
|
+
JSON.dump(value)
|
100
|
+
else
|
101
|
+
value.to_s
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
self
|
106
|
+
end
|
107
|
+
|
108
|
+
def include(*args)
|
109
|
+
::Kernel.raise ::ArgumentError, "#{name} block requires arguments for include path" if args.nil? || args.size != 1
|
110
|
+
if args.first =~ /\.rb$/
|
111
|
+
path = File.expand_path(args.first)
|
112
|
+
data = File.read(path)
|
113
|
+
self.instance_eval(data, path)
|
114
|
+
else
|
115
|
+
ss = StringScanner.new('')
|
116
|
+
Config::V1Parser.new(ss, @proxy.include_basepath, '', nil).eval_include(@attrs, @elements, args.first)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def source(&block)
|
121
|
+
@proxy.add_element('source', nil, block)
|
122
|
+
end
|
123
|
+
|
124
|
+
def match(*args, &block)
|
125
|
+
::Kernel.raise ::ArgumentError, "#{name} block requires arguments for match pattern" if args.nil? || args.size != 1
|
126
|
+
@proxy.add_element('match', args.first, block)
|
127
|
+
end
|
128
|
+
|
129
|
+
def self.const_missing(name)
|
130
|
+
return ::Kernel.const_get(name) if ::Kernel.const_defined?(name)
|
131
|
+
|
132
|
+
if name.to_s =~ /^Fluent::Config::DSL::Element::(.*)$/
|
133
|
+
name = "#{$1}".to_sym
|
134
|
+
return ::Kernel.const_get(name) if ::Kernel.const_defined?(name)
|
135
|
+
end
|
136
|
+
::Kernel.eval("#{name}")
|
137
|
+
end
|
138
|
+
|
139
|
+
def ruby(&block)
|
140
|
+
if block
|
141
|
+
@proxy.instance_exec(&block)
|
142
|
+
else
|
143
|
+
::Kernel
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,218 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'fluent/config/error'
|
18
|
+
require 'fluent/config/literal_parser'
|
19
|
+
|
20
|
+
module Fluent
|
21
|
+
module Config
|
22
|
+
class Element < Hash
|
23
|
+
def initialize(name, arg, attrs, elements, unused = nil)
|
24
|
+
@name = name
|
25
|
+
@arg = arg
|
26
|
+
@elements = elements
|
27
|
+
super()
|
28
|
+
attrs.each { |k, v|
|
29
|
+
self[k] = v
|
30
|
+
}
|
31
|
+
@unused = unused || attrs.keys
|
32
|
+
@v1_config = false
|
33
|
+
@corresponding_proxies = [] # some plugins use flat parameters, e.g. in_http doesn't provide <format> section for parser.
|
34
|
+
@unused_in = false # if this element is not used in plugins, correspoing plugin name and parent element name is set, e.g. [source, plugin class].
|
35
|
+
|
36
|
+
# it's global logger, not plugin logger: deprecated message should be global warning, not plugin level.
|
37
|
+
@logger = defined?($log) ? $log : nil
|
38
|
+
end
|
39
|
+
|
40
|
+
attr_accessor :name, :arg, :unused, :v1_config, :corresponding_proxies, :unused_in
|
41
|
+
attr_writer :elements
|
42
|
+
|
43
|
+
RESERVED_PARAMETERS_COMPAT = {
|
44
|
+
'@type' => 'type',
|
45
|
+
'@id' => 'id',
|
46
|
+
'@log_level' => 'log_level',
|
47
|
+
'@label' => nil,
|
48
|
+
}
|
49
|
+
RESERVED_PARAMETERS = RESERVED_PARAMETERS_COMPAT.keys
|
50
|
+
|
51
|
+
def elements(*names, name: nil, arg: nil)
|
52
|
+
raise ArgumentError, "name and names are exclusive" if name && !names.empty?
|
53
|
+
raise ArgumentError, "arg is available only with name" if arg && !name
|
54
|
+
|
55
|
+
if name
|
56
|
+
@elements.select{|e| e.name == name && (!arg || e.arg == arg) }
|
57
|
+
elsif !names.empty?
|
58
|
+
@elements.select{|e| names.include?(e.name) }
|
59
|
+
else
|
60
|
+
@elements
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def add_element(name, arg = '')
|
65
|
+
e = Element.new(name, arg, {}, [])
|
66
|
+
e.v1_config = @v1_config
|
67
|
+
@elements << e
|
68
|
+
e
|
69
|
+
end
|
70
|
+
|
71
|
+
def inspect
|
72
|
+
attrs = super
|
73
|
+
"name:#{@name}, arg:#{@arg}, " + attrs + ", " + @elements.inspect
|
74
|
+
end
|
75
|
+
|
76
|
+
# This method assumes _o_ is an Element object. Should return false for nil or other object
|
77
|
+
def ==(o)
|
78
|
+
self.name == o.name && self.arg == o.arg &&
|
79
|
+
self.keys.size == o.keys.size &&
|
80
|
+
self.keys.reduce(true){|r, k| r && self[k] == o[k] } &&
|
81
|
+
self.elements.size == o.elements.size &&
|
82
|
+
[self.elements, o.elements].transpose.reduce(true){|r, e| r && e[0] == e[1] }
|
83
|
+
end
|
84
|
+
|
85
|
+
def +(o)
|
86
|
+
e = Element.new(@name.dup, @arg.dup, o.merge(self), @elements + o.elements, (@unused + o.unused).uniq)
|
87
|
+
e.v1_config = @v1_config
|
88
|
+
e
|
89
|
+
end
|
90
|
+
|
91
|
+
# no code in fluentd uses this method
|
92
|
+
def each_element(*names, &block)
|
93
|
+
if names.empty?
|
94
|
+
@elements.each(&block)
|
95
|
+
else
|
96
|
+
@elements.each { |e|
|
97
|
+
if names.include?(e.name)
|
98
|
+
block.yield(e)
|
99
|
+
end
|
100
|
+
}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def has_key?(key)
|
105
|
+
@unused_in = false # some sections, e.g. <store> in copy, is not defined by config_section so clear unused flag for better warning message in check_not_fetched.
|
106
|
+
@unused.delete(key)
|
107
|
+
super
|
108
|
+
end
|
109
|
+
|
110
|
+
def [](key)
|
111
|
+
@unused_in = false # ditto
|
112
|
+
@unused.delete(key)
|
113
|
+
|
114
|
+
if RESERVED_PARAMETERS.include?(key) && !has_key?(key) && has_key?(RESERVED_PARAMETERS_COMPAT[key])
|
115
|
+
@logger.warn "'#{RESERVED_PARAMETERS_COMPAT[key]}' is deprecated parameter name. use '#{key}' instead." if @logger
|
116
|
+
return self[RESERVED_PARAMETERS_COMPAT[key]]
|
117
|
+
end
|
118
|
+
|
119
|
+
super
|
120
|
+
end
|
121
|
+
|
122
|
+
def check_not_fetched(&block)
|
123
|
+
each_key { |key|
|
124
|
+
if @unused.include?(key)
|
125
|
+
block.call(key, self)
|
126
|
+
end
|
127
|
+
}
|
128
|
+
@elements.each { |e|
|
129
|
+
e.check_not_fetched(&block)
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
133
|
+
def to_s(nest = 0)
|
134
|
+
indent = " " * nest
|
135
|
+
nindent = " " * (nest + 1)
|
136
|
+
out = ""
|
137
|
+
if @arg.empty?
|
138
|
+
out << "#{indent}<#{@name}>\n"
|
139
|
+
else
|
140
|
+
out << "#{indent}<#{@name} #{@arg}>\n"
|
141
|
+
end
|
142
|
+
each_pair { |k, v|
|
143
|
+
out << dump_value(k, v, nindent)
|
144
|
+
}
|
145
|
+
@elements.each { |e|
|
146
|
+
out << e.to_s(nest + 1)
|
147
|
+
}
|
148
|
+
out << "#{indent}</#{@name}>\n"
|
149
|
+
out
|
150
|
+
end
|
151
|
+
|
152
|
+
def to_masked_element
|
153
|
+
new_elems = @elements.map { |e| e.to_masked_element }
|
154
|
+
new_elem = Element.new(@name, @arg, {}, new_elems, @unused)
|
155
|
+
new_elem.v1_config = @v1_config
|
156
|
+
new_elem.corresponding_proxies = @corresponding_proxies
|
157
|
+
each_pair { |k, v|
|
158
|
+
new_elem[k] = secret_param?(k) ? 'xxxxxx' : v
|
159
|
+
}
|
160
|
+
new_elem
|
161
|
+
end
|
162
|
+
|
163
|
+
def secret_param?(key)
|
164
|
+
return false if @corresponding_proxies.empty?
|
165
|
+
|
166
|
+
param_key = key.to_sym
|
167
|
+
@corresponding_proxies.each { |proxy|
|
168
|
+
_block, opts = proxy.params[param_key]
|
169
|
+
if opts && opts.has_key?(:secret)
|
170
|
+
return opts[:secret]
|
171
|
+
end
|
172
|
+
}
|
173
|
+
|
174
|
+
false
|
175
|
+
end
|
176
|
+
|
177
|
+
def param_type(key)
|
178
|
+
return nil if @corresponding_proxies.empty?
|
179
|
+
|
180
|
+
param_key = key.to_sym
|
181
|
+
proxy = @corresponding_proxies.detect do |_proxy|
|
182
|
+
_proxy.params.has_key?(param_key)
|
183
|
+
end
|
184
|
+
return nil unless proxy
|
185
|
+
_block, opts = proxy.params[param_key]
|
186
|
+
opts[:type]
|
187
|
+
end
|
188
|
+
|
189
|
+
def dump_value(k, v, nindent)
|
190
|
+
if secret_param?(k)
|
191
|
+
"#{nindent}#{k} xxxxxx\n"
|
192
|
+
else
|
193
|
+
if @v1_config
|
194
|
+
case param_type(k)
|
195
|
+
when :string
|
196
|
+
"#{nindent}#{k} \"#{self.class.unescape_parameter(v)}\"\n"
|
197
|
+
when :enum, :integer, :float, :size, :bool, :time
|
198
|
+
"#{nindent}#{k} #{v}\n"
|
199
|
+
when :hash, :array
|
200
|
+
"#{nindent}#{k} #{v}\n"
|
201
|
+
else
|
202
|
+
# Unknown type
|
203
|
+
"#{nindent}#{k} #{v}\n"
|
204
|
+
end
|
205
|
+
else
|
206
|
+
"#{nindent}#{k} #{v}\n"
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
def self.unescape_parameter(v)
|
212
|
+
result = ''
|
213
|
+
v.each_char { |c| result << LiteralParser.unescape_char(c) }
|
214
|
+
result
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
module Fluent
|
18
|
+
class ConfigError < StandardError
|
19
|
+
end
|
20
|
+
|
21
|
+
class ConfigParseError < ConfigError
|
22
|
+
end
|
23
|
+
|
24
|
+
class ObsoletedParameterError < ConfigError
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,251 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'stringio'
|
18
|
+
|
19
|
+
require 'json'
|
20
|
+
require 'yajl'
|
21
|
+
require 'irb/ruby-lex' # RubyLex
|
22
|
+
|
23
|
+
require 'fluent/config/basic_parser'
|
24
|
+
|
25
|
+
module Fluent
|
26
|
+
module Config
|
27
|
+
class LiteralParser < BasicParser
|
28
|
+
def self.unescape_char(c)
|
29
|
+
case c
|
30
|
+
when '"'
|
31
|
+
'\"'
|
32
|
+
when "'"
|
33
|
+
"\\'"
|
34
|
+
when '\\'
|
35
|
+
'\\\\'
|
36
|
+
when "\r"
|
37
|
+
'\r'
|
38
|
+
when "\n"
|
39
|
+
'\n'
|
40
|
+
when "\t"
|
41
|
+
'\t'
|
42
|
+
when "\f"
|
43
|
+
'\f'
|
44
|
+
when "\b"
|
45
|
+
'\b'
|
46
|
+
else
|
47
|
+
c
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def initialize(strscan, eval_context)
|
52
|
+
super(strscan)
|
53
|
+
@eval_context = eval_context
|
54
|
+
end
|
55
|
+
|
56
|
+
def parse_literal(string_boundary_charset = LINE_END)
|
57
|
+
spacing_without_comment
|
58
|
+
|
59
|
+
value = if skip(/\[/)
|
60
|
+
scan_json(true)
|
61
|
+
elsif skip(/\{/)
|
62
|
+
scan_json(false)
|
63
|
+
else
|
64
|
+
scan_string(string_boundary_charset)
|
65
|
+
end
|
66
|
+
value
|
67
|
+
end
|
68
|
+
|
69
|
+
def scan_string(string_boundary_charset = LINE_END)
|
70
|
+
if skip(/\"/)
|
71
|
+
return scan_double_quoted_string
|
72
|
+
elsif skip(/\'/)
|
73
|
+
return scan_single_quoted_string
|
74
|
+
else
|
75
|
+
return scan_nonquoted_string(string_boundary_charset)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def scan_double_quoted_string
|
80
|
+
string = []
|
81
|
+
while true
|
82
|
+
if skip(/\"/)
|
83
|
+
return string.join
|
84
|
+
elsif check(/[^"]#{LINE_END_WITHOUT_SPACING_AND_COMMENT}/)
|
85
|
+
if s = check(/[^\\]#{LINE_END_WITHOUT_SPACING_AND_COMMENT}/)
|
86
|
+
string << s
|
87
|
+
end
|
88
|
+
skip(/[^"]#{LINE_END_WITHOUT_SPACING_AND_COMMENT}/)
|
89
|
+
elsif s = scan(/\\./)
|
90
|
+
string << eval_escape_char(s[1,1])
|
91
|
+
elsif skip(/\#\{/)
|
92
|
+
string << eval_embedded_code(scan_embedded_code)
|
93
|
+
skip(/\}/)
|
94
|
+
elsif s = scan(/./)
|
95
|
+
string << s
|
96
|
+
else
|
97
|
+
parse_error! "unexpected end of file in a double quoted string"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def scan_single_quoted_string
|
103
|
+
string = []
|
104
|
+
while true
|
105
|
+
if skip(/\'/)
|
106
|
+
return string.join
|
107
|
+
elsif s = scan(/\\'/)
|
108
|
+
string << "'"
|
109
|
+
elsif s = scan(/\\\\/)
|
110
|
+
string << "\\"
|
111
|
+
elsif s = scan(/./)
|
112
|
+
string << s
|
113
|
+
else
|
114
|
+
parse_error! "unexpected end of file in a signle quoted string"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def scan_nonquoted_string(boundary_charset = LINE_END)
|
120
|
+
charset = /(?!#{boundary_charset})./
|
121
|
+
|
122
|
+
string = []
|
123
|
+
while true
|
124
|
+
if s = scan(/\#/)
|
125
|
+
string << '#'
|
126
|
+
elsif s = scan(charset)
|
127
|
+
string << s
|
128
|
+
else
|
129
|
+
break
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
if string.empty?
|
134
|
+
return nil
|
135
|
+
end
|
136
|
+
|
137
|
+
string.join
|
138
|
+
end
|
139
|
+
|
140
|
+
def scan_embedded_code
|
141
|
+
rlex = RubyLex.new
|
142
|
+
src = '"#{'+@ss.rest+"\n=end\n}"
|
143
|
+
|
144
|
+
input = StringIO.new(src)
|
145
|
+
input.define_singleton_method(:encoding) { external_encoding }
|
146
|
+
rlex.set_input(input)
|
147
|
+
|
148
|
+
tk = rlex.token
|
149
|
+
code = src[3,tk.seek-3]
|
150
|
+
|
151
|
+
if @ss.rest.length < code.length
|
152
|
+
@ss.pos += @ss.rest.length
|
153
|
+
parse_error! "expected end of embedded code but $end"
|
154
|
+
end
|
155
|
+
|
156
|
+
@ss.pos += code.length
|
157
|
+
|
158
|
+
'"#{' + code + '}"'
|
159
|
+
end
|
160
|
+
|
161
|
+
def eval_embedded_code(code)
|
162
|
+
if @eval_context.nil?
|
163
|
+
parse_error! "embedded code is not allowed in this file"
|
164
|
+
end
|
165
|
+
@eval_context.instance_eval(code)
|
166
|
+
end
|
167
|
+
|
168
|
+
def eval_escape_char(c)
|
169
|
+
case c
|
170
|
+
when '"'
|
171
|
+
'"'
|
172
|
+
when "'"
|
173
|
+
"'"
|
174
|
+
when "r"
|
175
|
+
"\r"
|
176
|
+
when "n"
|
177
|
+
"\n"
|
178
|
+
when "t"
|
179
|
+
"\t"
|
180
|
+
when "f"
|
181
|
+
"\f"
|
182
|
+
when "b"
|
183
|
+
"\b"
|
184
|
+
when /[a-zA-Z0-9]/
|
185
|
+
parse_error! "unexpected back-slash escape character '#{c}'"
|
186
|
+
else # symbols
|
187
|
+
c
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def scan_json(is_array)
|
192
|
+
result = nil
|
193
|
+
# Yajl does not raise ParseError for imcomplete json string, like '[1', '{"h"', '{"h":' or '{"h1":1'
|
194
|
+
# This is the reason to use JSON module.
|
195
|
+
|
196
|
+
buffer = (is_array ? "[" : "{")
|
197
|
+
line_buffer = ""
|
198
|
+
|
199
|
+
until result
|
200
|
+
char = getch
|
201
|
+
|
202
|
+
break if char.nil?
|
203
|
+
|
204
|
+
if char == "#"
|
205
|
+
# If this is out of json string literals, this object can be parsed correctly
|
206
|
+
# '{"foo":"bar", #' -> '{"foo":"bar"}' (to check)
|
207
|
+
parsed = nil
|
208
|
+
begin
|
209
|
+
parsed = JSON.parse(buffer + line_buffer.rstrip.sub(/,$/, '') + (is_array ? "]" : "}"))
|
210
|
+
rescue JSON::ParserError => e
|
211
|
+
# This '#' is in json string literals
|
212
|
+
end
|
213
|
+
|
214
|
+
if parsed
|
215
|
+
# ignore chars as comment before newline
|
216
|
+
while (char = getch) != "\n"
|
217
|
+
# ignore comment char
|
218
|
+
end
|
219
|
+
buffer << line_buffer + "\n"
|
220
|
+
line_buffer = ""
|
221
|
+
else
|
222
|
+
# '#' is a char in json string
|
223
|
+
line_buffer << char
|
224
|
+
end
|
225
|
+
|
226
|
+
next # This char '#' MUST NOT terminate json object.
|
227
|
+
end
|
228
|
+
|
229
|
+
if char == "\n"
|
230
|
+
buffer << line_buffer + "\n"
|
231
|
+
line_buffer = ""
|
232
|
+
next
|
233
|
+
end
|
234
|
+
|
235
|
+
line_buffer << char
|
236
|
+
begin
|
237
|
+
result = JSON.parse(buffer + line_buffer)
|
238
|
+
rescue JSON::ParserError => e
|
239
|
+
# Incomplete json string yet
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
unless result
|
244
|
+
parse_error! "got incomplete JSON #{is_array ? 'array' : 'hash'} configuration"
|
245
|
+
end
|
246
|
+
|
247
|
+
JSON.dump(result)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|