From 8286693da1e6a95e62f968fb2dc9cfcd68d6ccea Mon Sep 17 00:00:00 2001 From: jrperritt Date: Mon, 3 Aug 2015 19:10:56 -0600 Subject: [PATCH 1/2] add DeleteMetadata field for deleting container metadata --- openstack/objectstorage/v1/containers/requests.go | 10 ++++++++-- rackspace/objectstorage/v1/containers/delegate.go | 8 +++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/openstack/objectstorage/v1/containers/requests.go b/openstack/objectstorage/v1/containers/requests.go index 50ff9f48..bb8a51e2 100644 --- a/openstack/objectstorage/v1/containers/requests.go +++ b/openstack/objectstorage/v1/containers/requests.go @@ -124,7 +124,7 @@ func Create(c *gophercloud.ServiceClient, containerName string, opts CreateOptsB // Delete is a function that deletes a container. func Delete(c *gophercloud.ServiceClient, containerName string) DeleteResult { var res DeleteResult - _, res.Err = c.Delete(deleteURL(c, containerName), nil) + _, res.Err = c.Delete(deleteURL(c, containerName), &gophercloud.RequestOpts{}) return res } @@ -137,7 +137,10 @@ type UpdateOptsBuilder interface { // UpdateOpts is a structure that holds parameters for updating, creating, or // deleting a container's metadata. type UpdateOpts struct { - Metadata map[string]string + // a map of key-value pairs to add/update for the container. + Metadata map[string]string + // a slice a keys of the metadata to delete from the container. + DeleteMetadata []string ContainerRead string `h:"X-Container-Read"` ContainerSyncTo string `h:"X-Container-Sync-To"` ContainerSyncKey string `h:"X-Container-Sync-Key"` @@ -157,6 +160,9 @@ func (opts UpdateOpts) ToContainerUpdateMap() (map[string]string, error) { for k, v := range opts.Metadata { h["X-Container-Meta-"+k] = v } + for _, k := range opts.DeleteMetadata { + h["X-Remove-Container-Meta-"+k] = "true" + } return h, nil } diff --git a/rackspace/objectstorage/v1/containers/delegate.go b/rackspace/objectstorage/v1/containers/delegate.go index 77ed0025..80d1e6f1 100644 --- a/rackspace/objectstorage/v1/containers/delegate.go +++ b/rackspace/objectstorage/v1/containers/delegate.go @@ -58,7 +58,10 @@ func Delete(c *gophercloud.ServiceClient, containerName string) os.DeleteResult // UpdateOpts is a structure that holds parameters for updating or creating a // container's metadata. type UpdateOpts struct { - Metadata map[string]string + // a map of key-value pairs to add/update for the container. + Metadata map[string]string + // a slice a keys of the metadata to delete from the container. + DeleteMetadata []string ContainerRead string `h:"X-Container-Read"` ContainerWrite string `h:"X-Container-Write"` ContentType string `h:"Content-Type"` @@ -76,6 +79,9 @@ func (opts UpdateOpts) ToContainerUpdateMap() (map[string]string, error) { for k, v := range opts.Metadata { h["X-Container-Meta-"+k] = v } + for _, k := range opts.DeleteMetadata { + h["X-Remove-Container-Meta-"+k] = "true" + } return h, nil } From 47988a61f87c6ba806d4c952ed8fa62642b555c3 Mon Sep 17 00:00:00 2001 From: jrperritt Date: Wed, 5 Aug 2015 11:07:18 -0600 Subject: [PATCH 2/2] allow deleting metadata from account --- openstack/objectstorage/v1/accounts/requests.go | 4 ++++ rackspace/objectstorage/v1/accounts/delegate.go | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/openstack/objectstorage/v1/accounts/requests.go b/openstack/objectstorage/v1/accounts/requests.go index 66c46a97..e0418ba0 100644 --- a/openstack/objectstorage/v1/accounts/requests.go +++ b/openstack/objectstorage/v1/accounts/requests.go @@ -60,6 +60,7 @@ type UpdateOptsBuilder interface { // deleting an account's metadata. type UpdateOpts struct { Metadata map[string]string + DeleteMetadata []string ContentType string `h:"Content-Type"` DetectContentType bool `h:"X-Detect-Content-Type"` TempURLKey string `h:"X-Account-Meta-Temp-URL-Key"` @@ -75,6 +76,9 @@ func (opts UpdateOpts) ToAccountUpdateMap() (map[string]string, error) { for k, v := range opts.Metadata { headers["X-Account-Meta-"+k] = v } + for _, k := range opts.DeleteMetadata { + headers["X-Remove-Account-Meta-"+k] = "true" + } return headers, err } diff --git a/rackspace/objectstorage/v1/accounts/delegate.go b/rackspace/objectstorage/v1/accounts/delegate.go index 94739308..d0275986 100644 --- a/rackspace/objectstorage/v1/accounts/delegate.go +++ b/rackspace/objectstorage/v1/accounts/delegate.go @@ -16,9 +16,10 @@ func Get(c *gophercloud.ServiceClient) os.GetResult { // UpdateOpts is a structure that contains parameters for updating, creating, or // deleting an account's metadata. type UpdateOpts struct { - Metadata map[string]string - TempURLKey string `h:"X-Account-Meta-Temp-URL-Key"` - TempURLKey2 string `h:"X-Account-Meta-Temp-URL-Key-2"` + Metadata map[string]string + DeleteMetadata []string + TempURLKey string `h:"X-Account-Meta-Temp-URL-Key"` + TempURLKey2 string `h:"X-Account-Meta-Temp-URL-Key-2"` } // ToAccountUpdateMap formats an UpdateOpts into a map[string]string of headers. @@ -30,6 +31,9 @@ func (opts UpdateOpts) ToAccountUpdateMap() (map[string]string, error) { for k, v := range opts.Metadata { headers["X-Account-Meta-"+k] = v } + for _, k := range opts.DeleteMetadata { + headers["X-Remove-Account-Meta-"+k] = "true" + } return headers, err }