Accounts updated unit tests; common ExtractHeaders method
diff --git a/openstack/objectstorage/v1/accounts/requests.go b/openstack/objectstorage/v1/accounts/requests.go
index 5de09da..b30439c 100644
--- a/openstack/objectstorage/v1/accounts/requests.go
+++ b/openstack/objectstorage/v1/accounts/requests.go
@@ -5,63 +5,75 @@
"github.com/rackspace/gophercloud"
)
-// UpdateOpts is a structure that contains parameters for updating, creating, or deleting an
-// account's metadata.
-type UpdateOpts struct {
- Metadata map[string]string
- Headers map[string]string
-}
-
-// Update is a function that creates, updates, or deletes an account's metadata.
-func Update(c *gophercloud.ServiceClient, opts UpdateOpts) UpdateResult {
- headers := c.Provider.AuthenticatedHeaders()
-
- for k, v := range opts.Headers {
- headers[k] = v
- }
-
- for k, v := range opts.Metadata {
- headers["X-Account-Meta-"+k] = v
- }
-
- var res UpdateResult
-
- var resp *perigee.Response
-
- resp, res.Err = perigee.Request("POST", accountURL(c), perigee.Options{
- MoreHeaders: headers,
- OkCodes: []int{204},
- })
-
- res.Resp = &resp.HttpResponse
-
- return res
-}
-
// GetOpts is a structure that contains parameters for getting an account's metadata.
type GetOpts struct {
- Headers map[string]string
+ Newest bool `h:"X-Newest"`
}
// Get is a function that retrieves an account's metadata. To extract just the custom
-// metadata, pass the GetResult response to the ExtractMetadata function.
-func Get(c *gophercloud.ServiceClient, opts GetOpts) GetResult {
- headers := c.Provider.AuthenticatedHeaders()
+// metadata, call the ExtractMetadata method on the GetResult. To extract all the headers that are
+// returned (including the metadata), call the ExtractHeaders method on the GetResult.
+func Get(c *gophercloud.ServiceClient, opts *GetOpts) GetResult {
+ var res GetResult
+ h := c.Provider.AuthenticatedHeaders()
- for k, v := range opts.Headers {
- headers[k] = v
+ if opts != nil {
+ headers, err := gophercloud.BuildHeaders(opts)
+ if err != nil {
+ res.Err = err
+ return res
+ }
+
+ for k, v := range headers {
+ h[k] = v
+ }
}
- var res GetResult
- var resp *perigee.Response
-
- resp, res.Err = perigee.Request("HEAD", accountURL(c), perigee.Options{
- MoreHeaders: headers,
- Results: &res.Resp,
+ resp, err := perigee.Request("HEAD", getURL(c), perigee.Options{
+ MoreHeaders: h,
OkCodes: []int{204},
})
-
res.Resp = &resp.HttpResponse
+ res.Err = err
+ return res
+}
+// UpdateOpts is a structure that contains parameters for updating, creating, or deleting an
+// account's metadata.
+type UpdateOpts struct {
+ Metadata map[string]string
+ ContentType string `h:"Content-Type"`
+ DetectContentType bool `h:"X-Detect-Content-Type"`
+ TempURLKey string `h:"X-Account-Meta-Temp-URL-Key"`
+ TempURLKey2 string `h:"X-Account-Meta-Temp-URL-Key-2"`
+}
+
+// Update is a function that creates, updates, or deletes an account's metadata. To extract the
+// headers returned, call the ExtractHeaders method on the UpdateResult.
+func Update(c *gophercloud.ServiceClient, opts *UpdateOpts) UpdateResult {
+ var res UpdateResult
+ h := c.Provider.AuthenticatedHeaders()
+
+ if opts != nil {
+ headers, err := gophercloud.BuildHeaders(opts)
+ if err != nil {
+ res.Err = err
+ return res
+ }
+ for k, v := range headers {
+ h[k] = v
+ }
+
+ for k, v := range opts.Metadata {
+ h["X-Account-Meta-"+k] = v
+ }
+ }
+
+ resp, err := perigee.Request("POST", updateURL(c), perigee.Options{
+ MoreHeaders: h,
+ OkCodes: []int{204},
+ })
+ res.Resp = &resp.HttpResponse
+ res.Err = err
return res
}