-
Notifications
You must be signed in to change notification settings - Fork 36
/
chef-api.js
34 lines (30 loc) · 1.14 KB
/
chef-api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// import dependencies
var fs = require("fs");
var _ = require("lodash");
var methodsFiles = fs.readdirSync([__dirname, "methods"].join("/"));
exports.getObject = function(){
var object = {};
object.options = {};
object.config = function(options){
object.options.name = options.user_name || options.client_name,
object.options.key_contents = options.key || fs.readFileSync(options.key_path),
object.options.host_url = options.url || ["https://api.opscode.com/organizations", options.organization].join("/")
if(options.hasOwnProperty("timeout")) {
object.options.timeout = options.timeout;
}
if(options.hasOwnProperty("ca")) {
// absent means default,
// null means unsafe,
// specific means specific
object.options.ca = options.ca;
}
}
_.each(methodsFiles, function(file){
if(/\.js$/.test(file)){
_.each(require([__dirname, "methods", file].join("/")).methods(object.options), function(method, method_name){
object[method_name] = method;
});
}
});
return object;
}