Skip to content

Latest commit

 

History

History
60 lines (38 loc) · 2.3 KB

README.md

File metadata and controls

60 lines (38 loc) · 2.3 KB

Chef Cookbooks Client (for Java)

This is a Java client that uses the REST API provided by the Chef cookbooks site described here:

http://docs.opscode.com/api_cookbooks_site.html

API

The API is defined as a set of interfaces. Agnostic of the implementation chosen, you can do the following:

Get a Cookbook's Information

The following examples show how to retrieve a cookbook's information. If the cookbook is found, then a Cookbook object is returned; otherwise, null is returned.

import com.github.jrh3k5.chef.client.CookbookClient;
import com.github.jrh3k5.chef.client.Cookbook;

[...]

final CookbookClient client = ...;
final Cookbook foundCookbook = client.getCookbook("name_of_cookbook");
assert foundCookbook != null;

final Cookbook missingCookbook = client.getCookbook("cookbook_not_found");
assert missingCookbook == null;

// When we're done, make sure we close the client to clean up any resources!
client.close();

Get Cookbook

Once you've retrieved a cookbook's information, you can actually download it through Cookbook.Version interface.

import com.github.jrh3k5.chef.client.Cookbook.Version;
import com.github.jrh3k5.chef.client.Cookbook;
import java.net.URL;

final Cookbook cookbook = ...;
// Get the latest version
final Cookbook.Version latestVersion = cookbook.getLatestVersion();
final URL latestTarballLocation = latestVersion.getFileLocation();

final Cookbook.Version v1Version = cookbook.getVersion("1.0.0");
assert v1Version != null;
final URL v1TarballLocation = v1Version.getFileLocation():

final Cookbook.Version notFoundVersion = cookbook.getVersion("not.found");
assert notFoundVersion == null;

// Do whatever you want now that you have the tarball location!

Jersey Implementation

The Jersey implementation uses Glassfish's Jersey 2.x implementation to interact with the REST API. The client can be created through the following means:

import com.github.jrh3k5.chef.client.jersey.JerseyCookbookClient;
import com.github.jrh3k5.chef.client.CookbookClient;

final CookbookClient defaultUrlClient = new JerseyCookbookClient();
final CookbookClient specifiedUrlClient = new JerseyCookbookClient("http://my.personal.chef.server/");