Sha256: b5fa8d3475949af5a3d9f4275a2999643d9f0433ddebe4cdcf73ee538cfc2327

Contents?: true

Size: 1.26 KB

Versions: 21

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module Facter
  class ConfigReader
    class << self
      attr_accessor :conf

      def init(config_path = nil)
        config_path ||= default_path
        refresh_config(config_path)
        self
      end

      def block_list
        @conf['facts'] && @conf['facts']['blocklist']
      end

      def ttls
        @conf['facts'] && @conf['facts']['ttls']
      end

      def global
        @conf['global']
      end

      def cli
        @conf['cli']
      end

      def fact_groups
        @conf['fact-groups']
      end

      def refresh_config(config_path)
        @conf = File.readable?(config_path) ? Hocon.load(config_path) : {}
      rescue StandardError => e
        log.warn("Facter failed to read config file #{config_path} with the following error: #{e.message}")
        @conf = {}
      end

      private

      def log
        @log ||= Log.new(self)
      end

      def default_path
        return '' if RUBY_PLATFORM == 'java'

        os = OsDetector.instance.identifier

        windows_path = File.join('C:', 'ProgramData', 'PuppetLabs', 'facter', 'etc', 'facter.conf')
        linux_path = File.join('/', 'etc', 'puppetlabs', 'facter', 'facter.conf')

        os == :windows ? windows_path : linux_path
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
facter-4.4.0 lib/facter/framework/config/config_reader.rb
facter-4.3.1 lib/facter/framework/config/config_reader.rb
facter-4.3.0 lib/facter/framework/config/config_reader.rb
facter-4.2.14 lib/facter/framework/config/config_reader.rb
facter-4.2.13 lib/facter/framework/config/config_reader.rb
facter-4.2.12 lib/facter/framework/config/config_reader.rb
facter-4.2.11 lib/facter/framework/config/config_reader.rb
facter-4.2.10 lib/facter/framework/config/config_reader.rb
facter-4.2.9 lib/facter/framework/config/config_reader.rb
facter-4.2.8 lib/facter/framework/config/config_reader.rb
facter-4.2.7 lib/facter/framework/config/config_reader.rb
facter-4.2.6 lib/facter/framework/config/config_reader.rb
facter-4.2.5 lib/facter/framework/config/config_reader.rb
facter-4.2.4 lib/facter/framework/config/config_reader.rb
facter-4.2.3 lib/facter/framework/config/config_reader.rb
facter-4.2.2 lib/facter/framework/config/config_reader.rb
facter-4.2.1 lib/facter/framework/config/config_reader.rb
facter-4.2.0 lib/facter/framework/config/config_reader.rb
facter-4.1.1 lib/facter/framework/config/config_reader.rb
facter-4.1.0 lib/facter/framework/config/config_reader.rb