opentofu/vendor/github.com/go-chef/chef/client.go
Paul Hinze 6fe2703665 Vendor all dependencies w/ Godep
* Remove `make updatedeps` from Travis build. We'll follow up with more
   specific plans around dependency updating in subsequent PRs.
 * Update all `make` targets to set `GO15VENDOREXPERIMENT=1` and to
   filter out `/vendor/` from `./...` where appropriate.
 * Temporarily remove `vet` from the `make test` target until we can
   figure out how to get it to not vet `vendor/`. (Initial
   experimentation failed to yield the proper incantation.)

Everything is pinned to current master, with the exception of:

 * Azure/azure-sdk-for-go which is pinned before the breaking change today
 * aws/aws-sdk-go which is pinned to the most recent tag

The documentation still needs to be updated, which we can do in a follow
up PR. The goal here is to unblock release.
2016-01-29 15:08:48 -06:00

89 lines
2.4 KiB
Go

package chef
import "fmt"
type ApiClientService struct {
client *Client
}
// Client represents the native Go version of the deserialized Client type
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"`
}
type ApiNewClient struct {
Name string `json:"name"`
Admin bool `json:"admin"`
}
type ApiClientCreateResult struct {
Uri string `json:"uri,omitempty"`
PrivateKey string `json:"private_key,omitempty"`
}
type ApiClientListResult map[string]string
// String makes ApiClientListResult implement the string result
func (c ApiClientListResult) String() (out string) {
for k, v := range c {
out += fmt.Sprintf("%s => %s\n", k, v)
}
return out
}
// List lists the clients in the Chef server.
//
// Chef API docs: https://docs.chef.io/api_chef_server.html#id13
func (e *ApiClientService) List() (data ApiClientListResult, err error) {
err = e.client.magicRequestDecoder("GET", "clients", nil, &data)
return
}
// Get gets a client from the Chef server.
//
// Chef API docs: https://docs.chef.io/api_chef_server.html#id16
func (e *ApiClientService) Get(name string) (client ApiClient, err error) {
url := fmt.Sprintf("clients/%s", name)
err = e.client.magicRequestDecoder("GET", url, nil, &client)
return
}
// Create makes a Client on the chef server
//
// Chef API docs: https://docs.chef.io/api_chef_server.html#id14
func (e *ApiClientService) Create(clientName string, admin bool) (data *ApiClientCreateResult, err error) {
post := ApiNewClient{
Name: clientName,
Admin: admin,
}
body, err := JSONReader(post)
if err != nil {
return
}
err = e.client.magicRequestDecoder("POST", "clients", body, &data)
return
}
// Put updates a client on the Chef server.
//
// Chef API docs: https://docs.chef.io/api_chef_server.html#id17
// Delete removes a client on the Chef server
//
// Chef API docs: https://docs.chef.io/api_chef_server.html#id15
func (e *ApiClientService) Delete(name string) (err error) {
err = e.client.magicRequestDecoder("DELETE", "clients/"+name, nil, nil)
return
}