[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5
Luke Kanies
luke at puppetlabs.com
Tue May 10 08:08:39 UTC 2011
The following commit has been merged in the experimental branch:
commit 076de13a24163f485a5dea2469c4b958f73a7d1e
Author: Luke Kanies <luke at puppetlabs.com>
Date: Fri Mar 25 15:54:09 2011 -0700
(#6855) ResourceType#search now accepts a regex
We treat the regex relatively plainly, but this is
more reasonable than just '*'.
Signed-off-by: Luke Kanies <luke at puppetlabs.com>
Reviewed-by: Max Martin <max at puppetlabs.com>
diff --git a/lib/puppet/indirector/resource_type/parser.rb b/lib/puppet/indirector/resource_type/parser.rb
index fd5b393..4bcaf3f 100644
--- a/lib/puppet/indirector/resource_type/parser.rb
+++ b/lib/puppet/indirector/resource_type/parser.rb
@@ -21,12 +21,23 @@ class Puppet::Indirector::ResourceType::Parser < Puppet::Indirector::Code
end
def search(request)
- raise ArgumentError, "Only '*' is acceptable as a search request" unless request.key == "*"
krt = request.environment.known_resource_types
# Make sure we've got all of the types loaded.
krt.loader.import_all
result = [krt.hostclasses.values, krt.definitions.values, krt.nodes.values].flatten.reject { |t| t.name == "" }
return nil if result.empty?
+ return result if request.key == "*"
+
+ # Strip the regex of any wrapping slashes that might exist
+ key = request.key.sub(/^\//, '').sub(/\/$/, '')
+ begin
+ regex = Regexp.new(key)
+ rescue => detail
+ raise ArgumentError, "Invalid regex '#{request.key}': #{detail}"
+ end
+
+ result.reject! { |t| t.name.to_s !~ regex }
+ return nil if result.empty?
result
end
end
diff --git a/spec/unit/indirector/resource_type/parser_spec.rb b/spec/unit/indirector/resource_type/parser_spec.rb
index 27e6148..f86b319 100755
--- a/spec/unit/indirector/resource_type/parser_spec.rb
+++ b/spec/unit/indirector/resource_type/parser_spec.rb
@@ -67,8 +67,35 @@ describe Puppet::Indirector::ResourceType::Parser do
@terminus.search(@request)
end
- it "should fail if anyther other than '*' was provided as the search key" do
- @request.key = "foo*"
+ it "should return all results if '*' is provided as the search string" do
+ @request.key = "*"
+ type = @krt.add(Puppet::Resource::Type.new(:hostclass, "foo"))
+ node = @krt.add(Puppet::Resource::Type.new(:node, "bar"))
+ define = @krt.add(Puppet::Resource::Type.new(:definition, "baz"))
+
+ result = @terminus.search(@request)
+ result.should be_include(type)
+ result.should be_include(node)
+ result.should be_include(define)
+ end
+
+ it "should treat any search string not '*' as a regex" do
+ @request.key = "a"
+ foo = @krt.add(Puppet::Resource::Type.new(:hostclass, "foo"))
+ bar = @krt.add(Puppet::Resource::Type.new(:hostclass, "bar"))
+ baz = @krt.add(Puppet::Resource::Type.new(:hostclass, "baz"))
+
+ result = @terminus.search(@request)
+ result.should be_include(bar)
+ result.should be_include(baz)
+ result.should_not be_include(foo)
+ end
+
+ it "should fail if a provided search string is not '*' and is not a valid regex" do
+ @request.key = "*foo*"
+
+ # Add one instance so we don't just get an empty array"
+ @krt.add(Puppet::Resource::Type.new(:hostclass, "foo"))
lambda { @terminus.search(@request) }.should raise_error(ArgumentError)
end
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list