Skip to content

Commit 800a2dc

Browse files
committed
(SERVER-3050) Allow retrieving facts from any terminus
Previously, the v4 catalog endpoint would only fetch facts (as opposed to requiring them in the request) if the PuppetDB facts terminus was configured. This caused issues for people wanting to use extensions of the PDB terminus, like satellite, because the endpoint would error claiming that PDB wasn't configured. This commit removes the restriction on the fact retrieval logic. Now, if facts are not supplied in the request body, puppetserver will attempt to fetch them from whatever facts terminus is configured, whether that is yaml/json (default), PuppetDB, or some custom terminus. So long as the terminus implements `find`, this will succeed.
1 parent 079ff46 commit 800a2dc

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

spec/puppet-server-lib/puppet/jvm/compiler_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ def set_facts(fact_hash)
9393

9494
it 'requests facts from pdb after classifying and attempts to classify again' do
9595
allow(Puppet::Node::Facts.indirection.terminus).to receive(:name).and_return(:puppetdb)
96-
expect(compiler).to receive(:get_facts_from_pdb)
96+
expect(compiler).to receive(:get_facts_from_terminus)
9797
.with(certname, 'fancy')
9898
.ordered
9999
.and_return(Puppet::Node::Facts.new(certname))
100-
expect(compiler).to receive(:get_facts_from_pdb)
100+
expect(compiler).to receive(:get_facts_from_terminus)
101101
.with(certname, 'production')
102102
.ordered
103103
.and_return(Puppet::Node::Facts.new(certname))
@@ -114,7 +114,7 @@ def set_facts(fact_hash)
114114
end
115115

116116
allow(Puppet::Node::Facts.indirection.terminus).to receive(:name).and_return(:puppetdb)
117-
allow(compiler).to receive(:get_facts_from_pdb).and_return(Puppet::Node::Facts.new(certname))
117+
allow(compiler).to receive(:get_facts_from_terminus).and_return(Puppet::Node::Facts.new(certname))
118118

119119
expect(Puppet::Node.indirection).to receive(:find).and_return(
120120
Puppet::Node.new(certname, environment: 'production')

src/ruby/puppetserver-lib/puppet/server/compiler.rb

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def create_node(request_data)
5959
end
6060

6161
environment = node.environment
62-
facts = get_facts_from_pdb(certname, environment.to_s)
62+
facts = get_facts_from_terminus(certname, environment.to_s)
6363
node = Puppet.override(trusted_information: trusted_facts) do
6464
Puppet::Node.indirection.find(certname,
6565
environment: environment,
@@ -175,11 +175,9 @@ def process_facts(request_data)
175175

176176
def extract_facts(request_data)
177177
if request_data['facts'].nil?
178-
if Puppet::Node::Facts.indirection.terminus.name.to_s == "puppetdb"
179-
facts = get_facts_from_pdb(request_data['certname'], request_data['environment'])
180-
else
181-
raise(Puppet::Error, "PuppetDB not configured, please provide facts with your catalog request.")
182-
end
178+
Puppet.debug _("No facts submitted with request, retrieving from %{terminus_name}.") % { terminus_name: Puppet::Node::Facts.indirection.terminus.name.to_s }
179+
facts = get_facts_from_terminus(request_data['certname'],
180+
request_data['environment'])
183181
else
184182
facts_from_request = request_data['facts']
185183

@@ -209,16 +207,11 @@ def extract_trusted_facts(request_data, facts)
209207
trusted_facts ||= {}
210208
end
211209

212-
def get_facts_from_pdb(nodename, environment)
213-
pdb_terminus = Puppet::Node::Facts::Puppetdb.new
214-
request = Puppet::Indirector::Request.new(pdb_terminus.class.name,
215-
:find,
216-
nodename,
217-
nil,
218-
:environment => environment)
219-
facts = pdb_terminus.find(request)
210+
def get_facts_from_terminus(nodename, environment)
211+
facts = Puppet::Node::Facts.indirection.find(nodename,
212+
{environment: environment})
220213

221-
# If no facts have been stored for the node, PDB will return nil
214+
# If no facts have been stored for the node, the terminus will return nil
222215
if facts.nil?
223216
# Create an empty facts object
224217
facts = Puppet::Node::Facts.new(nodename)

0 commit comments

Comments
 (0)