blob: 964a604580751b8fa504aa9011f68ce85f9049ea [file] [log] [blame]
Jamie Hannaford93209fe2014-10-10 11:54:19 +02001package accounts
2
3import (
Ash Wilsonaf262872014-10-20 09:32:29 -04004 "net/http"
Jamie Hannaford93209fe2014-10-10 11:54:19 +02005 "strings"
Jamie Hannafordb2e129d2014-10-10 14:06:28 +02006
Ash Wilsonaf262872014-10-20 09:32:29 -04007 "github.com/rackspace/gophercloud"
Jamie Hannaford93209fe2014-10-10 11:54:19 +02008)
9
Ash Wilsonaf262872014-10-20 09:32:29 -040010// GetResult is returned from a call to the Get function.
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020011type GetResult struct {
Ash Wilsonaf262872014-10-20 09:32:29 -040012 gophercloud.Result
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020013}
Jamie Hannaford93209fe2014-10-10 11:54:19 +020014
15// ExtractMetadata is a function that takes a GetResult (of type *http.Response)
16// and returns the custom metatdata associated with the account.
Jon Perritt4a59d232014-10-09 20:21:31 -050017func (gr GetResult) ExtractMetadata() (map[string]string, error) {
18 if gr.Err != nil {
19 return nil, gr.Err
20 }
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020021
Jon Perritt4a59d232014-10-09 20:21:31 -050022 metadata := make(map[string]string)
Ash Wilsonaf262872014-10-20 09:32:29 -040023 for k, v := range gr.Headers {
Jamie Hannaford93209fe2014-10-10 11:54:19 +020024 if strings.HasPrefix(k, "X-Account-Meta-") {
25 key := strings.TrimPrefix(k, "X-Account-Meta-")
26 metadata[key] = v[0]
27 }
28 }
Jon Perritt4a59d232014-10-09 20:21:31 -050029 return metadata, nil
30}
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020031
Ash Wilsonaf262872014-10-20 09:32:29 -040032// UpdateResult is returned from a call to the Update function.
Jon Perritt4a59d232014-10-09 20:21:31 -050033type UpdateResult struct {
Ash Wilsonaf262872014-10-20 09:32:29 -040034 gophercloud.Result
35}
36
37// Extract returns the unmodified HTTP headers and any error conditions encountered during the
38// metadata update.
39func (ur UpdateResult) Extract() (http.Header, error) {
40 return ur.Headers, ur.Err
Jamie Hannaford93209fe2014-10-10 11:54:19 +020041}