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