Categorygithub.com/go-chef/chef
modulepackage
0.30.1
Repository: https://github.com/go-chef/chef.git
Documentation: pkg.go.dev

# README

Stories in Ready Build Status Coverage Status

Chef Server API Client Library in Golang

This is a Library that you can use to write tools to interact with the chef server.

Install

go get github.com/go-chef/chef

Test

go get -t github.com/go-chef/chef
go test -v github.com/go-chef/chef
test_chef_server: kitchen verify  # integration tests

SSL

If you run into an SSL verification problem when trying to connect to a ssl server with self signed certs set up your config object with SkipSSL: true

Usage

This example is setting up a basic client that you can use to interact with all the service endpoints (clients, nodes, cookbooks, etc. At @chefapi) More usage examples can be found in the examples directory.

package main

import (
	"fmt"
	"os"
	"github.com/go-chef/chef"
)

func main() {
	// read a client key
	key, err := os.ReadFile("key.pem")
	if err != nil {
		fmt.Println("Couldn't read key.pem:", err)
		os.Exit(1)
	}

	// build a client
	client, err := chef.NewClient(&chef.Config{
		Name: "foo",
		Key:  string(key),
		// goiardi is on port 4545 by default. chef-zero is 8889
		BaseURL: "http://localhost:4545",
	})
	if err != nil {
		fmt.Println("Issue setting up client:", err)
	}

	// List Cookbooks
	cookList, err := client.Cookbooks.List()
	if err != nil {
		fmt.Println("Issue listing cookbooks:", err)
	}

	// Print out the list
	fmt.Println(cookList)
}

Chef API Error Status

To get the error status and error message returned from calls to the Chef API Server you can use ChefError to unwind the ErrorResponse and access the original http error. These methods are available to get specific information from the the error.

  • Error() returns a formatted error message with the URL and status code.
  • StatusCode() returns the original return status code.
  • StatusMsg() returns the error message extracted from the error message body.
  • StatusText() returns the returned error message body, usually JSON.
  • StatusMethod() returns the name of the method used for the request.
  • StatusURL() returns the URL object used for the request.

CONTRIBUTING

If you feel like contributing, great! Just fork the repo, make your improvements, and submit a pull request. Tests would, of course, be appreciated. Adding tests where there are no tests currently would be even more appreciated. At least, though, try and not break anything worse than it is. Test coverage has improved, but is still an ongoing concern.

AUTHORS

Jesse Nelson@spheromak
AJ Christensen@fujin
Brad Beam@bradbeam
Kraig Amador@bigkraig
Mark Gibbons@mark

COPYRIGHT

Copyright 2013-2014, Jesse Nelson

LICENSE

Like many Chef ecosystem programs, go-chef/chef is licensed under the Apache 2.0 License. See the LICENSE file for details.

Chef is copyright (c) 2008-2014 Chef, Inc. and its various contributors.

Thanks go out to the fine folks of Opscode and the Chef community for all their hard work.

# Packages

Test the go-chef/chef chef server api /users/USERNAME/keys endpoints against a live chef server.

# Functions

ACLAdminAccess Verify that pivotal is in the Users access list for each type of ACL access.
Base64BlockEncode takes a byte slice and breaks it up into a slice of base64 encoded strings.
CheckResponse receives a pointer to a http.Response and generates an Error via unmarshalling.
ChefError tries to unwind a chef client err return embedded in an error Unwinding allows easy access the StatusCode, StatusMethod and StatusURL functions.
GenerateDigestSignature will generate a signature of the given data protocol 1.3.
GenerateSignature will generate a signature ( sign ) the given data.
HashStr returns the base64 encoded SHA1 sum of the toHash string.
HashStr256 returns the base64 encoded SHA256 sum of the toHash string.
JSONReader handles arbitrary types and synthesizes a streaming encoder for them.
JSONSeeker handles arbitrary types and synthesizes a streaming encoder for them.
No description provided by the author
No description provided by the author
NewClient is the client generator used to instantiate a client for talking to a chef-server It is a simple constructor for the Client struct intended as a easy interface for issuing signed requests.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewNode is the Node constructor method.
NewRunListItem parses a single item from a run list and returns a structure.
PrivateKeyFromString parses an private key from a string.
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
DefaultChefVersion that we pretend to emulate.

# Variables

No description provided by the author
No description provided by the author

# Structs

No description provided by the author
ACLitems Newer versions of the Chef server split Actors into Users and Clients.
No description provided by the author
AddNow represents the body of the request to add a user to an organization POST /organization/NAME/users.
ApiClient represents the native Go version of the deserialized Client type.
ApiNewClientResult.
No description provided by the author
ApiNewClient structure to request a new client.
Association represents the response from creating an invitation to join an organization POST /organization/NAME/association_requests.
No description provided by the author
AuthConfig representing a client and a private key used for encryption This is embedded in the Client type.
Authenticate represents the body of the /authenticate_user request.
No description provided by the author
Body wraps io.Reader and adds methods for calculating hashes and detecting content.
No description provided by the author
CBADetail represents the detail for a specific cookbook_artifact.
CBAMeta represents the cookbook_artifacts metadata information.
CBAService is the service for interacting with chef server cookbook_artifacts endpoint.
No description provided by the author
No description provided by the author
Client is vessel for public methods used against the chef-server.
Config contains the configuration options for a chef client.
No description provided by the author
Container represents the native Go version of the deserialized Container type.
NewContainerResult.
No description provided by the author
Cookbook represents the native Go version of the deserialized api cookbook.
CookbookAccess represents the permissions on a Cookbook.
CookbookItem represents a object of cookbook file data.
No description provided by the author
CookbookMeta represents a Golang version of cookbook metadata.
CookbookService is the service for interacting with chef server cookbooks endpoint.
CookbookVersion is the data for a specific cookbook version.
CookbookVersions is the data container returned from the chef server when listing all cookbooks.
DataBag is a data bag.
No description provided by the author
DataBagService is the service for interacting with the chef server data endpoint.
Environment represents the native Go version of the deserialized Environment type.
Environment has a Reader, hey presto.
No description provided by the author
An ErrorResponse reports one or more errors caused by an API request.
Group represents the native Go version of the deserialized Group type.
No description provided by the author
No description provided by the author
GroupUpdate represents the payload needed to update a group.
IncludedPolicyLocks are the included policies locks.
Invite represents an entry in the array of responses listing the outstanding invitations GET /organization/NAME/association_requests.
JSearchResult will return a slice of json.RawMessage which can then be json.Unmarshaled to any of the chef-like objects (Role/Node/etc).
No description provided by the author
License represents the body of the returned information.
No description provided by the author
Node represents the native Go version of the deserialized Node type.
No description provided by the author
No description provided by the author
Organization represents the native Go version of the deserialized Organization type.
No description provided by the author
No description provided by the author
OrgUser represents the detailed information about a user in an organization GET /organization/NAME/user/NAME DELETE /organization/NAME/user/NAME.
Invite represents an entry in the array of responses listing the users in an organization GET /organization/NAME/association_requests.
No description provided by the author
No description provided by the author
PolicyGroupService is the service for interacting with chef server policies endpoint.
PolicyService is the service for interacting with chef server policies endpoint.
Principal represents the native Go version of the deserialized Principal type.
No description provided by the author
No description provided by the author
Request represents the body of the request to invite a user to an organization POST /organization/NAME/association_requests.
No description provided by the author
RescindInvite respresents the response from deleting an invitation DELETE /organization/NAME/association_requests/ID.
RevisionDetailsResponse is returned from the chef-server for Get Requests to /policies/<policy-name>/revisions/<rev-id>.
Role represents the native Go version of the deserialized Role type.
No description provided by the author
RunListItem external representation of a run list This module is a direct port of the Chef::RunList::RunListItem class see: https://github.com/chef/chef/blob/master/lib/chef/run_list/run_list_item.rb.
Sandbox Is the structure of an actual sandbox that has been created and returned by the final PUT to the sandbox ID.
A SandboxItem is embedded into the response from the chef-server and the actual sandbox is the Url and state for a specific Item.
SandboxPostResponse is the struct returned from the chef-server for Post Requests to /sandboxes.
SandboxRequest is the desired chef-api structure for a Post body.
SandboxService is the chef-client Sandbox service used as the entrypoint and caller for Sandbox methods.
No description provided by the author
SearchQuery Is the struct for holding a query request.
SearchResult.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Status represents the body of the returned information.
No description provided by the author
Universe represents the body of the returned information.
No description provided by the author
No description provided by the author
No description provided by the author
UpdatedSince represents the body of the returned information.
No description provided by the author
User represents the native Go version of the deserialized User type.
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

DataBagItem is a data bag item.

# Type aliases

ACL represents the native Go version of the deserialized ACL type The key string will be one of: create, delete, grant, read, update indicating the type of access granted to an accessor in the ACLitems lists.
ACLitem A list of a specific type of accessor.
ApiClientListResult is map of the client names to client Uri.
AuthVersion of server authentication.
CBAGetResponse is returned from the chef-server for Get Requests to /cookbook_artifacts.
ContainerListResult is map of the container names to container Uri.
CookbookListResult is the summary info returned by chef-api when listing http://docs.opscode.com/api_chef_server.html#cookbooks.
CookbookRecipesResult is the summary info returned by chef-api when listing http://docs.opscode.com/api_chef_server.html#cookbooks-recipes.
DataBagListResult is the list of data bags returned by chef-api when listing https://docs.chef.io/api_chef_server/#data.
No description provided by the author
No description provided by the author
No description provided by the author
EnvRunList represents the recipes and roles with environment specified for a node or as part of a role.
PolicyGetResponse is returned from the chef-server for Get Requests to /policies.
PolicyGetResponse is returned from chef-server for Get Requests to /policies/<policy-name>.
PolicyGroupGetResponse is returned from the chef-server for Get Requests to /policy_groups.
No description provided by the author
No description provided by the author
RequireRecipe the text of the required recipe.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
RunList represents the recipes and roles specified for a node or as part of a role.
Stats: represents the body of the returned information.