blob: 7b84497e595e2a011fda43f18ebdf87a3344bcd3 [file] [log] [blame]
Jon Perritt816d2a02014-03-11 20:49:46 -05001package accounts
2
3import (
4 "github.com/racker/perigee"
Jon Perrittb6b1d022014-04-14 21:50:45 -05005 storage "github.com/rackspace/gophercloud/openstack/storage/v1"
Jon Perritteb575642014-04-24 15:16:31 -05006 "net/http"
Jon Perritt816d2a02014-03-11 20:49:46 -05007)
8
Jon Perrittbef727e2014-05-12 22:41:55 -05009// GetResult is a *http.Response that is returned from a call to the Get function.
Jon Perritteb575642014-04-24 15:16:31 -050010type GetResult *http.Response
Jon Perritt816d2a02014-03-11 20:49:46 -050011
12// Update is a function that creates, updates, or deletes an account's metadata.
13func 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 Perritt816d2a02014-03-11 20:49:46 -050029 })
30 return err
31}
32
33// Get is a function that retrieves an account's metadata. To extract just the custom
Jon Perritteb575642014-04-24 15:16:31 -050034// metadata, pass the GetResult response to the ExtractMetadata function.
Jon Perritt816d2a02014-03-11 20:49:46 -050035func 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 Perritt816d2a02014-03-11 20:49:46 -050048 })
Jon Perritteb575642014-04-24 15:16:31 -050049 return &resp.HttpResponse, err
Jon Perritt816d2a02014-03-11 20:49:46 -050050}