Skip to content

Commit

Permalink
(PUP-7799) Allow searching for resources
Browse files Browse the repository at this point in the history
Searching for instances of a particular type in the request key or as an
indirector request option didn't work because the Puppet::Resource#to_resource
method was renamed. Update it to call the correct method.
  • Loading branch information
joshcooper committed Jun 11, 2021
1 parent 31e6d83 commit 445d1e7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/puppet/indirector/resource/ral.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ def search( request )
type(request).instances.map do |res|
res.to_resource
end.find_all do |res|
conditions.all? {|property, value| res.to_resource[property].to_s == value.to_s}
conditions.all? do |property, value|
# even though `res` is an instance of Puppet::Resource, calling
# `res[:name]` on it returns nil, and for some reason it is necessary
# to invoke the Puppet::Resource#copy_as_resource copy constructor...
res.copy_as_resource[property].to_s == value.to_s
end
end.sort_by(&:title)
end

Expand Down
2 changes: 0 additions & 2 deletions spec/unit/indirector/resource/ral_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@ def stub_retrieve(*instances)
end

it "should filter results by name if there's a name in the key" do
pending('to_resource')
allow(Puppet::Type.type(:user)).to receive(:instances).and_return([ my_instance, wrong_instance ])

actual = described_class.indirection.search('user/root')
expect(actual).to contain_exactly(an_object_having_attributes(name: 'User/root'))
end

it "should filter results by query parameters" do
pending('to_resource')
allow(Puppet::Type.type(:user)).to receive(:instances).and_return([ my_instance, wrong_instance ])

actual = described_class.indirection.search('user', name: 'bob')
Expand Down

0 comments on commit 445d1e7

Please sign in to comment.