Jon Perritt | b5c7812 | 2014-10-15 20:44:39 -0500 | [diff] [blame] | 1 | package cdncontainers |
| 2 | |
| 3 | import ( |
Jon Perritt | 33ed741 | 2014-10-17 19:35:32 -0500 | [diff] [blame] | 4 | "strconv" |
| 5 | |
Jon Perritt | b5c7812 | 2014-10-15 20:44:39 -0500 | [diff] [blame] | 6 | "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. |
| 13 | func ExtractNames(page pagination.Page) ([]string, error) { |
| 14 | return os.ExtractNames(page) |
| 15 | } |
| 16 | |
| 17 | // ListOpts are options for listing Rackspace CDN containers. |
| 18 | type 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. |
| 27 | func (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 Perritt | 0ba5a56 | 2014-10-15 23:23:12 -0500 | [diff] [blame] | 38 | func List(c *gophercloud.ServiceClient, opts os.ListOptsBuilder) pagination.Pager { |
Jon Perritt | b5c7812 | 2014-10-15 20:44:39 -0500 | [diff] [blame] | 39 | 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. |
| 45 | func 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. |
| 51 | type 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. |
| 58 | func (opts UpdateOpts) ToContainerUpdateMap() (map[string]string, error) { |
| 59 | h, err := gophercloud.BuildHeaders(opts) |
| 60 | if err != nil { |
| 61 | return nil, err |
| 62 | } |
Jon Perritt | 33ed741 | 2014-10-17 19:35:32 -0500 | [diff] [blame] | 63 | h["X-Cdn-Enabled"] = strconv.FormatBool(opts.CDNEnabled) |
Jon Perritt | b5c7812 | 2014-10-15 20:44:39 -0500 | [diff] [blame] | 64 | return h, nil |
| 65 | } |
| 66 | |
| 67 | // Update is a function that creates, updates, or deletes a container's |
| 68 | // metadata. |
| 69 | func Update(c *gophercloud.ServiceClient, containerName string, opts os.UpdateOptsBuilder) os.UpdateResult { |
| 70 | return os.Update(c, containerName, opts) |
| 71 | } |