-
Notifications
You must be signed in to change notification settings - Fork 301
/
agents.go
62 lines (53 loc) · 1.79 KB
/
agents.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
package api
// AgentsService handles communication with the agent related methods of the
// Buildkite Agent API.
type AgentsService struct {
client *Client
}
// Agent represents an agent on the Buildkite Agent API
type Agent struct {
Name string `json:"name"`
AccessToken string `json:"access_token"`
Hostname string `json:"hostname"`
Endpoint string `json:"endpoint"`
PingInterval int `json:"ping_interval"`
HearbeatInterval int `json:"heartbeat_interval"`
OS string `json:"os"`
Arch string `json:"arch"`
ScriptEvalEnabled bool `json:"script_eval_enabled"`
Priority string `json:"priority,omitempty"`
Version string `json:"version"`
Build string `json:"build"`
MetaData []string `json:"meta_data"`
PID int `json:"pid,omitempty"`
}
// Registers the agent against the Buildktie Agent API. The client for this
// call must be authenticated using an Agent Registration Token
func (as *AgentsService) Register(agent *Agent) (*Agent, *Response, error) {
req, err := as.client.NewRequest("POST", "register", agent)
if err != nil {
return nil, nil, err
}
a := new(Agent)
resp, err := as.client.Do(req, a)
if err != nil {
return nil, resp, err
}
return a, resp, err
}
// Connects the agent to the Buildkite Agent API
func (as *AgentsService) Connect() (*Response, error) {
req, err := as.client.NewRequest("POST", "connect", nil)
if err != nil {
return nil, err
}
return as.client.Do(req, nil)
}
// Disconnects the agent to the Buildkite Agent API
func (as *AgentsService) Disconnect() (*Response, error) {
req, err := as.client.NewRequest("POST", "disconnect", nil)
if err != nil {
return nil, err
}
return as.client.Do(req, nil)
}