Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 1 | package accounts |
| 2 | |
| 3 | import ( |
Jon Perritt | eb57564 | 2014-04-24 15:16:31 -0500 | [diff] [blame] | 4 | "net/http" |
Ash Wilson | 604320e | 2014-09-10 16:02:28 -0400 | [diff] [blame] | 5 | |
| 6 | "github.com/racker/perigee" |
| 7 | "github.com/rackspace/gophercloud" |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 8 | ) |
| 9 | |
Jon Perritt | bef727e | 2014-05-12 22:41:55 -0500 | [diff] [blame] | 10 | // 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] | 11 | type GetResult *http.Response |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 12 | |
| 13 | // Update is a function that creates, updates, or deletes an account's metadata. |
Ash Wilson | 604320e | 2014-09-10 16:02:28 -0400 | [diff] [blame] | 14 | func Update(c *gophercloud.ServiceClient, opts UpdateOpts) error { |
| 15 | h := c.Provider.AuthenticatedHeaders() |
| 16 | |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 17 | for k, v := range opts.Headers { |
| 18 | h[k] = v |
| 19 | } |
| 20 | |
| 21 | for k, v := range opts.Metadata { |
| 22 | h["X-Account-Meta-"+k] = v |
| 23 | } |
| 24 | |
Jon Perritt | fc39b94 | 2014-09-10 21:18:19 -0500 | [diff] [blame^] | 25 | _, err := perigee.Request("POST", accountURL(c), perigee.Options{ |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 26 | MoreHeaders: h, |
Ash Wilson | e47ea9e | 2014-09-10 16:03:44 -0400 | [diff] [blame] | 27 | OkCodes: []int{204}, |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 28 | }) |
| 29 | return err |
| 30 | } |
| 31 | |
| 32 | // 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] | 33 | // metadata, pass the GetResult response to the ExtractMetadata function. |
Ash Wilson | 604320e | 2014-09-10 16:02:28 -0400 | [diff] [blame] | 34 | func Get(c *gophercloud.ServiceClient, opts GetOpts) (GetResult, error) { |
| 35 | h := c.Provider.AuthenticatedHeaders() |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 36 | |
| 37 | for k, v := range opts.Headers { |
| 38 | h[k] = v |
| 39 | } |
| 40 | |
Jon Perritt | fc39b94 | 2014-09-10 21:18:19 -0500 | [diff] [blame^] | 41 | resp, err := perigee.Request("HEAD", accountURL(c), perigee.Options{ |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 42 | MoreHeaders: h, |
Ash Wilson | e47ea9e | 2014-09-10 16:03:44 -0400 | [diff] [blame] | 43 | OkCodes: []int{204}, |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 44 | }) |
Jon Perritt | eb57564 | 2014-04-24 15:16:31 -0500 | [diff] [blame] | 45 | return &resp.HttpResponse, err |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 46 | } |