blob: 40c4ed1974cceb2f191b130e2b9c1e50616fe449 [file] [log] [blame]
Jon Perrittb5c78122014-10-15 20:44:39 -05001package cdncontainers
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
9// ExtractNames interprets a page of List results when just the container
10// names are requested.
11func ExtractNames(page pagination.Page) ([]string, error) {
12 return os.ExtractNames(page)
13}
14
15// ListOpts are options for listing Rackspace CDN containers.
16type ListOpts struct {
17 EndMarker string `q:"end_marker"`
18 Format string `q:"format"`
19 Limit int `q:"limit"`
20 Marker string `q:"marker"`
21}
22
23// ToContainerListParams formats a ListOpts into a query string and boolean
24// representing whether to list complete information for each container.
25func (opts ListOpts) ToContainerListParams() (bool, string, error) {
26 q, err := gophercloud.BuildQueryString(opts)
27 if err != nil {
28 return false, "", err
29 }
30 return false, q.String(), nil
31}
32
33// List is a function that retrieves containers associated with the account as
34// well as account metadata. It returns a pager which can be iterated with the
35// EachPage function.
36func List(c *gophercloud.ServiceClient, opts *ListOpts) pagination.Pager {
37 return os.List(c, opts)
38}
39
40// Get is a function that retrieves the metadata of a container. To extract just
41// the custom metadata, pass the GetResult response to the ExtractMetadata
42// function.
43func Get(c *gophercloud.ServiceClient, containerName string) os.GetResult {
44 return os.Get(c, containerName)
45}
46
47// UpdateOpts is a structure that holds parameters for updating, creating, or
48// deleting a container's metadata.
49type UpdateOpts struct {
50 CDNEnabled bool `h:"X-Cdn-Enabled"`
51 LogRetention bool `h:"X-Log-Retention"`
52 TTL int `h:"X-Ttl"`
53}
54
55// ToContainerUpdateMap formats a CreateOpts into a map of headers.
56func (opts UpdateOpts) ToContainerUpdateMap() (map[string]string, error) {
57 h, err := gophercloud.BuildHeaders(opts)
58 if err != nil {
59 return nil, err
60 }
61
62 return h, nil
63}
64
65// Update is a function that creates, updates, or deletes a container's
66// metadata.
67func Update(c *gophercloud.ServiceClient, containerName string, opts os.UpdateOptsBuilder) os.UpdateResult {
68 return os.Update(c, containerName, opts)
69}