github.com/bshelton229/agent@v3.5.4+incompatible/api/agents.go (about) 1 package api 2 3 import ( 4 "net/http" 5 6 "github.com/buildkite/agent/experiments" 7 ) 8 9 // AgentsService handles communication with the agent related methods of the 10 // Buildkite Agent API. 11 type AgentsService struct { 12 client *Client 13 } 14 15 // Agent represents an agent on the Buildkite Agent API 16 type Agent struct { 17 Name string `json:"name" msgpack:"name"` 18 AccessToken string `json:"access_token" msgpack:"access_token"` 19 Hostname string `json:"hostname" msgpack:"hostname"` 20 Endpoint string `json:"endpoint" msgpack:"endpoint"` 21 PingInterval int `json:"ping_interval" msgpack:"ping_interval"` 22 JobStatusInterval int `json:"job_status_interval" msgpack:"job_status_interval"` 23 HearbeatInterval int `json:"heartbeat_interval" msgpack:"heartbeat_interval"` 24 OS string `json:"os" msgpack:"os"` 25 Arch string `json:"arch" msgpack:"arch"` 26 ScriptEvalEnabled bool `json:"script_eval_enabled" msgpack:"script_eval_enabled"` 27 Priority string `json:"priority,omitempty" msgpack:"priority,omitempty"` 28 Version string `json:"version" msgpack:"version"` 29 Build string `json:"build" msgpack:"build"` 30 Tags []string `json:"meta_data" msgpack:"meta_data"` 31 PID int `json:"pid,omitempty" msgpack:"pid,omitempty"` 32 MachineID string `json:"machine_id,omitempty" msgpack:"machine_id,omitempty"` 33 } 34 35 // Registers the agent against the Buildktie Agent API. The client for this 36 // call must be authenticated using an Agent Registration Token 37 func (as *AgentsService) Register(agent *Agent) (*Agent, *Response, error) { 38 var req *http.Request 39 var err error 40 if experiments.IsEnabled("msgpack") { 41 req, err = as.client.NewRequestWithMessagePack("POST", "register", agent) 42 } else { 43 req, err = as.client.NewRequest("POST", "register", agent) 44 } 45 46 if err != nil { 47 return nil, nil, err 48 } 49 50 a := new(Agent) 51 resp, err := as.client.Do(req, a) 52 if err != nil { 53 return nil, resp, err 54 } 55 56 return a, resp, err 57 } 58 59 // Connects the agent to the Buildkite Agent API 60 func (as *AgentsService) Connect() (*Response, error) { 61 req, err := as.client.NewRequest("POST", "connect", nil) 62 if err != nil { 63 return nil, err 64 } 65 66 return as.client.Do(req, nil) 67 } 68 69 // Disconnects the agent to the Buildkite Agent API 70 func (as *AgentsService) Disconnect() (*Response, error) { 71 req, err := as.client.NewRequest("POST", "disconnect", nil) 72 if err != nil { 73 return nil, err 74 } 75 76 return as.client.Do(req, nil) 77 }