blob: c7385735c3b91e3d21ede1d4d4b10da97c78d118 [file] [log] [blame]
Jon Perritt816d2a02014-03-11 20:49:46 -05001package accounts
2
3import (
Jon Perritteb575642014-04-24 15:16:31 -05004 "net/http"
Ash Wilson604320e2014-09-10 16:02:28 -04005
6 "github.com/racker/perigee"
7 "github.com/rackspace/gophercloud"
Jon Perritt816d2a02014-03-11 20:49:46 -05008)
9
Jon Perrittbef727e2014-05-12 22:41:55 -050010// GetResult is a *http.Response that is returned from a call to the Get function.
Jon Perritteb575642014-04-24 15:16:31 -050011type GetResult *http.Response
Jon Perritt816d2a02014-03-11 20:49:46 -050012
13// Update is a function that creates, updates, or deletes an account's metadata.
Ash Wilson604320e2014-09-10 16:02:28 -040014func Update(c *gophercloud.ServiceClient, opts UpdateOpts) error {
15 h := c.Provider.AuthenticatedHeaders()
16
Jon Perritt816d2a02014-03-11 20:49:46 -050017 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 Perrittfc39b942014-09-10 21:18:19 -050025 _, err := perigee.Request("POST", accountURL(c), perigee.Options{
Jon Perritt816d2a02014-03-11 20:49:46 -050026 MoreHeaders: h,
Ash Wilsone47ea9e2014-09-10 16:03:44 -040027 OkCodes: []int{204},
Jon Perritt816d2a02014-03-11 20:49:46 -050028 })
29 return err
30}
31
32// Get is a function that retrieves an account's metadata. To extract just the custom
Jon Perritteb575642014-04-24 15:16:31 -050033// metadata, pass the GetResult response to the ExtractMetadata function.
Ash Wilson604320e2014-09-10 16:02:28 -040034func Get(c *gophercloud.ServiceClient, opts GetOpts) (GetResult, error) {
35 h := c.Provider.AuthenticatedHeaders()
Jon Perritt816d2a02014-03-11 20:49:46 -050036
37 for k, v := range opts.Headers {
38 h[k] = v
39 }
40
Jon Perrittfc39b942014-09-10 21:18:19 -050041 resp, err := perigee.Request("HEAD", accountURL(c), perigee.Options{
Jon Perritt816d2a02014-03-11 20:49:46 -050042 MoreHeaders: h,
Ash Wilsone47ea9e2014-09-10 16:03:44 -040043 OkCodes: []int{204},
Jon Perritt816d2a02014-03-11 20:49:46 -050044 })
Jon Perritteb575642014-04-24 15:16:31 -050045 return &resp.HttpResponse, err
Jon Perritt816d2a02014-03-11 20:49:46 -050046}