blob: 50032bde37bbc3380fae43677405a43cca77d0b4 [file] [log] [blame]
Jamie Hannaford93209fe2014-10-10 11:54:19 +02001package accounts
2
3import (
Jamie Hannaford93209fe2014-10-10 11:54:19 +02004 "strings"
Jamie Hannafordb2e129d2014-10-10 14:06:28 +02005
Jon Perritt27249f42016-02-18 10:35:59 -06006 "github.com/gophercloud/gophercloud"
Jamie Hannaford93209fe2014-10-10 11:54:19 +02007)
8
Jon Perrittae06ab72014-11-06 18:18:55 -06009// UpdateResult is returned from a call to the Update function.
10type UpdateResult struct {
11 gophercloud.HeaderResult
12}
13
14// UpdateHeader represents the headers returned in the response from an Update request.
15type UpdateHeader struct {
Jon Perritt3c166472016-02-25 03:07:41 -060016 ContentLength string `json:"Content-Length"`
17 ContentType string `json:"Content-Type"`
18 Date gophercloud.JSONRFC1123 `json:"Date"`
19 TransID string `json:"X-Trans-Id"`
Jon Perrittae06ab72014-11-06 18:18:55 -060020}
21
22// Extract will return a struct of headers returned from a call to Get. To obtain
23// a map of headers, call the ExtractHeader method on the GetResult.
Jon Perritt3c166472016-02-25 03:07:41 -060024func (ur UpdateResult) Extract() (*UpdateHeader, error) {
25 var uh *UpdateHeader
26 err := ur.ExtractInto(&uh)
27 return uh, err
Jon Perrittae06ab72014-11-06 18:18:55 -060028}
29
30// GetHeader represents the headers returned in the response from a Get request.
31type GetHeader struct {
Jon Perritt3c166472016-02-25 03:07:41 -060032 BytesUsed string `json:"X-Account-Bytes-Used"`
33 ContainerCount string `json:"X-Account-Container-Count"`
34 ContentLength string `json:"Content-Length"`
35 ContentType string `json:"Content-Type"`
36 Date gophercloud.JSONRFC1123 `json:"Date"`
37 ObjectCount string `json:"X-Account-Object-Count"`
38 TransID string `json:"X-Trans-Id"`
39 TempURLKey string `json:"X-Account-Meta-Temp-URL-Key"`
40 TempURLKey2 string `json:"X-Account-Meta-Temp-URL-Key-2"`
Jon Perrittae06ab72014-11-06 18:18:55 -060041}
42
Ash Wilsonaf262872014-10-20 09:32:29 -040043// GetResult is returned from a call to the Get function.
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020044type GetResult struct {
Jon Perrittd50f93e2014-10-27 14:19:27 -050045 gophercloud.HeaderResult
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020046}
Jamie Hannaford93209fe2014-10-10 11:54:19 +020047
Jon Perrittae06ab72014-11-06 18:18:55 -060048// Extract will return a struct of headers returned from a call to Get. To obtain
49// a map of headers, call the ExtractHeader method on the GetResult.
Jon Perritt3c166472016-02-25 03:07:41 -060050func (gr GetResult) Extract() (*GetHeader, error) {
51 var gh *GetHeader
52 err := gr.ExtractInto(&gh)
53 return gh, err
Jon Perrittae06ab72014-11-06 18:18:55 -060054}
55
Jamie Hannaford93209fe2014-10-10 11:54:19 +020056// ExtractMetadata is a function that takes a GetResult (of type *http.Response)
57// and returns the custom metatdata associated with the account.
Jon Perritt4a59d232014-10-09 20:21:31 -050058func (gr GetResult) ExtractMetadata() (map[string]string, error) {
59 if gr.Err != nil {
60 return nil, gr.Err
61 }
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020062
Jon Perritt4a59d232014-10-09 20:21:31 -050063 metadata := make(map[string]string)
Ash Wilson72e4d2c2014-10-20 10:27:30 -040064 for k, v := range gr.Header {
Jamie Hannaford93209fe2014-10-10 11:54:19 +020065 if strings.HasPrefix(k, "X-Account-Meta-") {
66 key := strings.TrimPrefix(k, "X-Account-Meta-")
67 metadata[key] = v[0]
68 }
69 }
Jon Perritt4a59d232014-10-09 20:21:31 -050070 return metadata, nil
71}