Skip to content

Instantly share code, notes, and snippets.

@redivy
Created March 2, 2010 14:46
Show Gist options
  • Save redivy/319550 to your computer and use it in GitHub Desktop.
Save redivy/319550 to your computer and use it in GitHub Desktop.
--- search.rb 2010-03-02 17:44:14.000000000 +0300
+++ /usr/lib64/ruby/gems/1.8/gems/chef-server-slice-0.7.16/app/controllers/search.rb 2010-03-03 12:51:27.000000000 +0300
@@ -35,6 +35,17 @@
@s = Chef::Search.new
query = params[:q].nil? ? "*" : (params[:q].empty? ? "*" : params[:q])
+ if session[:node_name] and session[:level] != :admin
+ node = Chef::Node.load(session[:node_name])
+ shared_key = '""'
+ begin
+ shared_key = "\"#{node.shared_key}\""
+ rescue
+ shared_key = '""'
+ end
+ query.gsub!(/(shared_key\:).+/, '\1' + shared_key)
+ query = ( query == "*" ) ? "shared_key:#{shared_key} AND id:*" : "shared_key:#{shared_key} AND #{query}"
+ end
attributes = params[:a].nil? ? [] : params[:a].split(",").collect { |a| a.to_sym }
@results = @s.search(params[:id], query, attributes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment