forked from buildkite/agent
-
Notifications
You must be signed in to change notification settings - Fork 1
/
meta_data.go
72 lines (57 loc) · 1.59 KB
/
meta_data.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
package api
import (
"fmt"
)
// MetaDataService handles communication with the meta data related methods of
// the Buildkite Agent API.
type MetaDataService struct {
client *Client
}
// MetaData represents a Buildkite Agent API MetaData
type MetaData struct {
Key string `json:"key,omitempty"`
Value string `json:"value,omitempty"`
}
// MetaDataExists represents a Buildkite Agent API MetaData Exists check
// response
type MetaDataExists struct {
Exists bool `json:"exists"`
}
// Sets the meta data value
func (ps *MetaDataService) Set(jobId string, metaData *MetaData) (*Response, error) {
u := fmt.Sprintf("jobs/%s/data/set", jobId)
req, err := ps.client.NewRequest("POST", u, metaData)
if err != nil {
return nil, err
}
return ps.client.Do(req, nil)
}
// Gets the meta data value
func (ps *MetaDataService) Get(jobId string, key string) (*MetaData, *Response, error) {
u := fmt.Sprintf("jobs/%s/data/get", jobId)
m := &MetaData{Key: key}
req, err := ps.client.NewRequest("POST", u, m)
if err != nil {
return nil, nil, err
}
resp, err := ps.client.Do(req, m)
if err != nil {
return nil, resp, err
}
return m, resp, err
}
// Returns true if the meta data key has been set, false if it hasn't.
func (ps *MetaDataService) Exists(jobId string, key string) (*MetaDataExists, *Response, error) {
u := fmt.Sprintf("jobs/%s/data/exists", jobId)
m := &MetaData{Key: key}
req, err := ps.client.NewRequest("POST", u, m)
if err != nil {
return nil, nil, err
}
e := new(MetaDataExists)
resp, err := ps.client.Do(req, e)
if err != nil {
return nil, resp, err
}
return e, resp, err
}