-
Notifications
You must be signed in to change notification settings - Fork 525
/
requests.go
53 lines (46 loc) · 1.79 KB
/
requests.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
package ec2credentials
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// List enumerates the Credentials to which the current token has access.
func List(client *gophercloud.ServiceClient, userID string) pagination.Pager {
url := listURL(client, userID)
return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
return CredentialPage{pagination.LinkedPageBase{PageResult: r}}
})
}
// Get retrieves details on a single EC2 credential by ID.
func Get(client *gophercloud.ServiceClient, userID string, id string) (r GetResult) {
resp, err := client.Get(getURL(client, userID, id), &r.Body, nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
// CreateOpts provides options used to create an EC2 credential.
type CreateOpts struct {
// TenantID is the project ID scope of the EC2 credential.
TenantID string `json:"tenant_id" required:"true"`
}
// ToCredentialCreateMap formats a CreateOpts into a create request.
func (opts CreateOpts) ToCredentialCreateMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "")
}
// Create creates a new EC2 Credential.
func Create(client *gophercloud.ServiceClient, userID string, opts CreateOpts) (r CreateResult) {
b, err := opts.ToCredentialCreateMap()
if err != nil {
r.Err = err
return
}
resp, err := client.Post(createURL(client, userID), &b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{201},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
// Delete deletes an EC2 credential.
func Delete(client *gophercloud.ServiceClient, userID string, id string) (r DeleteResult) {
resp, err := client.Delete(deleteURL(client, userID, id), nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}