summaryrefslogtreecommitdiff
path: root/lib/chef/search/query.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/search/query.rb')
-rw-r--r--lib/chef/search/query.rb18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/chef/search/query.rb b/lib/chef/search/query.rb
index 7357dbf6be..7e70584f30 100644
--- a/lib/chef/search/query.rb
+++ b/lib/chef/search/query.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -63,6 +63,14 @@ class Chef
validate_type(type)
args_h = hashify_args(*args)
+ if args_h.key?(:fuzz)
+ if type == :node
+ query = fuzzify_node_query(query)
+ end
+ # FIXME: can i haz proper ruby-2.x named parameters someday plz?
+ args_h = args_h.reject { |k, v| k == :fuzz }
+ end
+
response = call_rest_service(type, query: query, **args_h)
if block
@@ -92,6 +100,14 @@ class Chef
private
+ def fuzzify_node_query(query)
+ if query !~ /:/
+ "tags:*#{query}* OR roles:*#{query}* OR fqdn:*#{query}* OR addresses:*#{query}* OR policy_name:*#{query}* OR policy_group:*#{query}*"
+ else
+ query
+ end
+ end
+
def validate_type(t)
unless t.kind_of?(String) || t.kind_of?(Symbol)
msg = "Invalid search object type #{t.inspect} (#{t.class}), must be a String or Symbol." +