Sha256: b94b9cbb2700a2d392a48dad268370981f24a6f001863f8aacc33193e21f1cd8

Contents?: true

Size: 1.31 KB

Versions: 13

Compression:

Stored size: 1.31 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

      def clear
        @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

13 entries across 13 versions & 1 rubygems

Version Path
facter-4.10.0 lib/facter/framework/config/config_reader.rb
facter-4.9.0 lib/facter/framework/config/config_reader.rb
facter-4.8.0 lib/facter/framework/config/config_reader.rb
facter-4.7.1 lib/facter/framework/config/config_reader.rb
facter-4.7.0 lib/facter/framework/config/config_reader.rb
facter-4.6.1 lib/facter/framework/config/config_reader.rb
facter-4.6.0 lib/facter/framework/config/config_reader.rb
facter-4.5.2 lib/facter/framework/config/config_reader.rb
facter-4.5.1 lib/facter/framework/config/config_reader.rb
facter-4.5.0 lib/facter/framework/config/config_reader.rb
facter-4.4.3 lib/facter/framework/config/config_reader.rb
facter-4.4.2 lib/facter/framework/config/config_reader.rb
facter-4.4.1 lib/facter/framework/config/config_reader.rb