openfact 6.0.0 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e52f6542f74fd6ae174527c89973ccf46aa5542e44d9f397bc800fbc92d357bd
4
- data.tar.gz: ce3214f7c6274abcff1fb2606963f551f207a2aa0a67016b01614468a685f42a
3
+ metadata.gz: 4daa243a80d8ba47b89553843beda2cb577af1592688fc50824b28b4453c4e72
4
+ data.tar.gz: 1e1cbf1a2817cf2eb906ed791fd58bc60d0b1acaa229ace93e8a55d2f353c758
5
5
  SHA512:
6
- metadata.gz: 864114f9fa9ed5f294a306aa3d7d0e10d069bc3ad3020e33d63a022c83989e4fb4bd16fae775a6ee125dcf8feb5d67b3e571ebd95c869f5bcf5390c7b3b749a0
7
- data.tar.gz: af09f689814fbd7ea78a4323025522447b7edb9811a257973efaf083f45fa78f4c55945ccc8384e3fadd7e0b20786e7bf499fdc3d88a8bfa91cd1a4a1b28a9c3
6
+ metadata.gz: 1791dc19b98a3676c9adcbc03df513ba5907d123159de09e6a67317ecdee1003eb5c1ea057b9099d81972c10f39e55a9f73f02f5a498918cc7fd227a710990b6
7
+ data.tar.gz: ba01bd6bf64dfe485897a0be96bcb8f7686b8500298f3205b28c7d8f20905b3d4db9530e11221be1e5bc55e92370eea7d82f0dcc80d82eaf58d19b4f6b74a861
@@ -11,7 +11,7 @@
11
11
  ### `<%= name %>`
12
12
 
13
13
  <% if schema['hidden'] -%>
14
- This legacy fact is hidden by default in Facter's command-line output.
14
+ This legacy fact is hidden by default in OpenFact's command-line output.
15
15
 
16
16
  <% end -%>
17
17
  **Type:** <%= schema['type'] %>
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # A Facter plugin that loads external facts.
3
+ # An OpenFact plugin that loads external facts.
4
4
  #
5
5
  # Default Unix Directories:
6
6
  # /opt/puppetlabs/custom_facts/facts.d, /etc/custom_facts/facts.d, /etc/puppetlabs/custom_facts/facts.d
@@ -104,7 +104,7 @@ module Facter
104
104
  class_option :puppet,
105
105
  type: :boolean,
106
106
  aliases: '-p',
107
- desc: 'Load the Puppet libraries, thus allowing Facter to load Puppet-specific facts.'
107
+ desc: 'Load the OpenVox libraries, thus allowing OpenFact to load OpenVox-specific facts.'
108
108
 
109
109
  desc '--man', 'Display manual.', hide: true
110
110
  map ['--man'] => :man
@@ -34,7 +34,7 @@ module Facter
34
34
  def refresh_config(config_path)
35
35
  @conf = File.readable?(config_path) ? Hocon.load(config_path) : {}
36
36
  rescue StandardError => e
37
- log.warn("Facter failed to read config file #{config_path} with the following error: #{e.message}")
37
+ log.warn("OpenFact failed to read config file #{config_path} with the following error: #{e.message}")
38
38
  @conf = {}
39
39
  end
40
40
 
@@ -52,7 +52,7 @@ module Facter
52
52
 
53
53
  def set_logger_format
54
54
  @@logger.formatter = proc do |severity, datetime, _progname, msg|
55
- datetime = datetime.strftime(@datetime_format || '%Y-%m-%d %H:%M:%S.%6N ')
55
+ datetime = datetime.strftime('%Y-%m-%dT%H:%M:%S.%6N%:z')
56
56
  "[#{datetime}] #{severity} #{msg} \n"
57
57
  end
58
58
  end
@@ -18,14 +18,19 @@ module Facter
18
18
  end
19
19
 
20
20
  def read_facts(fact_name)
21
- @fact_list[:metadata] = {}
22
- query_for_metadata(EC2_METADATA_ROOT_URL, @fact_list[:metadata])
23
- @fact_list[:userdata] = get_data_from(EC2_USERDATA_ROOT_URL).strip.force_encoding('UTF-8')
21
+ if fact_name == :metadata
22
+ metadata = {}
23
+ query_for_metadata(EC2_METADATA_ROOT_URL, metadata)
24
+ @fact_list[:metadata] = metadata
25
+ else
26
+ @fact_list[:userdata] = get_data_from(EC2_USERDATA_ROOT_URL).strip.force_encoding('UTF-8')
27
+ end
28
+
24
29
  @fact_list[fact_name]
25
30
  end
26
31
 
27
32
  def query_for_metadata(url, container)
28
- metadata = get_data_from(url)
33
+ metadata = get_metadata_from(url)
29
34
  metadata.each_line do |line|
30
35
  next if line.empty?
31
36
 
@@ -34,14 +39,15 @@ module Facter
34
39
 
35
40
  if http_path_component.end_with?('/')
36
41
  child = {}
37
- child[http_path_component] = query_for_metadata("#{url}#{http_path_component}", child)
38
- child.reject! { |key, _info| key == http_path_component }
42
+ query_for_metadata("#{url}#{http_path_component}", child)
39
43
  name = http_path_component.chomp('/')
40
44
  container[name] = child
41
45
  else
42
- container[http_path_component] = get_data_from("#{url}#{http_path_component}").strip
46
+ container[http_path_component] = get_metadata_from("#{url}#{http_path_component}").strip
43
47
  end
44
48
  end
49
+
50
+ container
45
51
  end
46
52
 
47
53
  def build_path_component(line)
@@ -55,6 +61,12 @@ module Facter
55
61
  Facter::Util::Resolvers::Http.get_request(url, headers, { session: determine_session_timeout }, false)
56
62
  end
57
63
 
64
+ def get_metadata_from(url)
65
+ headers = {}
66
+ headers['X-aws-ec2-metadata-token'] = v2_token if v2_token
67
+ Facter::Util::Resolvers::Http.get_request!(url, headers, { session: determine_session_timeout }, false)
68
+ end
69
+
58
70
  def determine_session_timeout
59
71
  session_env = ENV.fetch('EC2_SESSION_TIMEOUT', nil)
60
72
  session_env ? session_env.to_i : EC2_SESSION_TIMEOUT
@@ -10,20 +10,20 @@ module Facter
10
10
  end
11
11
 
12
12
  class Sockaddr < ::FFI::Struct
13
- layout :sa_family, :sa_family_t,
14
- :sa_data, [:uchar, 14]
13
+ layout :sa_family, :sa_family_t,
14
+ :sa_data, [:uchar, 14]
15
15
  end
16
16
 
17
17
  class Lifnum < ::FFI::Struct
18
- layout :lifn_family, :sa_family_t,
19
- :lifn_flags, :int,
20
- :lifn_count, :int
18
+ layout :lifn_family, :sa_family_t,
19
+ :lifn_flags, :int,
20
+ :lifn_count, :int
21
21
  end
22
22
 
23
23
  class Arpreq < ::FFI::Struct
24
- layout :arp_pa, Sockaddr,
25
- :arp_ha, Sockaddr,
26
- :arp_flags, :int
24
+ layout :arp_pa, Sockaddr,
25
+ :arp_ha, Sockaddr,
26
+ :arp_flags, :int
27
27
 
28
28
  def sa_data_to_mac
29
29
  self[:arp_ha][:sa_data].entries[0, 6].map do |s|
@@ -41,27 +41,27 @@ module Facter
41
41
  end
42
42
 
43
43
  class Lifru1 < ::FFI::Union
44
- layout :lifru_addrlen, :int,
45
- :lifru_ppa, :uint_t
44
+ layout :lifru_addrlen, :int,
45
+ :lifru_ppa, :uint_t
46
46
  end
47
47
 
48
48
  class Lifru < ::FFI::Union
49
- layout :lifru_addr, SockaddrStorage,
50
- :lifru_dstaddr, SockaddrStorage,
51
- :lifru_broadaddr, SockaddrStorage,
52
- :lifru_token, SockaddrStorage,
53
- :lifru_subnet, SockaddrStorage,
54
- :lifru_flags, :uint64,
55
- :lifru_metric, :int,
56
- :pad, [:char, 80]
49
+ layout :lifru_addr, SockaddrStorage,
50
+ :lifru_dstaddr, SockaddrStorage,
51
+ :lifru_broadaddr, SockaddrStorage,
52
+ :lifru_token, SockaddrStorage,
53
+ :lifru_subnet, SockaddrStorage,
54
+ :lifru_flags, :uint64,
55
+ :lifru_metric, :int,
56
+ :pad, [:char, 80]
57
57
  end
58
58
 
59
59
  class Lifreq < ::FFI::Struct
60
- layout :lifr_name, [:char, 32],
61
- :lifr_lifru1, Lifru1,
62
- :lifr_movetoindex, :int,
63
- :lifr_lifru, Lifru,
64
- :pad, [:char, 80]
60
+ layout :lifr_name, [:char, 32],
61
+ :lifr_lifru1, Lifru1,
62
+ :lifr_movetoindex, :int,
63
+ :lifr_lifru, Lifru,
64
+ :pad, [:char, 80]
65
65
 
66
66
  def name
67
67
  self[:lifr_name].to_s
@@ -77,10 +77,10 @@ module Facter
77
77
  end
78
78
 
79
79
  class Lifconf < ::FFI::Struct
80
- layout :lifc_family, :uint,
81
- :lifc_flags, :int,
82
- :lifc_len, :int,
83
- :lifc_buf, :pointer
80
+ layout :lifc_family, :uint,
81
+ :lifc_flags, :int,
82
+ :lifc_len, :int,
83
+ :lifc_buf, :pointer
84
84
 
85
85
  def self.new_for_ioctl(interface_count)
86
86
  lifconf = new
@@ -93,8 +93,8 @@ module Facter
93
93
  end
94
94
 
95
95
  class Lifcu < ::FFI::Union
96
- layout :lifcu_buf, :caddr_t,
97
- :lifcu_req, Lifreq
96
+ layout :lifcu_buf, :caddr_t,
97
+ :lifcu_req, Lifreq
98
98
  end
99
99
 
100
100
  class InAddr < ::FFI::Struct
@@ -102,10 +102,10 @@ module Facter
102
102
  end
103
103
 
104
104
  class SockaddrIn < ::FFI::Struct
105
- layout :sin_family, :sa_family_t,
106
- :sin_port, :in_port_t,
107
- :sin_addr, InAddr,
108
- :sin_zero, [:char, 8]
105
+ layout :sin_family, :sa_family_t,
106
+ :sin_port, :in_port_t,
107
+ :sin_addr, InAddr,
108
+ :sin_zero, [:char, 8]
109
109
 
110
110
  def s_addr
111
111
  self[:sin_addr][:s_addr]
@@ -117,11 +117,11 @@ module Facter
117
117
  end
118
118
 
119
119
  class SockaddrIn6 < ::FFI::Struct
120
- layout :sin6_family, :sa_family_t,
121
- :sin6_port, :in_port_t,
122
- :sin6_flowinfo, :uint32_t,
123
- :sin6_addr, In6Addr,
124
- :sin6_scope_id, :uint32_t
120
+ layout :sin6_family, :sa_family_t,
121
+ :sin6_port, :in_port_t,
122
+ :sin6_flowinfo, :uint32_t,
123
+ :sin6_addr, In6Addr,
124
+ :sin6_scope_id, :uint32_t
125
125
  end
126
126
  end
127
127
  end
@@ -23,9 +23,8 @@ module Facter
23
23
  end
24
24
 
25
25
  def build_fact_list(reg)
26
- # rubocop:disable Performance/InefficientHashSearch
26
+ # rubocop:disable-next Performance/InefficientHashSearch
27
27
  @fact_list[:kvm] = reg.keys.include?('netkvm')
28
- # rubocop:enable Performance/InefficientHashSearch
29
28
  end
30
29
  end
31
30
  end
@@ -15,19 +15,18 @@ module Facter
15
15
  default_return
16
16
  end
17
17
 
18
- # rubocop:disable Style/SpecialGlobalVars
18
+ # rubocop:disable-next Style/SpecialGlobalVars
19
19
  def safe_readlines(path, default_return = [], sep = $/, chomp: false)
20
20
  return File.readlines(path, sep, chomp: chomp, encoding: Encoding::UTF_8) if File.readable?(path)
21
21
 
22
22
  log_failed_to_read(path)
23
23
  default_return
24
24
  end
25
- # rubocop:enable Style/SpecialGlobalVars
26
25
 
27
26
  # This previously acted as a helper method for versions of Ruby older
28
27
  # than 2.5, before Dir.children was added. As it isn't a private
29
- # method, we can't remove it entirely until the next major Facter
30
- # release (presumably Facter 5).
28
+ # method, we can't remove it entirely until the next major OpenFact
29
+ # release.
31
30
  def dir_children(path)
32
31
  Dir.children(path)
33
32
  end
@@ -6,6 +6,8 @@ module Facter
6
6
  module Http
7
7
  @log = Facter::Log.new(self)
8
8
 
9
+ class RequestError < StandardError; end
10
+
9
11
  class << self
10
12
  CONNECTION_TIMEOUT = 0.6
11
13
  SESSION_TIMEOUT = 5
@@ -27,6 +29,15 @@ module Facter
27
29
  make_request(url, headers, timeouts, 'GET', proxy)
28
30
  end
29
31
 
32
+ # Makes a GET HTTP request and returns its response body.
33
+ #
34
+ # Unlike get_request, this method raises when the response code is
35
+ # not 200 or when the request fails. A successful empty response is
36
+ # still returned as an empty string.
37
+ def get_request!(url, headers = {}, timeouts = {}, proxy = true)
38
+ make_request!(url, headers, timeouts, 'GET', proxy)
39
+ end
40
+
30
41
  # Makes a PUT HTTP request and returns its response
31
42
  # @param (see #get_request)
32
43
  # @return (see #get_request)
@@ -37,6 +48,28 @@ module Facter
37
48
  private
38
49
 
39
50
  def make_request(url, headers, timeouts, request_type, proxy)
51
+ response = perform_request(url, headers, timeouts, request_type, proxy)
52
+
53
+ successful_response?(response) ? response.body : ''
54
+ rescue StandardError => e
55
+ @log.debug("Trying to connect to #{url} but got: #{e.message}")
56
+ ''
57
+ end
58
+
59
+ def make_request!(url, headers, timeouts, request_type, proxy)
60
+ response = perform_request(url, headers, timeouts, request_type, proxy)
61
+
62
+ return response.body if successful_response?(response)
63
+
64
+ raise RequestError, "Request to #{url} failed with HTTP status #{response.code}"
65
+ rescue RequestError
66
+ raise
67
+ rescue StandardError => e
68
+ @log.debug("Trying to connect to #{url} but got: #{e.message}")
69
+ raise
70
+ end
71
+
72
+ def perform_request(url, headers, timeouts, request_type, proxy)
40
73
  require 'net/http'
41
74
 
42
75
  uri = URI.parse(url)
@@ -52,11 +85,7 @@ module Facter
52
85
  # Make the request
53
86
  response = http.request(request)
54
87
  response.uri = url
55
-
56
- successful_response?(response) ? response.body : ''
57
- rescue StandardError => e
58
- @log.debug("Trying to connect to #{url} but got: #{e.message}")
59
- ''
88
+ response
60
89
  end
61
90
 
62
91
  def http_obj(parsed_url, timeouts, proxy)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Facter
4
- VERSION = '6.0.0' unless defined?(VERSION)
4
+ VERSION = '6.1.0' unless defined?(VERSION)
5
5
  end
data/lib/facter.rb CHANGED
@@ -15,7 +15,7 @@ module Facter
15
15
  @already_searched = {}
16
16
 
17
17
  class << self
18
- # Method used by puppet-agent to retrieve facts
18
+ # Method used by openvox-agent to retrieve facts
19
19
  # @param args_as_string [string] facter cli arguments
20
20
  #
21
21
  # @return [Hash<String, Object>]
@@ -45,8 +45,8 @@ module Facter
45
45
  Hash[queried_facts(cli.args)]
46
46
  end
47
47
 
48
- # Method used by cli to set puppet paths
49
- # in order to retrieve puppet custom and external facts
48
+ # Method used by cli to set OpenVox paths
49
+ # in order to retrieve OpenVox custom and external facts
50
50
  #
51
51
  # @return nil
52
52
  #
@@ -54,7 +54,7 @@ module Facter
54
54
  def puppet_facts
55
55
  require 'puppet'
56
56
 
57
- # don't allow puppet logger to be injected in Facter
57
+ # don't allow the OpenVox logger to be injected in OpenFact
58
58
  Options[:allow_external_loggers] = false
59
59
 
60
60
  Puppet.initialize_settings
@@ -69,7 +69,7 @@ module Facter
69
69
  end
70
70
  end
71
71
  rescue LoadError => e
72
- logger.error("Could not load puppet gem, got #{e}")
72
+ logger.error("Could not load the openvox gem, got #{e}")
73
73
  end
74
74
 
75
75
  # Alias method for Facter.fact()
@@ -375,7 +375,7 @@ module Facter
375
375
  # @api public
376
376
  def to_hash
377
377
  log_blocked_facts
378
- logger.debug("Facter version: #{Facter::VERSION}")
378
+ logger.debug("OpenFact version: #{Facter::VERSION}")
379
379
 
380
380
  resolved_facts = Facter::FactManager.instance.resolve_facts
381
381
  resolved_facts.reject! { |fact| fact.type == :custom && fact.value.nil? }
@@ -439,7 +439,7 @@ module Facter
439
439
  @already_searched[user_query]
440
440
  end
441
441
 
442
- # Returns Facter version
442
+ # Returns OpenFact version
443
443
  #
444
444
  # @return [String] Current version
445
445
  #
@@ -456,7 +456,7 @@ module Facter
456
456
  def to_user_output(cli_options, *args)
457
457
  init_cli_options(cli_options)
458
458
  logger.info("executed with command line: #{ARGV.drop(1).join(' ')}")
459
- logger.debug("Facter version: #{Facter::VERSION}")
459
+ logger.debug("OpenFact version: #{Facter::VERSION}")
460
460
  log_blocked_facts
461
461
  resolved_facts = resolve_facts_for_user_query(args)
462
462
  fact_formatter = Facter::FormatterFactory.build(Facter::Options.get)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openfact
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenVox Project
@@ -87,14 +87,14 @@ dependencies:
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: 1.88.0
90
+ version: 1.90.0
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: 1.88.0
97
+ version: 1.90.0
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: rubocop-performance
100
100
  requirement: !ruby/object:Gem::Requirement