/
client_action.go
93 lines (76 loc) · 2.36 KB
/
client_action.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 cdsclient
import (
"context"
"fmt"
"io"
"github.com/ovh/cds/sdk"
)
func (c *client) Requirements() ([]sdk.Requirement, error) {
var req []sdk.Requirement
if _, err := c.GetJSON(context.Background(), "/action/requirement", &req); err != nil {
return nil, err
}
return req, nil
}
func (c *client) ActionDelete(groupName, name string) error {
path := fmt.Sprintf("/action/%s/%s", groupName, name)
_, err := c.DeleteJSON(context.Background(), path, nil)
return err
}
func (c *client) ActionGet(groupName, name string, mods ...RequestModifier) (*sdk.Action, error) {
var a sdk.Action
path := fmt.Sprintf("/action/%s/%s", groupName, name)
if _, err := c.GetJSON(context.Background(), path, &a, mods...); err != nil {
return nil, err
}
return &a, nil
}
func (c *client) ActionUsage(groupName, name string, mods ...RequestModifier) (*sdk.ActionUsages, error) {
var a sdk.ActionUsages
path := fmt.Sprintf("/action/%s/%s/usage", groupName, name)
if _, err := c.GetJSON(context.Background(), path, &a, mods...); err != nil {
return nil, err
}
return &a, nil
}
func (c *client) ActionList() ([]sdk.Action, error) {
actions := []sdk.Action{}
if _, err := c.GetJSON(context.Background(), "/action", &actions); err != nil {
return nil, err
}
return actions, nil
}
func (c *client) ActionImport(content io.Reader, mods ...RequestModifier) error {
url := "/action/import"
_, _, code, err := c.Request(context.Background(), "POST", url, content, mods...)
if err != nil {
return err
}
if code > 400 {
return newAPIError(fmt.Errorf("HTTP Code %d", code))
}
return nil
}
func (c *client) ActionExport(groupName, name string, mods ...RequestModifier) ([]byte, error) {
path := fmt.Sprintf("/action/%s/%s/export", groupName, name)
body, _, _, err := c.Request(context.Background(), "GET", path, nil, mods...)
if err != nil {
return nil, err
}
return body, nil
}
func (c *client) ActionBuiltinList() ([]sdk.Action, error) {
actions := []sdk.Action{}
if _, err := c.GetJSON(context.Background(), "/actionBuiltin", &actions); err != nil {
return nil, err
}
return actions, nil
}
func (c *client) ActionBuiltinGet(name string, mods ...RequestModifier) (*sdk.Action, error) {
var a sdk.Action
path := fmt.Sprintf("/actionBuiltin/%s", name)
if _, err := c.GetJSON(context.Background(), path, &a, mods...); err != nil {
return nil, err
}
return &a, nil
}