Chef::REST::Client

REST api client for Chef

View the Project on GitHub github4bhavin/ChefRESTClient

Overview

An implementation of the basic chef REST client as described on opscode doc. The module takes care of creating Chef Hearders, creating base64 encoding and signing the request. It makes accessing the recipes , roles and other artifacts stored on the remote Chef server as easy as calling the native perl method.

Note

client private key generated by Chef Server should be placed under ../data as 'private_key' .(../data/private_key).

				
my $obj = new Chef::REST::Client ( 'chef_client_name' => $chef_client_name );
   $obj->name( $chef_client_name ); 
   $obj->roles('vagrant')->details; 
   $obj->roles('vagrant','environments')->details;
   $obj->roles->list;
   $obj->search( 'secrets' , {  q => 'id:centrify', rows => 1 } )->details;
   $obj->environments(,'cookbooks' , )->details; 
   $obj->environments(,
                      'cookbooks_versions',
                      { 'method' => 'post',
                        'data' => { 'runlist' => [ 'ms-scribe'] }
                      }
                     );
   $obj->roles()->details->override_attributes;
				
			

Methods

role( $role )

returns new Chef::REST::Client::role object . used by other classes.

	 $obj = new Chef::REST::Client(); 	

roles ( @roles )

fetches all the roles from the Chef Server and returns Chef::REST::Client::roles object. you can directly get details of all the roles by calling the details method.

	
				
$obj->role( 'role1' , 'role2' )->details;

# @endpoint : /roles

$obj->roles->list;

# @endpoint : /roles/

$obj->roles('role_name')->details;
$obj->roles('role_name')->details->run_list;
$obj->roles('role_name')->details->override_attributes;
				 
				
			

runlist( @recipes )

returns new Chef::REST::Client::runlist object . It takes a list of recipes as paramets, Used by other internal classes.

sandboxes

returns new Chef::REST::Client::sandboxes object

	
				
# @endpoint : /sandboxes

$obj->sandboxes->list

# @endpoint : /sandboxes/

$obj->sandboxes('id')->details;
 
				
			

search

returns new Chef::REST::Client::search object

	
				

# @endpoint : /search

$obj->search->listen

# @endpoint : /search/

$obj->search('index')->details

# @endpoint : /search/queryid : centrify and get row 1

$obj->search
      (  'secrets',
         { q   => 'id:centrify',
           row => 1
         }
      )
     ->details 
				
			

recipe

returns new Chef::REST::Client::recipe object. used by other internal classes.

principals

returns new Chef::REST::Client::principals object.

				

# @endpoint : /principals

$obj->principals->list

# @endpoint : /principals/

$obj->principals('name')->details
				
			

node

returns new Chef::REST::Client::node object. used by other internal classes.

nodes

returns new Chef::REST::Client::nodes object.

				

# @endpoint : /nodes

$obj->nodes->list

# @endpoint : /nodes/

$obj->nodes('name')->details
				
			

envrunlist

returns new Chef::REST::Client::envrunlist object. used by other internal classes.

environment

returns new Chef::REST::Client::environment object. used by other internal classes.

environments

returns new Chef::REST::Client::environments object. used by other internal classes.

				

# @endpoint : /environment/

$obj->environments('env_name')->details;

# @endpoint : /environment//cookboks/

$obj->environments('env_name', 'cookbooks' , 'coookbook_name')->details;

# @endpoint : /environment//cookbooks

$obj->environments('env_name','cookbooks');

# @endpoint  : /environments//cookbooks_versions 
# @method    : POST
# @operation : this will update the runlist for 'cookbook_versions' for 'env_name'

$obj->environment('env_name' , 'cookbooks_version' , 
                  { 'methos' => 'post',
                    'data'   => {
                                  'runlist' => ['scribe']
                                }
                  }
                 );

				
			

databag

returns new Chef::REST::Client::databag object. used by other internal classes.

data

returns new Chef::REST::Client::data object.

				

# @endpoint : /data

$obj->data->list;

# @endpoint : /data/

$obj->data('var_name' )->details;
 
				
			

cookbook

returns new Chef::REST::Client::cookbook object. used by other internal classes.

cookbooks

returns new Chef::REST::Client::cookbooks object.

				

# @endpoint : /cookbooks

$obj->cookbooks->list

# @endpoint : /cookbooks/

$obj->cookbooks('cookbook_name')->details;
$obj->cookbooks('cookbook_name', '_latest')->details->recipes;
$obj->cookbooks('cookbook_name','version')->details->attributes;

				
			

clients

returns new Chef::REST::Client::clients object.

				

# @endpoint : /clients

$obj->clients->list

# @endpoint : /clients/

$obj->clients('client_name')->details;

				
			

attribute

returns new Chef::REST::Client::attribute object.

attributes

returns new Chef::REST::Client::attributes object.

Authors and Support

Bhavin Patel (@github4bhavin).