Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration options to filter facts out in puppetdb termini #3998

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions puppet/lib/puppet/indirector/facts/puppetdb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ def save(request)
package_inventory = inventory['packages'] if inventory.respond_to?(:keys)
facts.values.delete('_puppet_inventory_1')

fact_names_blocklist = Puppet::Util::Puppetdb.config.fact_names_blocklist

fact_names_blocklist.each{|blocklisted_fact_name|
facts.values.delete(blocklisted_fact_name)
}

fact_names_blocklist_regexps = Puppet::Util::Puppetdb.config.fact_names_blocklist_regex

fact_names_blocklist_regexps.each{|blocklisted_fact_name_regexp_str|
facts.values.reject!{|k,v| k =~ Regexp.new(blocklisted_fact_name_regexp_str)}
}

payload_value = {
"certname" => facts.name,
"values" => facts.values,
Expand Down
20 changes: 18 additions & 2 deletions puppet/lib/puppet/util/puppetdb/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def self.load(config_file = nil)
:submit_only_server_urls => "",
:command_broadcast => false,
:sticky_read_failover => false,
:verify_client_certificate => true
:verify_client_certificate => true,
:fact_names_blocklist => "",
:fact_names_blocklist_regex => ""
}

config_file ||= File.join(Puppet[:confdir], "puppetdb.conf")
Expand Down Expand Up @@ -71,7 +73,9 @@ def self.load(config_file = nil)
:submit_only_server_urls,
:command_broadcast,
:sticky_read_failover,
:verify_client_certificate].include?(k))
:verify_client_certificate,
:fact_names_blocklist,
:fact_names_blocklist_regex].include?(k))
end

parsed_urls = config_hash[:server_urls].split(",").map {|s| s.strip}
Expand Down Expand Up @@ -108,6 +112,10 @@ def self.load(config_file = nil)
"or equal to the number of server_urls (#{config_hash[:server_urls].length})"
end

config_hash[:fact_names_blocklist] = config_hash[:fact_names_blocklist].split(",").map {|s| s.strip}

config_hash[:fact_names_blocklist_regex] = config_hash[:fact_names_blocklist_regex].split(",").map {|s| s.strip}

self.new(config_hash)
rescue => detail
Puppet.log_exception detail, "Could not configure PuppetDB terminuses: #{detail.message}", {level: :warning}
Expand Down Expand Up @@ -160,6 +168,14 @@ def verify_client_certificate
config[:verify_client_certificate]
end

def fact_names_blocklist
config[:fact_names_blocklist]
end

def fact_names_blocklist_regex
config[:fact_names_blocklist_regex]
end

# @!group Private instance methods

# @!attribute [r] count
Expand Down