chef

package module
v0.3.1-0...-46ce22b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2019 License: Apache-2.0 Imports: 22 Imported by: 0

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

SSL

If you run into an SSL verification problem when trying to connect to a ssl server with self signed certs setup 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.) More usage examples can be found in the examples directory.

package main

import (
	"fmt"
	"io/ioutil"
	"os"

	"github.com/go-chef/chef"
)

func main() {
	// read a client key
	key, err := ioutil.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)
}

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

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.

Documentation

Overview

This is a chef server api client. This Library can be used to write tools to interact with the chef server.

The testing can be run with `go test`, and the client can be used as per normal via `go get github.com/go-chef/chef` Documentation can be found on GoDoc at http://godoc.org/github.com/go-chef/chef

This is example code generating a new node on the chef-server.

package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"log"
	"os"

	"github.com/go-chef/chef"
)

func main() {
	// read a client key
	key, err := ioutil.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)
		os.Exit(1)
	}

	// Create a Node object
	// TOOD: should have a constructor for this
	ranjib := chef.Node{
		Name:        "ranjib",
		Environment: "_default",
		ChefType:    "node",
		JsonClass:   "Chef::Node",
		RunList:     []string{"pwn"},
	}

	// Create
	_, err = client.Nodes.Post(ranjib)
	if err != nil {
		log.Fatal("Couldn't create node. ", err)
	}

	// List nodes
	nodeList, err := client.Nodes.List()
	if err != nil {
		log.Fatal("Couldn't list nodes: ", err)
	}

	// dump the node list in Json
	jsonData, err := json.MarshalIndent(nodeList, "", "\t")
	os.Stdout.Write(jsonData)
	os.Stdout.WriteString("\n")

	// dump the ranjib node we got from server in JSON!
	serverNode, _ := client.Nodes.Get("ranjib")
	if err != nil {
		log.Fatal("Couldn't get node: ", err)
	}
	jsonData, err = json.MarshalIndent(serverNode, "", "\t")
	os.Stdout.Write(jsonData)
	os.Stdout.WriteString("\n")

	// update node
	ranjib.RunList = append(ranjib.RunList, "recipe[works]")
	jsonData, err = json.MarshalIndent(ranjib, "", "\t")
	os.Stdout.Write(jsonData)
	os.Stdout.WriteString("\n")

	_, err = client.Nodes.Put(ranjib)
	if err != nil {
		log.Fatal("Couldn't update node: ", err)
	}

	// Delete node ignoring errors :)
	client.Nodes.Delete(ranjib.Name)

}

Index

Constants

View Source
const ChefVersion = "11.12.0"

ChefVersion that we pretend to emulate

Variables

This section is empty.

Functions

func Base64BlockEncode

func Base64BlockEncode(content []byte, limit int) []string

Base64BlockEncode takes a byte slice and breaks it up into a slice of base64 encoded strings

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse receives a pointer to a http.Response and generates an Error via unmarshalling

func GenerateSignature

func GenerateSignature(priv *rsa.PrivateKey, data string) (enc []byte, err error)

GenerateSignature will generate a signature ( sign ) the given data

func HashStr

func HashStr(toHash string) string

HashStr returns the base64 encoded SHA1 sum of the toHash string

func JSONReader

func JSONReader(v interface{}) (r io.Reader, err error)

JSONReader handles arbitrary types and synthesizes a streaming encoder for them.

func PrivateKeyFromString

func PrivateKeyFromString(key []byte) (*rsa.PrivateKey, error)

PrivateKeyFromString parses an RSA private key from a string

Types

type ACL

type ACL map[string]ACLitems

ACL represents the native Go version of the deserialized ACL type

func NewACL

func NewACL(acltype string, actors, groups ACLitem) (acl *ACL)

type ACLService

type ACLService struct {
	// contains filtered or unexported fields
}

func (*ACLService) Get

func (a *ACLService) Get(subkind string, name string) (acl ACL, err error)

Get gets an ACL from the Chef server.

Chef API docs: lol

func (*ACLService) Put

func (a *ACLService) Put(subkind, name string, acltype string, item *ACL) (err error)

Put updates an ACL on the Chef server.

Chef API docs: rofl

type ACLitem

type ACLitem []string

ACLitem

type ACLitems

type ACLitems struct {
	Groups ACLitem `json:"groups"`
	Actors ACLitem `json:"actors"`
}

ACLitems

type ApiClient

type ApiClient struct {
	Name        string `json:"name"`
	ClientName  string `json:"clientname"`
	OrgName     string `json:"orgname"`
	Admin       bool   `json:"admin"`
	Validator   bool   `json:"validator"`
	Certificate string `json:"certificate,omitempty"`
	PublicKey   string `json:"public_key,omitempty"`
	PrivateKey  string `json:"private_key,omitempty"`
	Uri         string `json:"uri,omitempty"`
	JsonClass   string `json:"json_class"`
	ChefType    string `json:"chef_type"`
}

Client represents the native Go version of the deserialized Client type

type ApiClientCreateResult

type ApiClientCreateResult struct {
	Uri        string `json:"uri,omitempty"`
	PrivateKey string `json:"private_key,omitempty"`
}

type ApiClientKey

type ApiClientKey struct {
	Name           string `json:"name"`
	PublicKey      string `json:"public_key"`
	ExpirationDate string `json:"expiration_date"`
}

type ApiClientKeyListResult

type ApiClientKeyListResult []ApiClientKeyListResultItem

type ApiClientKeyListResultItem

type ApiClientKeyListResultItem struct {
	Name    string `json:"name"`
	Expired bool   `json:"expired"`
}

type ApiClientListResult

type ApiClientListResult map[string]string

func (ApiClientListResult) String

func (c ApiClientListResult) String() (out string)

String makes ApiClientListResult implement the string result

type ApiClientService

type ApiClientService struct {
	// contains filtered or unexported fields
}

func (*ApiClientService) Create

func (e *ApiClientService) Create(clientName string, admin bool) (data *ApiClientCreateResult, err error)

Create makes a Client on the chef server

Chef API docs: https://docs.chef.io/api_chef_server.html#clients

func (*ApiClientService) Delete

func (e *ApiClientService) Delete(name string) (err error)

Delete removes a client on the Chef server

Chef API docs: https://docs.chef.io/api_chef_server.html#clients-name

func (*ApiClientService) Get

func (e *ApiClientService) Get(name string) (client ApiClient, err error)

Get gets a client from the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#clients-name

func (*ApiClientService) GetKey

func (e *ApiClientService) GetKey(clientName string, keyName string) (data *ApiClientKey, err error)

GetKey gets a client key from the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#clients-client-keys-key

func (*ApiClientService) List

func (e *ApiClientService) List() (data ApiClientListResult, err error)

List lists the clients in the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#clients

func (*ApiClientService) ListKeys

func (e *ApiClientService) ListKeys(clientName string) (data *ApiClientKeyListResult, err error)

ListKeys lists the keys associated with a client on the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#clients-client-keys

type ApiNewClient

type ApiNewClient struct {
	Name  string `json:"name"`
	Admin bool   `json:"admin"`
}

type AuthConfig

type AuthConfig struct {
	PrivateKey *rsa.PrivateKey
	ClientName string
}

AuthConfig representing a client and a private key used for encryption

This is embedded in the Client type

func (AuthConfig) SignRequest

func (ac AuthConfig) SignRequest(request *http.Request) error

SignRequest modifies headers of an http.Request

type Body

type Body struct {
	io.Reader
}

Body wraps io.Reader and adds methods for calculating hashes and detecting content

func (*Body) Buffer

func (body *Body) Buffer() *bytes.Buffer

Buffer creates a byte.Buffer copy from a io.Reader resets read on reader to 0,0

func (*Body) ContentType

func (body *Body) ContentType() string

ContentType returns the content-type string of Body as detected by http.DetectContentType()

func (*Body) Hash

func (body *Body) Hash() (h string)

Hash calculates the body content hash

type Client

type Client struct {
	Auth    *AuthConfig
	BaseURL *url.URL

	ACLs          *ACLService
	Clients       *ApiClientService
	Cookbooks     *CookbookService
	DataBags      *DataBagService
	Environments  *EnvironmentService
	Groups        *GroupService
	Nodes         *NodeService
	Organizations *OrganizationService
	Principals    *PrincipalService
	Roles         *RoleService
	Sandboxes     *SandboxService
	Search        *SearchService
	Users         *UserService
	// contains filtered or unexported fields
}

Client is vessel for public methods used against the chef-server

func NewClient

func NewClient(cfg *Config) (*Client, error)

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

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do is used either internally via our magic request shite or a user may use it

func (*Client) NewRequest

func (c *Client) NewRequest(method string, requestUrl string, body io.Reader) (*http.Request, error)

NewRequest returns a signed request suitable for the chef server

type Config

type Config struct {
	// This should be the user ID on the chef server
	Name string

	// This is the plain text private Key for the user
	Key string

	// BaseURL is the chef server URL used to connect to. If using orgs you should include your org in the url
	BaseURL string

	// When set to false (default) this will enable SSL Cert Verification. If you need to disable Cert Verification set to true
	SkipSSL bool

	// Time to wait in seconds before giving up on a request to the server
	Timeout int
}

Config contains the configuration options for a chef client. This is Used primarily in the NewClient() constructor in order to setup a proper client object

type Cookbook

type Cookbook struct {
	CookbookName string         `json:"cookbook_name"`
	Name         string         `json:"name"`
	Version      string         `json:"version,omitempty"`
	ChefType     string         `json:"chef_type,omitempty"`
	Frozen       bool           `json:"frozen?,omitempty"`
	JsonClass    string         `json:"json_class,omitempty"`
	Files        []CookbookItem `json:"files,omitempty"`
	Templates    []CookbookItem `json:"templates,omitempty"`
	Attributes   []CookbookItem `json:"attributes,omitempty"`
	Recipes      []CookbookItem `json:"recipes,omitempty"`
	Definitions  []CookbookItem `json:"definitions,omitempty"`
	Libraries    []CookbookItem `json:"libraries,omitempty"`
	Providers    []CookbookItem `json:"providers,omitempty"`
	Resources    []CookbookItem `json:"resources,omitempty"`
	RootFiles    []CookbookItem `json:"root_files,omitempty"`
	Metadata     CookbookMeta   `json:"metadata,omitempty"`
	Access       CookbookAccess `json:"access,omitempty"`
}

Cookbook represents the native Go version of the deserialized api cookbook

type CookbookAccess

type CookbookAccess struct {
	Read   bool `json:"read,omitempty"`
	Create bool `json:"create,omitempty"`
	Grant  bool `json:"grant,omitempty"`
	Update bool `json:"update,omitempty"`
	Delete bool `json:"delete,omitempty"`
}

CookbookAccess represents the permissions on a Cookbook

type CookbookItem

type CookbookItem struct {
	Url         string `json:"url,omitempty"`
	Path        string `json:"path,omitempty"`
	Name        string `json:"name,omitempty"`
	Checksum    string `json:"checksum,omitempty"`
	Specificity string `json:"specificity,omitempty"`
}

CookbookItem represents a object of cookbook file data

type CookbookListResult

type CookbookListResult map[string]CookbookVersions

CookbookListResult is the summary info returned by chef-api when listing http://docs.opscode.com/api_chef_server.html#cookbooks

func (CookbookListResult) String

func (c CookbookListResult) String() (out string)

String makes CookbookListResult implement the string result

type CookbookMeta

type CookbookMeta struct {
	Name            string                 `json:"name,omitempty"`
	Version         string                 `json:"version,omitempty"`
	Description     string                 `json:"description,omitempty"`
	LongDescription string                 `json:"long_description,omitempty"`
	Maintainer      string                 `json:"maintainer,omitempty"`
	MaintainerEmail string                 `json:"maintainer_email,omitempty"`
	License         string                 `json:"license,omitempty"`
	Platforms       map[string]string      `json:"platforms,omitempty"`
	Depends         map[string]string      `json:"dependencies,omitempty"`
	Reccomends      map[string]string      `json:"recommendations,omitempty"`
	Suggests        map[string]string      `json:"suggestions,omitempty"`
	Conflicts       map[string]string      `json:"conflicting,omitempty"`
	Provides        map[string]string      `json:"providing,omitempty"`
	Replaces        map[string]string      `json:"replacing,omitempty"`
	Attributes      map[string]interface{} `json:"attributes,omitempty"` // this has a format as well that could be typed, but blargh https://github.com/lob/chef/blob/master/cookbooks/apache2/metadata.json
	Groupings       map[string]interface{} `json:"groupings,omitempty"`  // never actually seen this used.. looks like it should be map[string]map[string]string, but not sure http://docs.opscode.com/essentials_cookbook_metadata.html
	Recipes         map[string]string      `json:"recipes,omitempty"`
}

CookbookMeta represents a Golang version of cookbook metadata

type CookbookRecipesResult

type CookbookRecipesResult []string

CookbookRecipesResult is the summary info returned by chef-api when listing http://docs.opscode.com/api_chef_server.html#cookbooks-recipes

type CookbookService

type CookbookService struct {
	// contains filtered or unexported fields
}

CookbookService is the service for interacting with chef server cookbooks endpoint

func (*CookbookService) Delete

func (c *CookbookService) Delete(name, version string) (err error)

DeleteVersion removes a version of a cook from a server

func (*CookbookService) DownloadCookbook

func (c *CookbookService) DownloadCookbook(name, version string) error

DownloadCookbook downloads a cookbook to the current directory on disk

func (*CookbookService) DownloadCookbookAt

func (c *CookbookService) DownloadCookbookAt(name, version, localDir string) error

DownloadCookbookAt downloads a cookbook to the specified local directory on disk

func (*CookbookService) Get

func (c *CookbookService) Get(name string) (data CookbookVersion, err error)

Get retruns a CookbookVersion for a specific cookbook

GET /cookbooks/name

func (*CookbookService) GetAvailableVersions

func (c *CookbookService) GetAvailableVersions(name, numVersions string) (data CookbookListResult, err error)

GetAvailable returns the versions of a coookbook available on a server

func (*CookbookService) GetVersion

func (c *CookbookService) GetVersion(name, version string) (data Cookbook, err error)

GetVersion fetches a specific version of a cookbooks data from the server api

GET /cookbook/foo/1.2.3
GET /cookbook/foo/_latest
Chef API docs: https://docs.chef.io/api_chef_server.html#cookbooks-name-version

func (*CookbookService) List

List returns a CookbookListResult with the latest versions of cookbooks available on the server

func (*CookbookService) ListAllRecipes

func (c *CookbookService) ListAllRecipes() (data CookbookRecipesResult, err error)

ListAllRecipes lists the names of all recipes in the most recent cookbook versions

Chef API docs: https://docs.chef.io/api_chef_server.html#cookbooks-recipes

func (*CookbookService) ListAvailableVersions

func (c *CookbookService) ListAvailableVersions(numVersions string) (data CookbookListResult, err error)

ListVersions lists the cookbooks available on the server limited to numVersions

Chef API docs: https://docs.chef.io/api_chef_server.html#cookbooks-name

type CookbookVersion

type CookbookVersion struct {
	Url     string `json:"url,omitempty"`
	Version string `json:"version,omitempty"`
}

CookbookVersion is the data for a specific cookbook version

type CookbookVersions

type CookbookVersions struct {
	Url      string            `json:"url,omitempty"`
	Versions []CookbookVersion `json:"versions,omitempty"`
}

CookbookVersions is the data container returned from the chef server when listing all cookbooks

type DataBag

type DataBag struct {
	Name      string `json:"name"`
	JsonClass string `json:"json_class"`
	ChefType  string `json:"chef_type"`
}

DataBag is a data bag

type DataBagCreateResult

type DataBagCreateResult struct {
	URI string `json:"uri"`
}

type DataBagItem

type DataBagItem interface{}

DataBagItem is a data bag item

type DataBagListResult

type DataBagListResult map[string]string

DataBagListResult is the list of data bags returned by chef-api when listing http://docs.getchef.com/api_chef_server.html#data

func (DataBagListResult) String

func (d DataBagListResult) String() (out string)

String makes DataBagListResult implement the string result

type DataBagService

type DataBagService struct {
	// contains filtered or unexported fields
}

DataBagService is the service for interacting with the chef server data endpoint

func (*DataBagService) Create

func (d *DataBagService) Create(databag *DataBag) (result *DataBagCreateResult, err error)

Create adds a data bag to the server

Chef API Docs: http://docs.getchef.com/api_chef_server.html#id19

func (*DataBagService) CreateItem

func (d *DataBagService) CreateItem(databagName string, databagItem DataBagItem) (err error)

CreateItem adds an item to a data bag

Chef API Docs: http://docs.getchef.com/api_chef_server.html#id21

func (*DataBagService) Delete

func (d *DataBagService) Delete(name string) (result *DataBag, err error)

Delete removes a data bag from the server

Chef API Docs: ????????????????

func (*DataBagService) DeleteItem

func (d *DataBagService) DeleteItem(databagName, databagItem string) (err error)

DeleteItem deletes an item from a data bag

Chef API Docs: http://docs.getchef.com/api_chef_server.html#id22

func (*DataBagService) GetItem

func (d *DataBagService) GetItem(databagName, databagItem string) (item DataBagItem, err error)

GetItem gets an item from a data bag

Chef API Docs: http://docs.getchef.com/api_chef_server.html#id23

func (*DataBagService) List

func (d *DataBagService) List() (data *DataBagListResult, err error)

List returns a list of databags on the server

Chef API Docs: http://docs.getchef.com/api_chef_server.html#id18

func (*DataBagService) ListItems

func (d *DataBagService) ListItems(name string) (data *DataBagListResult, err error)

ListItems gets a list of the items in a data bag.

Chef API Docs: http://docs.getchef.com/api_chef_server.html#id20

func (*DataBagService) UpdateItem

func (d *DataBagService) UpdateItem(databagName, databagItemId string, databagItem DataBagItem) (err error)

UpdateItem updates an item in a data bag

Chef API Docs: http://docs.getchef.com/api_chef_server.html#id24

type Environment

type Environment struct {
	Name               string            `json:"name"`
	Description        string            `json:"description"`
	ChefType           string            `json:"chef_type"`
	Attributes         interface{}       `json:"attributes,omitempty"`
	DefaultAttributes  interface{}       `json:"default_attributes,omitempty"`
	OverrideAttributes interface{}       `json:"override_attributes,omitempty"`
	JsonClass          string            `json:"json_class,omitempty"`
	CookbookVersions   map[string]string `json:"cookbook_versions"`
}

Environment represents the native Go version of the deserialized Environment type

type EnvironmentCookbookResult

type EnvironmentCookbookResult map[string]CookbookVersions

type EnvironmentResult

type EnvironmentResult map[string]string

func (EnvironmentResult) String

func (e EnvironmentResult) String() (out string)

String makes EnvironmentResult implement the string result

type EnvironmentService

type EnvironmentService struct {
	// contains filtered or unexported fields
}

Environment has a Reader, hey presto

func (*EnvironmentService) Create

func (e *EnvironmentService) Create(environment *Environment) (data *EnvironmentResult, err error)

Create an environment in the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#environments

func (*EnvironmentService) Get

func (e *EnvironmentService) Get(name string) (data *Environment, err error)

Get gets an environment from the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#environments-name

func (*EnvironmentService) List

func (e *EnvironmentService) List() (data *EnvironmentResult, err error)

List lists the environments in the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#environments

func (*EnvironmentService) ListCookbooks

func (e *EnvironmentService) ListCookbooks(name string, numVersions string) (data EnvironmentCookbookResult, err error)

Get the versions of a cookbook for this environment from the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#environments-name-cookbooks

func (*EnvironmentService) Put

func (e *EnvironmentService) Put(environment *Environment) (data *Environment, err error)

Write an environment to the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#environments-name

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response // HTTP response that caused this error
}

An ErrorResponse reports one or more errors caused by an API request. Thanks to https://github.com/google/go-github

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Group

type Group struct {
	Name      string   `json:"name"`
	GroupName string   `json:"groupname"`
	OrgName   string   `json:"orgname"`
	Actors    []string `json:"actors"`
	Clients   []string `json:"clients"`
	Groups    []string `json:"groups"`
	Users     []string `json:"users"`
}

Group represents the native Go version of the deserialized Group type

type GroupResult

type GroupResult struct {
	Uri string `json:"uri"`
}

type GroupService

type GroupService struct {
	// contains filtered or unexported fields
}

func (*GroupService) Create

func (e *GroupService) Create(group Group) (data *GroupResult, err error)

Creates a Group on the chef server

Chef API docs: https://docs.chef.io/api_chef_server.html#groups

func (*GroupService) Delete

func (e *GroupService) Delete(name string) (err error)

Delete removes a group on the Chef server

Chef API docs: https://docs.chef.io/api_chef_server.html#groups

func (*GroupService) Get

func (e *GroupService) Get(name string) (group Group, err error)

Get gets a group from the Chef server.

Chef API docs: http://docs.opscode.com/api_chef_server.html#id28

func (*GroupService) List

func (e *GroupService) List() (grouplist map[string]string, err error)

List lists the groups in the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#groups

func (*GroupService) Update

func (e *GroupService) Update(g Group) (group Group, err error)

Update a group on the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#groups

type Node

type Node struct {
	Name                string                 `json:"name"`
	Environment         string                 `json:"chef_environment,omitempty"`
	ChefType            string                 `json:"chef_type,omitempty"`
	AutomaticAttributes map[string]interface{} `json:"automatic,omitempty"`
	NormalAttributes    map[string]interface{} `json:"normal,omitempty"`
	DefaultAttributes   map[string]interface{} `json:"default,omitempty"`
	OverrideAttributes  map[string]interface{} `json:"override,omitempty"`
	JsonClass           string                 `json:"json_class,omitempty"`
	RunList             []string               `json:"run_list,omitempty"`
	PolicyName          string                 `json:"policy_name,omitempty"`
	PolicyGroup         string                 `json:"policy_group,omitempty"`
}

Node represents the native Go version of the deserialized Node type

func NewNode

func NewNode(name string) (node Node)

NewNode is the Node constructor method

type NodeResult

type NodeResult struct {
	Uri string `json:"uri"`
}

type NodeService

type NodeService struct {
	// contains filtered or unexported fields
}

func (*NodeService) Delete

func (e *NodeService) Delete(name string) (err error)

Delete removes a node on the Chef server

Chef API docs: https://docs.chef.io/api_chef_server.html#nodes-name

func (*NodeService) Get

func (e *NodeService) Get(name string) (node Node, err error)

Get gets a node from the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#nodes-name

func (*NodeService) List

func (e *NodeService) List() (data map[string]string, err error)

List lists the nodes in the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#nodes

func (*NodeService) Post

func (e *NodeService) Post(node Node) (data *NodeResult, err error)

Post creates a Node on the chef server

Chef API docs: https://docs.chef.io/api_chef_server.html#nodes

func (*NodeService) Put

func (e *NodeService) Put(n Node) (node Node, err error)

Put updates a node on the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#nodes-name

type Organization

type Organization struct {
	Name     string `json:"name"`
	FullName string `json:"full_name"`
	Guid     string `json:"guid"`
}

Organization represents the native Go version of the deserialized Organization type

type OrganizationResult

type OrganizationResult struct {
	ClientName string `json:"clientname"`
	PrivateKey string `json:"private_key"`
	Uri        string `json:"uri"`
}

type OrganizationService

type OrganizationService struct {
	// contains filtered or unexported fields
}

func (*OrganizationService) Create

func (e *OrganizationService) Create(organization Organization) (data OrganizationResult, err error)

Creates an Organization on the chef server

Chef API docs: https://docs.chef.io/api_chef_server.html#organizations

func (*OrganizationService) Delete

func (e *OrganizationService) Delete(name string) (err error)

Delete removes an organization on the Chef server

Chef API docs: https://docs.chef.io/api_chef_server.html#organizations

func (*OrganizationService) Get

func (e *OrganizationService) Get(name string) (organization Organization, err error)

Get gets an organization from the Chef server.

Chef API docs: http://docs.opscode.com/api_chef_server.html#id28

func (*OrganizationService) List

func (e *OrganizationService) List() (organizationlist map[string]string, err error)

List lists the organizations in the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#organizations

func (*OrganizationService) Update

func (e *OrganizationService) Update(g Organization) (organization Organization, err error)

Update an organization on the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#organizations

type Principal

type Principal struct {
	Name      string `json:"name"`
	Type      string `json:"type"`
	PublicKey string `json:"public_key"`
	AuthzId   string `json:"authz_id"`
	OrgMember bool   `json:"org_member"`
}

Principal represents the native Go version of the deserialized Principal type

func NewPrincipal

func NewPrincipal(name, typ, publicKey string) Principal

type PrincipalService

type PrincipalService struct {
	// contains filtered or unexported fields
}

func (*PrincipalService) Get

func (e *PrincipalService) Get(name string) (principal Principal, err error)

Get gets a principal from the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#principals-name

type Role

type Role struct {
	Name               string      `json:"name"`
	ChefType           string      `json:"chef_type"`
	Description        string      `json:"description"`
	RunList            RunList     `json:"run_list"`
	DefaultAttributes  interface{} `json:"default_attributes,omitempty"`
	OverrideAttributes interface{} `json:"override_attributes,omitempty"`
	JsonClass          string      `json:"json_class,omitempty"`
}

Role represents the native Go version of the deserialized Role type

type RoleCreateResult

type RoleCreateResult map[string]string

func (RoleCreateResult) String

func (e RoleCreateResult) String() (out string)

String makes RoleCreateResult implement the string result

type RoleListResult

type RoleListResult map[string]string

func (RoleListResult) String

func (e RoleListResult) String() (out string)

String makes RoleListResult implement the string result

type RoleService

type RoleService struct {
	// contains filtered or unexported fields
}

func (*RoleService) Create

func (e *RoleService) Create(role *Role) (data *RoleCreateResult, err error)

Create a new role in the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#roles

func (*RoleService) Delete

func (e *RoleService) Delete(name string) (err error)

Delete a role from the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#roles-name

func (*RoleService) Get

func (e *RoleService) Get(name string) (data *Role, err error)

Get gets a role from the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#roles-name

func (*RoleService) List

func (e *RoleService) List() (data *RoleListResult, err error)

List lists the roles in the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#roles

func (*RoleService) Put

func (e *RoleService) Put(role *Role) (data *Role, err error)

Update a role in the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#roles-name

type RunList

type RunList []string

RunList represents the recipes and roles specified for a node or as part of a role.

type Sandbox

type Sandbox struct {
	ID           string    `json:"guid"`
	Name         string    `json:"name"`
	CreationTime time.Time `json:"create_time"`
	Completed    bool      `json:"is_completed"`
	Checksums    []string
}

Sandbox Is the structure of an actul sandbox that has been created and returned by the final PUT to the sandbox ID

type SandboxItem

type SandboxItem struct {
	Url    string `json:"url"`
	Upload bool   `json:"needs_upload"`
}

A SandbooxItem is embeddedinto the response from the chef-server and the actual sandbox It is the Url and state for a specific Item.

type SandboxPostResponse

type SandboxPostResponse struct {
	ID        string `json:"sandbox_id"`
	Uri       string `json:"uri"`
	Checksums map[string]SandboxItem
}

SandboxPostResponse is the struct returned from the chef-server for Post Requests to /sandbox

type SandboxRequest

type SandboxRequest struct {
	Checksums map[string]interface{} `json:"checksums"`
}

SandboxRequest is the desired chef-api structure for a Post body

type SandboxService

type SandboxService struct {
	// contains filtered or unexported fields
}

SandboxService is the chef-client Sandbox service used as the entrypoint and caller for Sandbox methods

func (SandboxService) Post

func (s SandboxService) Post(sums []string) (data SandboxPostResponse, err error)

Post creates a new sandbox on the chef-server. Deviates from the Chef-server api in that it takes a []string of sums for the sandbox instead of the IMO rediculous hash of nulls that the API wants. We convert it to the right structure under the hood for the chef-server api. http://docs.getchef.com/api_chef_server.html#id38

func (SandboxService) Put

func (s SandboxService) Put(id string) (box Sandbox, err error)

Put is used to commit a sandbox ID to the chef server. To singal that the sandox you have Posted is now uploaded.

type SearchQuery

type SearchQuery struct {
	// The index you want to search
	Index string

	// The query you want to execute. This is the 'chef' query ex: 'chef_environment:prod'
	Query string

	// Sort order you want the search results returned
	SortBy string

	// Starting position for search
	Start int

	// Number of rows to return
	Rows int
}

SearchQuery Is the struct for holding a query request

func (SearchQuery) Do

func (q SearchQuery) Do(client *Client) (res SearchResult, err error)

Do will execute the search query on the client

func (SearchQuery) DoPartial

func (q SearchQuery) DoPartial(client *Client, params map[string]interface{}) (res SearchResult, err error)

DoPartial will execute the search query on the client with partal mapping

func (SearchQuery) String

func (q SearchQuery) String() string

String implements the Stringer Interface for the SearchQuery

type SearchResult

type SearchResult struct {
	Total int
	Start int
	Rows  []interface{}
}

SearchResult will return a slice of interface{} of chef-like objects (roles/nodes/etc)

type SearchService

type SearchService struct {
	// contains filtered or unexported fields
}

func (SearchService) Exec

func (e SearchService) Exec(idx, statement string) (res SearchResult, err error)

Exec runs the query on the index passed in. This is a helper method. If you want more controll over the query use NewQuery and its Do() method. BUG(spheromak): Should we use exec or SearchQuery.Do() or have both ?

func (SearchService) Indexes

func (e SearchService) Indexes() (data map[string]string, err error)

List lists the nodes in the Chef server.

Chef API docs: http://docs.opscode.com/api_chef_server.html#id25

func (SearchService) NewQuery

func (e SearchService) NewQuery(idx, statement string) (query SearchQuery, err error)

NewSearch is a constructor for a SearchQuery struct. This is used by other search service methods to perform search requests on the server

func (SearchService) PartialExec

func (e SearchService) PartialExec(idx, statement string, params map[string]interface{}) (res SearchResult, err error)

PartialExec Executes a partial search based on passed in params and the query.

type User

type User struct {
	UserName                      string `json:"username,omitempty"` // V1 name instead of name for V0
	DisplayName                   string `json:"display_name,omitempty"`
	Email                         string `json:"email,omitempty"`
	ExternalAuthenticationUid     string `json:"external_authentication_uid,omitempty"` // this or password
	FirstName                     string `json:"first_name,omitempty"`
	FullName                      string `json:"full_name,omitempty"`
	LastName                      string `json:"last_name,omitempty"`
	MiddleName                    string `json:"middle_name,omitempty"`
	Password                      string `json:"password,omitempty"`   // Valid password
	PublicKey                     string `json:"public_key,omitempty"` // not for Create
	RecoveryAuthenticationEnabled bool   `json:"recovery_authentication_enabled,omitempty"`
}

User represents the native Go version of the deserialized User type

type UserKey

type UserKey struct {
	KeyName        string `json:"name,omitempty"`
	PublicKey      string `json:"public_key,omitempty"`
	ExpirationDate string `json:"expiration_date,omitempty"`
}

type UserKeyResult

type UserKeyResult struct {
	KeyName string `json:"name,omitempty"`
	Uri     string `json:"uri,omitempty"`
	Expired string `json:"expired,omitempty"`
}

type UserResult

type UserResult struct {
	Uri        string `json:"uri,omitempty"`
	PrivateKey string `json:"private_key,omitempty"`
}

type UserService

type UserService struct {
	// contains filtered or unexported fields
}

func (*UserService) Create

func (e *UserService) Create(user User) (data UserResult, err error)

/users POST Creates a User on the chef server

201 =  sucesss
400 - invalid  (missing display_name, email,( password or external) among other things)
      username must be lower case without spaces
403 - unauthorized
409 - already exists

Chef API docs: https://docs.chef.io/api_chef_server.html#users

func (*UserService) Delete

func (e *UserService) Delete(name string) (err error)

Delete removes a user on the Chef server /users/USERNAME DELETE

200 - deleted
401 - not authenticated
403 - not authorized
404 - not found

Chef API docs: https://docs.chef.io/api_chef_server.html#users-name

func (*UserService) Get

func (e *UserService) Get(name string) (user User, err error)

Get gets a user from the Chef server. /users/USERNAME GET 200 - got it 401 - not authenticated 403 - not authorizated 404 - user doesn't exist

Chef API docs: https://docs.chef.io/api_chef_server.html#users-name

func (*UserService) List

func (e *UserService) List(filters ...string) (userlist map[string]string, err error)

/users GET List lists the users in the Chef server.

Chef API docs: https://docs.chef.io/api_chef_server.html#users

Notes

Bugs

  • tightly coupled

  • This is now both a *response* decoder and handles upload.. gettin smelly

  • Should we use exec or SearchQuery.Do() or have both ?

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL