class Fluent::EC2Metadata::PlaceholderExpander

Attributes

Public Class Methods

new(log) click to toggle source
# File lib/fluent/plugin/ec2_metadata.rb, line 142
def initialize(log)
  @log = log
end

Public Instance Methods

expand(str, placeholders) click to toggle source
# File lib/fluent/plugin/ec2_metadata.rb, line 168
def expand(str, placeholders)
  str.gsub(/(\${[a-z_:\-]+(\[-?[0-9]+\])?}|__[A-Z_]+__)/) {
    @log.warn "ec2-metadata: unknown placeholder `#{$1}` found in a tag `#{placeholders['${tag}']}`" unless placeholders.include?($1)
    placeholders[$1]
  }
end
prepare_placeholders(_record, tag, tag_parts, ec2_metadata) click to toggle source
# File lib/fluent/plugin/ec2_metadata.rb, line 150
def prepare_placeholders(_record, tag, tag_parts, ec2_metadata)
  placeholders = {
    '${tag}' => tag,
  }

  size = tag_parts.size
  tag_parts.each_with_index { |t, idx|
    placeholders.store("${tag_parts[#{idx}]}", t)
    placeholders.store("${tag_parts[#{idx-size}]}", t) # support tag_parts[-1]
  }

  ec2_metadata.each { |k, v|
    placeholders.store("${#{k}}", v)
  }

  placeholders
end