From ad7b83d3032abecba06154be9c1b81de8886fa4d Mon Sep 17 00:00:00 2001 From: Athish Pranav D Date: Tue, 6 Aug 2024 16:33:00 +0530 Subject: [PATCH] Moved Interpolation logic to logical_parser Signed-off-by: Athish Pranav D --- lib/fluent/config/literal_parser.rb | 14 ++++++++++---- lib/fluent/config/types.rb | 13 ------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/lib/fluent/config/literal_parser.rb b/lib/fluent/config/literal_parser.rb index 5664986481..ec68a54dd4 100644 --- a/lib/fluent/config/literal_parser.rb +++ b/lib/fluent/config/literal_parser.rb @@ -155,11 +155,11 @@ def scan_nonquoted_string(boundary_charset = LINE_END) end def scan_embedded_code - src = '"#{'+@ss.rest+"\n=begin\n=end\n}" + src = '#{'+@ss.rest+"\n=begin\n=end\n}" seek = -1 while (seek = src.index('}', seek + 1)) - unless Ripper.sexp(src[0..seek] + '"').nil? # eager parsing until valid expression + unless Ripper.sexp(src[0..seek]).nil? # eager parsing until valid expression break end end @@ -168,7 +168,7 @@ def scan_embedded_code raise Fluent::ConfigParseError, @ss.rest end - code = src[3, seek-3] + code = src[2, seek-2] if @ss.rest.length < code.length @ss.pos += @ss.rest.length @@ -255,7 +255,12 @@ def scan_json(is_array) line_buffer = "" else # '#' is a char in json string - line_buffer << char + if skip(/\{/) + line_buffer << eval_embedded_code(scan_embedded_code) + skip(/\}/) + else + line_buffer << char + end end next # This char '#' MUST NOT terminate json object. @@ -280,6 +285,7 @@ def scan_json(is_array) end JSON.dump(result) + end end end diff --git a/lib/fluent/config/types.rb b/lib/fluent/config/types.rb index b6b0e97657..9c9ba89c8d 100644 --- a/lib/fluent/config/types.rb +++ b/lib/fluent/config/types.rb @@ -201,7 +201,6 @@ def self.hash_value(val, opts = {}, name = nil) return nil if val.nil? param = if val.is_a?(String) - val = Config.process_env_vars(val) val.start_with?('{') ? JSON.parse(val) : Hash[val.strip.split(/\s*,\s*/).map{|v| v.split(':', 2)}] else val @@ -229,7 +228,6 @@ def self.array_value(val, opts = {}, name = nil) return nil if val.nil? param = if val.is_a?(String) - val = Config.process_env_vars(val) val.start_with?('[') ? JSON.parse(val) : val.strip.split(/\s*,\s*/) else val @@ -247,16 +245,5 @@ def self.array_value(val, opts = {}, name = nil) ARRAY_TYPE = Proc.new { |val, opts = {}, name = nil| Config.array_value(val, opts, name) } - - def self.process_env_vars(val) - pattern = /#\{ENV\[[^}]+\]\}/ - env_vars = val.scan(pattern) - env_vars.each do |env_var| - env_value = ENV[env_var[7..-4]] - raise ConfigError, "Environment variable #{env_var} not found" unless env_value - val.gsub!(env_var, env_value) - end - val - end end end