From 40fce00118fcb82210c9966c37cb02d9a23153fd Mon Sep 17 00:00:00 2001 From: Chris Watts Date: Sun, 7 Dec 2014 19:20:44 -0800 Subject: [PATCH 1/3] Added a fix so that the search query string can be passed in as a string instead of an object --- methods/search.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/methods/search.js b/methods/search.js index d9eddb6..c8a5416 100644 --- a/methods/search.js +++ b/methods/search.js @@ -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); }); } } } + From c01ef37fe2fdacbf22f725f51cf93aaef897dba8 Mon Sep 17 00:00:00 2001 From: Chris Watts Date: Sun, 7 Dec 2014 19:27:44 -0800 Subject: [PATCH 2/3] Added documentation for search methods --- methods/README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/methods/README.md b/methods/README.md index 7492f5b..f31fe4c 100644 --- a/methods/README.md +++ b/methods/README.md @@ -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){ From a3343f0cab7ad95119f9b3e85b7011152cf57894 Mon Sep 17 00:00:00 2001 From: Chris Watts Date: Sun, 7 Dec 2014 19:30:52 -0800 Subject: [PATCH 3/3] Added tests for new search method --- spec/search.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 spec/search.js diff --git a/spec/search.js b/spec/search.js new file mode 100644 index 0000000..e3ba167 --- /dev/null +++ b/spec/search.js @@ -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(); + }); + }); +});