forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delegate.go
93 lines (81 loc) · 3.11 KB
/
delegate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package containers
import (
"github.com/rackspace/gophercloud"
os "github.com/rackspace/gophercloud/openstack/objectstorage/v1/containers"
"github.com/rackspace/gophercloud/pagination"
)
// ExtractInfo interprets a page of List results when full container info
// is requested.
func ExtractInfo(page pagination.Page) ([]os.Container, error) {
return os.ExtractInfo(page)
}
// ExtractNames interprets a page of List results when just the container
// names are requested.
func ExtractNames(page pagination.Page) ([]string, error) {
return os.ExtractNames(page)
}
// List is a function that retrieves containers associated with the account as
// well as account metadata. It returns a pager which can be iterated with the
// EachPage function.
func List(c *gophercloud.ServiceClient, opts os.ListOptsBuilder) pagination.Pager {
return os.List(c, opts)
}
// CreateOpts is a structure that holds parameters for creating a container.
type CreateOpts struct {
Metadata map[string]string
ContainerRead string `h:"X-Container-Read"`
ContainerWrite string `h:"X-Container-Write"`
VersionsLocation string `h:"X-Versions-Location"`
}
// ToContainerCreateMap formats a CreateOpts into a map of headers.
func (opts CreateOpts) ToContainerCreateMap() (map[string]string, error) {
h, err := gophercloud.BuildHeaders(opts)
if err != nil {
return nil, err
}
for k, v := range opts.Metadata {
h["X-Container-Meta-"+k] = v
}
return h, nil
}
// Create is a function that creates a new container.
func Create(c *gophercloud.ServiceClient, containerName string, opts os.CreateOptsBuilder) os.CreateResult {
return os.Create(c, containerName, opts)
}
// Delete is a function that deletes a container.
func Delete(c *gophercloud.ServiceClient, containerName string) os.DeleteResult {
return os.Delete(c, containerName)
}
// UpdateOpts is a structure that holds parameters for updating or creating a
// container's metadata.
type UpdateOpts struct {
Metadata map[string]string
ContainerRead string `h:"X-Container-Read"`
ContainerWrite string `h:"X-Container-Write"`
ContentType string `h:"Content-Type"`
DetectContentType bool `h:"X-Detect-Content-Type"`
RemoveVersionsLocation string `h:"X-Remove-Versions-Location"`
VersionsLocation string `h:"X-Versions-Location"`
}
// ToContainerUpdateMap formats a CreateOpts into a map of headers.
func (opts UpdateOpts) ToContainerUpdateMap() (map[string]string, error) {
h, err := gophercloud.BuildHeaders(opts)
if err != nil {
return nil, err
}
for k, v := range opts.Metadata {
h["X-Container-Meta-"+k] = v
}
return h, nil
}
// Update is a function that creates, updates, or deletes a container's
// metadata.
func Update(c *gophercloud.ServiceClient, containerName string, opts os.UpdateOptsBuilder) os.UpdateResult {
return os.Update(c, containerName, opts)
}
// Get is a function that retrieves the metadata of a container. To extract just
// the custom metadata, pass the GetResult response to the ExtractMetadata
// function.
func Get(c *gophercloud.ServiceClient, containerName string) os.GetResult {
return os.Get(c, containerName)
}