Class: LogStash::Config::Source::Local::ConfigPathLoader

Inherits:
Object
  • Object
show all
Includes:
Util::Loggable
Defined in:
lib/logstash/config/source/local.rb

Constant Summary collapse

TEMPORARY_FILE_RE =
/~$/
LOCAL_FILE_URI =
/^file:\/\//i

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ConfigPathLoader

Returns a new instance of ConfigPathLoader.



49
50
51
# File 'lib/logstash/config/source/local.rb', line 49

def initialize(path)
  @path = normalize_path(path)
end

Class Method Details

.read(path) ⇒ Object



93
94
95
# File 'lib/logstash/config/source/local.rb', line 93

def self.read(path)
  ConfigPathLoader.new(path).read
end

Instance Method Details

#readObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/logstash/config/source/local.rb', line 53

def read
  config_parts = []
  encoding_issue_files = []

  if logger.debug?
    logger.debug("Skipping the following files while reading config since they don't match the specified glob pattern", :files => get_unmatched_files)
  end

  get_matched_files.each do |file|
    next unless ::File.file?(file) # skip directory

    logger.debug("Reading config file", :config_file => file)

    if temporary_file?(file)
      logger.warn("NOT reading config file because it is a temp file", :config_file => file)
      next
    end

    config_string = ::File.read(file)
    config_string.force_encoding("UTF-8")

    if config_string.valid_encoding?
      part = org.logstash.common.SourceWithMetadata.new("file", file, 0, 0, config_string)
      config_parts << part
    else
      encoding_issue_files << file
    end
  end

  if encoding_issue_files.any?
    raise LogStash::ConfigLoadingError, "The following config files contains non-ascii characters but are not UTF-8 encoded #{encoding_issue_files}"
  end

  if config_parts.empty?
    logger.info("No config files found in path", :path => path)
  end

  config_parts
end