Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions methods/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@
});
```

###Search
[Search indicies](http://docs.opscode.com/api_chef_server_search.html#get)
```javascript
chef.getSearchIndices(function(err, indicies){
});
```

[Search node](http://docs.getchef.com/api_chef_server_search_index.html#GET)
```javascript
chef.search("node", 'chef_environment:prod', function(err, node){
});
```

[Search node](http://docs.getchef.com/api_chef_server_search_index.html#POST)
```javascript
chef.partialSearch("node", "chef_environment:prod", { name: 'name' }, function(err, cookbook){
});
```

###Data Bags
```javascript
chef.getDataBags(function(err, data_bags){
Expand Down
5 changes: 3 additions & 2 deletions methods/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ exports.methods = function(config){

// http://docs.opscode.com/api_chef_server_search_index.html#get
search: function(index, qs, fn){
http_methods.get([config.host_url, "search", index].join("/"), qs, function(err, response){
http_methods.get([config.host_url, "search", index].join("/"), {q: qs}, function(err, response){
return fn(err, response);
});
},

// http://docs.opscode.com/api_chef_server_search_index.html#post
partialSearch: function(index, qs, data, fn){
http_methods.post([config.host_url, "search", index].join("/"), qs, data, function(err, response){
http_methods.post([config.host_url, "search", index].join("/"), {q: qs}, data, function(err, response){
return fn(err, response);
});
}
}
}

21 changes: 21 additions & 0 deletions spec/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var ChefApi = require('../main.js'),
chef = new ChefApi(),
options = {
user_name: USER,
key_path: PATH/TO/KEY,
organization: ORGANISATION
},
assert = require('assert');

chef.config(options);

describe('search', function(){
it('should search for nodes with the role ubuntu', function(done){
chef.search('node', "role:ubuntu", function(err, nodes){
if(err) throw err;
console.log(nodes);
assert.ok(nodes);
done();
});
});
});