Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 1 | package accounts |
| 2 | |
| 3 | import ( |
| 4 | "github.com/racker/perigee" |
Jon Perritt | b6b1d02 | 2014-04-14 21:50:45 -0500 | [diff] [blame] | 5 | storage "github.com/rackspace/gophercloud/openstack/storage/v1" |
Jon Perritt | eb57564 | 2014-04-24 15:16:31 -0500 | [diff] [blame] | 6 | "net/http" |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 7 | ) |
| 8 | |
Jon Perritt | bef727e | 2014-05-12 22:41:55 -0500 | [diff] [blame^] | 9 | // GetResult is a *http.Response that is returned from a call to the Get function. |
Jon Perritt | eb57564 | 2014-04-24 15:16:31 -0500 | [diff] [blame] | 10 | type GetResult *http.Response |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 11 | |
| 12 | // Update is a function that creates, updates, or deletes an account's metadata. |
| 13 | func Update(c *storage.Client, opts UpdateOpts) error { |
| 14 | h, err := c.GetHeaders() |
| 15 | if err != nil { |
| 16 | return err |
| 17 | } |
| 18 | for k, v := range opts.Headers { |
| 19 | h[k] = v |
| 20 | } |
| 21 | |
| 22 | for k, v := range opts.Metadata { |
| 23 | h["X-Account-Meta-"+k] = v |
| 24 | } |
| 25 | |
| 26 | url := c.GetAccountURL() |
| 27 | _, err = perigee.Request("POST", url, perigee.Options{ |
| 28 | MoreHeaders: h, |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 29 | }) |
| 30 | return err |
| 31 | } |
| 32 | |
| 33 | // Get is a function that retrieves an account's metadata. To extract just the custom |
Jon Perritt | eb57564 | 2014-04-24 15:16:31 -0500 | [diff] [blame] | 34 | // metadata, pass the GetResult response to the ExtractMetadata function. |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 35 | func Get(c *storage.Client, opts GetOpts) (GetResult, error) { |
| 36 | h, err := c.GetHeaders() |
| 37 | if err != nil { |
| 38 | return nil, err |
| 39 | } |
| 40 | |
| 41 | for k, v := range opts.Headers { |
| 42 | h[k] = v |
| 43 | } |
| 44 | |
| 45 | url := c.GetAccountURL() |
| 46 | resp, err := perigee.Request("HEAD", url, perigee.Options{ |
| 47 | MoreHeaders: h, |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 48 | }) |
Jon Perritt | eb57564 | 2014-04-24 15:16:31 -0500 | [diff] [blame] | 49 | return &resp.HttpResponse, err |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 50 | } |