Chef Cookbooks Client (for Java)

A client library for Java that reads data from the cookbooks API.

License

License

Categories

Categories

Java Languages CLI User Interface
GroupId

GroupId

com.github.jrh3k5
ArtifactId

ArtifactId

chef-cookbooks-client-java
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

Chef Cookbooks Client (for Java)
A client library for Java that reads data from the cookbooks API.
Source Code Management

Source Code Management

https://github.com/jrh3k5/chef-cookbooks-client-java

Download chef-cookbooks-client-java

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.jrh3k5/chef-cookbooks-client-java/ -->
<dependency>
    <groupId>com.github.jrh3k5</groupId>
    <artifactId>chef-cookbooks-client-java</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.jrh3k5/chef-cookbooks-client-java/
implementation 'com.github.jrh3k5:chef-cookbooks-client-java:1.0'
// https://jarcasting.com/artifacts/com.github.jrh3k5/chef-cookbooks-client-java/
implementation ("com.github.jrh3k5:chef-cookbooks-client-java:1.0")
'com.github.jrh3k5:chef-cookbooks-client-java:jar:1.0'
<dependency org="com.github.jrh3k5" name="chef-cookbooks-client-java" rev="1.0">
  <artifact name="chef-cookbooks-client-java" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.jrh3k5', module='chef-cookbooks-client-java', version='1.0')
)
libraryDependencies += "com.github.jrh3k5" % "chef-cookbooks-client-java" % "1.0"
[com.github.jrh3k5/chef-cookbooks-client-java "1.0"]

Dependencies

compile (6)

Group / Artifact Type Version
com.fasterxml.jackson.jaxrs : jackson-jaxrs-json-provider jar 2.1.4
commons-io : commons-io jar 2.4
commons-lang : commons-lang jar 2.6
javax.ws.rs : javax.ws.rs-api jar 2.0
org.glassfish.jersey.core : jersey-client jar 2.5
org.slf4j : slf4j-api jar 1.7.5

test (6)

Group / Artifact Type Version
junit : junit jar 4.11
org.easytesting : fest-assert jar 1.4
org.mockito : mockito-core jar 1.9.5
org.powermock : powermock-api-mockito jar 1.5.2
org.powermock : powermock-core jar 1.5.2
org.powermock : powermock-module-junit4 jar 1.5.2

Project Modules

There are no modules declared in this project.

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/");

Versions

Version
1.0