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