edelight/chef-solo-search — Issue #6: Move search() override to Chef::Mixin::Language so it can be used from resource providers
Author: TylerRick
Created: 2012-02-23 04:08:10+00:00
State: open

When I tried to use the latest version of the users recipe (1.0.4, currently only in github), I was getting this error:

INFO: Processing users_manage[sysadmin] action remove (users::sysadmins line 23)
WARN: Failed to read the private key /etc/chef/client.pem: #
ERROR: users_manage[sysadmin] (users::sysadmins line 23) has had an error
ERROR: users_manage[sysadmin] (/etc/chef/cookbooks/users/recipes/sysadmins.rb:23:in `from_file') had an error:
users_manage[sysadmin] (users::sysadmins line 23) had an error: Chef::Exceptions::PrivateKeyMissing: I cannot read /etc/chef/client.pem, which you told me to use to sign requests!
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/rest/auth_credentials.rb:62:in `load_signing_key'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/rest/auth_credentials.rb:33:in `initialize'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/rest.rb:47:in `new'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/rest.rb:47:in `initialize'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/search/query.rb:34:in `new'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/search/query.rb:34:in `initialize'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/mixin/language.rb:133:in `new'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/mixin/language.rb:133:in `search'
/etc/chef/cookbooks/users/providers/manage.rb:27:in `class_from_file'

because it wasn't using the overridden search() method provided by chef-solo-search.

The reason it was working before (with users 1.0.0) was because in that version the call to search() happened in a recipe, so the overridden Chef::Recipe#search was being called in that version.

As of users 1.0.4, however, the call to search happened in a resource provider (https://github.com/opscode/cookbooks/blob/master/users/providers/manage.rb) and not in a recipe.

Please refer to my fork, https://github.com/TylerRick/chef-solo-search, for a patch...

```
commit 6c752879d6f4de940792d6699f1cbc9eb5f6bf9b
Author: Tyler Rick
Date: Wed Feb 22 19:48:07 2012 -0800

Override search() method in Chef::Mixin::Language instead of
Chef::Recipe so that this override will also be used when search() is
called from a resource provider and not a recipe.

This is necessary, for example, for the "users_manage" Lightweight
Resource Provider at https://github.com/opscode/cookbooks/blob/master/users/providers/manage.rb
to work.
```

I would send a pull request but it will only let me have one pull request open at a time and I already have one open :)