blob: 2ba4744503eca0d7e0c802b48b282d324797cfeb [file] [log] [blame]
Jon Perritt816d2a02014-03-11 20:49:46 -05001package accounts
2
3import (
Ash Wilson604320e2014-09-10 16:02:28 -04004 "github.com/racker/perigee"
5 "github.com/rackspace/gophercloud"
Jon Perritt816d2a02014-03-11 20:49:46 -05006)
7
Jamie Hannaford93209fe2014-10-10 11:54:19 +02008// UpdateOpts is a structure that contains parameters for updating, creating, or deleting an
9// account's metadata.
10type UpdateOpts struct {
11 Metadata map[string]string
12 Headers map[string]string
13}
Jon Perritt816d2a02014-03-11 20:49:46 -050014
15// Update is a function that creates, updates, or deletes an account's metadata.
Ash Wilson604320e2014-09-10 16:02:28 -040016func Update(c *gophercloud.ServiceClient, opts UpdateOpts) error {
17 h := c.Provider.AuthenticatedHeaders()
18
Jon Perritt816d2a02014-03-11 20:49:46 -050019 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 Perrittfc39b942014-09-10 21:18:19 -050027 _, err := perigee.Request("POST", accountURL(c), perigee.Options{
Jon Perritt816d2a02014-03-11 20:49:46 -050028 MoreHeaders: h,
Ash Wilsone47ea9e2014-09-10 16:03:44 -040029 OkCodes: []int{204},
Jon Perritt816d2a02014-03-11 20:49:46 -050030 })
31 return err
32}
33
Jamie Hannaford93209fe2014-10-10 11:54:19 +020034// GetOpts is a structure that contains parameters for getting an account's metadata.
35type GetOpts struct {
36 Headers map[string]string
37}
38
Jon Perritt816d2a02014-03-11 20:49:46 -050039// Get is a function that retrieves an account's metadata. To extract just the custom
Jon Perritteb575642014-04-24 15:16:31 -050040// metadata, pass the GetResult response to the ExtractMetadata function.
Ash Wilson604320e2014-09-10 16:02:28 -040041func Get(c *gophercloud.ServiceClient, opts GetOpts) (GetResult, error) {
42 h := c.Provider.AuthenticatedHeaders()
Jon Perritt816d2a02014-03-11 20:49:46 -050043
44 for k, v := range opts.Headers {
45 h[k] = v
46 }
47
Jon Perrittfc39b942014-09-10 21:18:19 -050048 resp, err := perigee.Request("HEAD", accountURL(c), perigee.Options{
Jon Perritt816d2a02014-03-11 20:49:46 -050049 MoreHeaders: h,
Ash Wilsone47ea9e2014-09-10 16:03:44 -040050 OkCodes: []int{204},
Jon Perritt816d2a02014-03-11 20:49:46 -050051 })
Jon Perritteb575642014-04-24 15:16:31 -050052 return &resp.HttpResponse, err
Jon Perritt816d2a02014-03-11 20:49:46 -050053}