Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Commit

Permalink
Merge 5d69fa5 into 0f7cb7a
Browse files Browse the repository at this point in the history
  • Loading branch information
florindragos committed Apr 10, 2020
2 parents 0f7cb7a + 5d69fa5 commit f831585
Show file tree
Hide file tree
Showing 18 changed files with 603 additions and 34 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Metrics/ClassLength:
- 'lib/custom_facts/util/fact.rb'
- 'lib/resolvers/windows/networking_resolver.rb'
- 'lib/custom_facts/util/collection.rb'
- 'lib/framework/cli/cli.rb'

Style/DoubleNegation:
Exclude:
Expand Down
5 changes: 3 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# This configuration was generated by
# `rubocop --auto-gen-config --exclude-limit 1000`
# on 2020-04-07 19:23:35 +0300 using RuboCop version 0.74.0.
# on 2020-04-07 13:56:01 +0300 using RuboCop version 0.74.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 79
# Offense count: 80
# Configuration parameters: CustomTransform, IgnoreMethods.
RSpec/FilePath:
Exclude:
Expand Down Expand Up @@ -72,6 +72,7 @@ RSpec/FilePath:
- 'spec/facter/resolvers/windows/virtualization_resolver_spec.rb'
- 'spec/facter/resolvers/windows/win_os_description_resolver_spec.rb'
- 'spec/framework/config/block_list_spec.rb'
- 'spec/framework/config/cache_list_spec.rb'
- 'spec/framework/config/config_reader_spec.rb'
- 'spec/framework/core/fact/external/external_fact_manager_spec.rb'
- 'spec/framework/core/fact/internal/internal_fact_manager_spec.rb'
Expand Down
14 changes: 0 additions & 14 deletions block_groups.conf

This file was deleted.

169 changes: 169 additions & 0 deletions fact_groups.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
{
"EC2": [
"ec2_metadata",
"ec2_userdata"
],
"GCE": [
"gce"
],
"augeas": [
"augeas",
"augeasversion"
],
"desktop management interface": [
"dmi",
"bios_vendor",
"bios_version",
"bios_release_date",
"boardassettag",
"boardmanufacturer",
"boardproductname",
"boardserialnumber",
"chassisassettag",
"manufacturer",
"productname",
"serialnumber",
"uuid",
"chassistype"
],
"file system": [
"mountpoints",
"filesystems",
"partitions"
],
"hypervisors": [
"hypervisors"
],
"id": [
"id",
"gid",
"identity"
],
"kernel": [
"kernel",
"kernelversion",
"kernelrelease",
"kernelmajversion"
],
"load_average": [
"load_averages"
],
"memory": [
"memory",
"memoryfree",
"memoryfree_mb",
"memorysize",
"memorysize_mb",
"swapfree",
"swapfree_mb",
"swapsize",
"swapsize_mb",
"swapencrypted"
],
"networking": [
"networking",
"hostname",
"ipaddress",
"ipaddress6",
"netmask",
"netmask6",
"network",
"network6",
"macaddress",
"interfaces",
"domain",
"fqdn",
"dhcp_servers"
],
"operating system": [
"os",
"operatingsystem",
"osfamily",
"operatingsystemrelease",
"operatingsystemmajrelease",
"hardwaremodel",
"architecture",
"lsbdistid",
"lsbdistrelease",
"lsbdistcodename",
"lsbdistdescription",
"lsbmajdistrelease",
"lsbminordistrelease",
"lsbrelease",
"macosx_buildversion",
"macosx_productname",
"macosx_productversion",
"macosx_productversion_major",
"macosx_productversion_minor",
"windows_edition_id",
"windows_installation_type",
"windows_product_name",
"windows_release_id",
"system32",
"selinux",
"selinux_enforced",
"selinux_policyversion",
"selinux_current_mode",
"selinux_config_mode",
"selinux_config_policy"
],
"path": [
"path"
],
"processor": [
"processors",
"processorcount",
"physicalprocessorcount",
"hardwareisa"
],
"ssh": [
"ssh",
"sshdsakey",
"sshrsakey",
"sshecdsakey",
"sshed25519key",
"sshfp_dsa",
"sshfp_rsa",
"sshfp_ecdsa",
"sshfp_ed25519"
],
"system profiler": [
"system_profiler",
"sp_boot_mode",
"sp_boot_rom_version",
"sp_boot_volume",
"sp_cpu_type",
"sp_current_processor_speed",
"sp_kernel_version",
"sp_l2_cache_core",
"sp_l3_cache",
"sp_local_host_name",
"sp_machine_model",
"sp_machine_name",
"sp_number_processors",
"sp_os_version",
"sp_packages",
"sp_physical_memory",
"sp_platform_uuid",
"sp_secure_vm",
"sp_serial_number",
"sp_smc_version_system",
"sp_uptime",
"sp_user_name"
],
"timezone": [
"timezone"
],
"uptime": [
"system_uptime",
"uptime",
"uptime_days",
"uptime_hours",
"uptime_seconds"
],
"virtualization": [
"virtual",
"is_virtual",
"cloud"
]
}
15 changes: 15 additions & 0 deletions lib/custom_facts/util/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def self.external_facts_dirs
@external_facts_dirs
end

def self.facts_cache_dir
@facts_cache_dir
end

def self.setup_default_ext_facts_dirs
if LegacyFacter::Util::Root.root?
windows_dir = windows_data_dir
Expand Down Expand Up @@ -68,6 +72,17 @@ def self.override_binary_dir
@override_binary_dir
end

def self.setup_default_cache_dir
windows_dir = windows_data_dir
@facts_cache_dir = if windows_dir
File.join(windows_dir, 'PuppetLabs', 'facter', 'cache', 'cached_facts')
else
'/opt/puppetlabs/facter/cache/cached_facts'
end
end

setup_default_cache_dir

def self.setup_default_override_binary_dir
@override_binary_dir = if LegacyFacter::Util::Config.windows?
nil
Expand Down
6 changes: 6 additions & 0 deletions lib/framework/cli/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ def list_block_groups(*_args)
puts Facter::BlockList.instance.block_groups.to_yaml.lines[1..-1].join
end

desc '--list-cache-groups', 'List cache groups'
map ['--list-cache-groups'] => :list_cache_groups
def list_cache_groups(*_args)
puts Facter::CacheList.instance.cache_groups.to_yaml.lines[1..-1].join
end

def self.exit_on_failure?
true
end
Expand Down
4 changes: 2 additions & 2 deletions lib/framework/config/block_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class BlockList
attr_reader :block_groups, :block_list

def initialize(block_list_path = nil)
@block_groups_file_path = block_list_path || File.join(ROOT_DIR, 'block_groups.conf')
@block_groups_file_path = block_list_path || File.join(ROOT_DIR, 'fact_groups.conf')
load_block_groups
end

Expand All @@ -27,7 +27,7 @@ def blocked_facts
private

def load_block_groups
@block_groups = File.readable?(@block_groups_file_path) ? Hocon.load(@block_groups_file_path) : {}
@block_groups = Facter::GroupList.instance.groups
options = Options.instance
@block_list = ConfigReader.new(options[:config]).block_list || {}
end
Expand Down
50 changes: 50 additions & 0 deletions lib/framework/config/cache_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

module Facter
class CacheList
include Singleton

attr_reader :cache_groups, :groups_ttls

def initialize(block_list_path = nil)
@block_groups_file_path = block_list_path || File.join(ROOT_DIR, 'fact_groups.conf')
load_cache_groups
end

# Get the group name a fact is part of
def get_fact_group(fact_name)
@cache_groups.detect { |k, v| break k if Array(v).find { |f| fact_name =~ /^#{f}.*/ } }
end

# Get config ttls for a given group
def get_group_ttls(group_name)
return unless (ttls = @groups_ttls.find { |g| g[group_name] })

ttls_to_seconds(ttls[group_name])
end

private

def load_cache_groups
groups = Facter::GroupList.instance.groups
options = Options.instance
@groups_ttls = ConfigReader.new(options[:config]).ttls || {}
@cache_groups = groups.select { |g| @groups_ttls.find { |t| t[g] } }
end

def ttls_to_seconds(ttls)
duration, unit = ttls.split(' ', 2)
time = duration.to_i
case unit
when 'seconds'
return time
when 'minutes'
return time * 60
when 'hours'
return time * 60 * 60
when 'days'
return time * 60 * 60 * 24
end
end
end
end
14 changes: 14 additions & 0 deletions lib/framework/config/group_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Facter
class GroupList
include Singleton

attr_reader :groups

def initialize(group_list_path = nil)
@groups_file_path = group_list_path || File.join(ROOT_DIR, 'fact_groups.conf')
@groups ||= File.readable?(@groups_file_path) ? Hocon.load(@groups_file_path) : {}
end
end
end
Loading

0 comments on commit f831585

Please sign in to comment.