blob: 77ed0025743e611d96c3c73600acdb7a53a7aa4a [file] [log] [blame]
Jon Perritt0e28b112014-10-14 20:49:31 -05001package containers
2
3import (
4 "github.com/rackspace/gophercloud"
5 os "github.com/rackspace/gophercloud/openstack/objectstorage/v1/containers"
6 "github.com/rackspace/gophercloud/pagination"
7)
8
Jon Perritt457f8ca2014-10-15 00:28:23 -05009// ExtractInfo interprets a page of List results when full container info
10// is requested.
11func ExtractInfo(page pagination.Page) ([]os.Container, error) {
12 return os.ExtractInfo(page)
13}
14
15// ExtractNames interprets a page of List results when just the container
16// names are requested.
17func ExtractNames(page pagination.Page) ([]string, error) {
18 return os.ExtractNames(page)
19}
20
Jon Perritt0e28b112014-10-14 20:49:31 -050021// List is a function that retrieves containers associated with the account as
22// well as account metadata. It returns a pager which can be iterated with the
23// EachPage function.
Jon Perritt4fcbfaa2014-10-16 20:28:13 -050024func List(c *gophercloud.ServiceClient, opts os.ListOptsBuilder) pagination.Pager {
Jon Perritt0e28b112014-10-14 20:49:31 -050025 return os.List(c, opts)
26}
27
28// CreateOpts is a structure that holds parameters for creating a container.
29type CreateOpts struct {
30 Metadata map[string]string
31 ContainerRead string `h:"X-Container-Read"`
32 ContainerWrite string `h:"X-Container-Write"`
33 VersionsLocation string `h:"X-Versions-Location"`
34}
35
36// ToContainerCreateMap formats a CreateOpts into a map of headers.
37func (opts CreateOpts) ToContainerCreateMap() (map[string]string, error) {
38 h, err := gophercloud.BuildHeaders(opts)
39 if err != nil {
40 return nil, err
41 }
42 for k, v := range opts.Metadata {
43 h["X-Container-Meta-"+k] = v
44 }
45 return h, nil
46}
47
48// Create is a function that creates a new container.
49func Create(c *gophercloud.ServiceClient, containerName string, opts os.CreateOptsBuilder) os.CreateResult {
50 return os.Create(c, containerName, opts)
51}
52
53// Delete is a function that deletes a container.
54func Delete(c *gophercloud.ServiceClient, containerName string) os.DeleteResult {
55 return os.Delete(c, containerName)
56}
57
58// UpdateOpts is a structure that holds parameters for updating or creating a
59// container's metadata.
60type UpdateOpts struct {
61 Metadata map[string]string
62 ContainerRead string `h:"X-Container-Read"`
63 ContainerWrite string `h:"X-Container-Write"`
64 ContentType string `h:"Content-Type"`
65 DetectContentType bool `h:"X-Detect-Content-Type"`
66 RemoveVersionsLocation string `h:"X-Remove-Versions-Location"`
67 VersionsLocation string `h:"X-Versions-Location"`
68}
69
70// ToContainerUpdateMap formats a CreateOpts into a map of headers.
71func (opts UpdateOpts) ToContainerUpdateMap() (map[string]string, error) {
72 h, err := gophercloud.BuildHeaders(opts)
73 if err != nil {
74 return nil, err
75 }
76 for k, v := range opts.Metadata {
77 h["X-Container-Meta-"+k] = v
78 }
79 return h, nil
80}
81
82// Update is a function that creates, updates, or deletes a container's
83// metadata.
Jon Perritt4fcbfaa2014-10-16 20:28:13 -050084func Update(c *gophercloud.ServiceClient, containerName string, opts os.UpdateOptsBuilder) os.UpdateResult {
Jon Perritt0e28b112014-10-14 20:49:31 -050085 return os.Update(c, containerName, opts)
86}
87
88// Get is a function that retrieves the metadata of a container. To extract just
89// the custom metadata, pass the GetResult response to the ExtractMetadata
90// function.
91func Get(c *gophercloud.ServiceClient, containerName string) os.GetResult {
92 return os.Get(c, containerName)
93}