github.com/go-chef/chef@v0.30.1/container.go (about)

     1  package chef
     2  
     3  import "fmt"
     4  
     5  type ContainerService struct {
     6  	client *Client
     7  }
     8  
     9  // Container represents the native Go version of the deserialized Container type
    10  type Container struct {
    11  	ContainerName string `json:"containername"`
    12  	ContainerPath string `json:"containerpath"`
    13  }
    14  
    15  // NewContainerResult
    16  type ContainerCreateResult struct {
    17  	Uri string `json:"uri,omitempty"`
    18  }
    19  
    20  // ContainerListResult is map of the container names to container Uri
    21  type ContainerListResult map[string]string
    22  
    23  // String makes ContainerListResult implement the string result
    24  func (c ContainerListResult) String() (out string) {
    25  	for k, v := range c {
    26  		out += fmt.Sprintf("%s => %s\n", k, v)
    27  	}
    28  	return out
    29  }
    30  
    31  // List lists the containers in the Chef server.
    32  //
    33  // Chef API docs: https://docs.chef.io/api_chef_server/containers
    34  func (e *ContainerService) List() (data ContainerListResult, err error) {
    35  	err = e.client.magicRequestDecoder("GET", "containers", nil, &data)
    36  	return
    37  }
    38  
    39  // Create makes a Container on the chef server
    40  //
    41  // Chef API docs: https://docs.chef.io/api_chef_server.html#containers
    42  func (e *ContainerService) Create(container Container) (data *ContainerCreateResult, err error) {
    43  	body, err := JSONReader(container)
    44  	if err != nil {
    45  		return
    46  	}
    47  	err = e.client.magicRequestDecoder("POST", "containers", body, &data)
    48  	return
    49  }
    50  
    51  // Delete removes a containers on the Chef server
    52  //
    53  // Chef API docs: https://docs.chef.io/api_chef_server.html#container
    54  func (e *ContainerService) Delete(name string) (err error) {
    55  	url := fmt.Sprintf("containers/%s", name)
    56  	err = e.client.magicRequestDecoder("DELETE", url, nil, nil)
    57  	return
    58  }
    59  
    60  // Get gets a container from the Chef server.
    61  //
    62  // Chef API docs: https://docs.chef.io/api_chef_server.html#containers
    63  func (e *ContainerService) Get(name string) (container Container, err error) {
    64  	url := fmt.Sprintf("containers/%s", name)
    65  	err = e.client.magicRequestDecoder("GET", url, nil, &container)
    66  	return
    67  }