403Webshell
Server IP : 104.21.14.103  /  Your IP : 18.191.103.117
Web Server : LiteSpeed
System : Linux business53.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64
User : giankuin ( 1871)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/facter/framework/formatters/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/facter/framework/formatters/yaml_fact_formatter.rb
# frozen_string_literal: true

module Facter
  class YamlFactFormatter
    def initialize
      @log = Log.new(self)
    end

    def format(resolved_facts)
      user_queries = resolved_facts.uniq(&:user_query).map(&:user_query)

      facts_to_display = if user_queries.count == 1 && user_queries.first.empty?
                           FormatterHelper.retrieve_fact_collection(resolved_facts)
                         else
                           FormatterHelper.retrieve_facts_to_display_for_user_query(user_queries, resolved_facts)
                         end

      facts_to_display = Psych.parse_stream(facts_to_display.to_yaml)
      facts_to_display.children[0].tag_directives = []
      yaml_pretty = quote_special_strings(facts_to_display)

      @log.debug('Replace ---  from yaml beginning, to keep it compatible with C facter')
      yaml_pretty.gsub(/^---[\r\n]+/, '')
    end

    private

    def quote_special_strings(fact_hash)
      require 'psych'

      fact_hash.grep(Psych::Nodes::Scalar).each do |node|
        next unless needs_quote?(node.value)

        node.plain  = false
        node.quoted = true
        node.style  = Psych::Nodes::Scalar::DOUBLE_QUOTED
      end

      fact_hash = unquote_keys(fact_hash)
      fact_hash.yaml
    end

    def unquote_keys(fact_hash)
      fact_hash.grep(Psych::Nodes::Mapping).each do |node|
        node.children.each_slice(2) do |k, _|
          k.plain  = true
          k.quoted = false
          k.style  = Psych::Nodes::Scalar::ANY
        end
      end
      fact_hash
    end

    def needs_quote?(value)
      return false if /true|false/.match?(value)
      return false if value[/^[0-9]+$/]
      return true if /y|Y|yes|Yes|YES|n|N|no|No|NO|True|TRUE|False|FALSE|on|On|ON|off|Off|OFF|:/.match?(value)
      return false if value[/[a-zA-Z]/]
      return false if value[/[0-9]+\.[0-9]+/]

      true
    end
  end
end

Youez - 2016 - github.com/yon3zu
LinuXploit