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