diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2017-03-30 14:40:02 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2017-03-31 13:03:08 -0700 |
commit | 5fb94bf7bd7d22fd3a1cff22f5861b0fbf32adb1 (patch) | |
tree | 2af84f37a5de0fff1f167f01bdb068274fe6b153 /lib/chef/search | |
parent | ac21083e7480c90a79cad36f05da973bc681f110 (diff) | |
download | chef-5fb94bf7bd7d22fd3a1cff22f5861b0fbf32adb1.tar.gz |
apply knife search node fuzzifier to knife ssh
extracts out a common 'fuzz' option to Chef::Search::Query so that anyone can
use it.
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/search')
-rw-r--r-- | lib/chef/search/query.rb | 18 |
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." + |