blob: 3ffc5f7938bf3aa5f50ff28bee16ac1f6a104eb5 [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
25 url := c.GetAccountURL()
26 _, err = perigee.Request("POST", url, perigee.Options{
27 MoreHeaders: h,
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
41 url := c.GetAccountURL()
42 resp, err := perigee.Request("HEAD", url, perigee.Options{
43 MoreHeaders: h,
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}