github.com/discordapp/buildkite-agent@v2.6.6+incompatible/api/agents.go (about)

     1  package api
     2  
     3  // AgentsService handles communication with the agent related methods of the
     4  // Buildkite Agent API.
     5  type AgentsService struct {
     6  	client *Client
     7  }
     8  
     9  // Agent represents an agent on the Buildkite Agent API
    10  type Agent struct {
    11  	Name              string   `json:"name"`
    12  	AccessToken       string   `json:"access_token"`
    13  	Hostname          string   `json:"hostname"`
    14  	Endpoint          string   `json:"endpoint"`
    15  	PingInterval      int      `json:"ping_interval"`
    16  	HearbeatInterval  int      `json:"heartbeat_interval"`
    17  	OS                string   `json:"os"`
    18  	Arch              string   `json:"arch"`
    19  	ScriptEvalEnabled bool     `json:"script_eval_enabled"`
    20  	Priority          string   `json:"priority,omitempty"`
    21  	Version           string   `json:"version"`
    22  	Build             string   `json:"build"`
    23  	MetaData          []string `json:"meta_data"`
    24  	PID               int      `json:"pid,omitempty"`
    25  }
    26  
    27  // Registers the agent against the Buildktie Agent API. The client for this
    28  // call must be authenticated using an Agent Registration Token
    29  func (as *AgentsService) Register(agent *Agent) (*Agent, *Response, error) {
    30  	req, err := as.client.NewRequest("POST", "register", agent)
    31  	if err != nil {
    32  		return nil, nil, err
    33  	}
    34  
    35  	a := new(Agent)
    36  	resp, err := as.client.Do(req, a)
    37  	if err != nil {
    38  		return nil, resp, err
    39  	}
    40  
    41  	return a, resp, err
    42  }
    43  
    44  // Connects the agent to the Buildkite Agent API
    45  func (as *AgentsService) Connect() (*Response, error) {
    46  	req, err := as.client.NewRequest("POST", "connect", nil)
    47  	if err != nil {
    48  		return nil, err
    49  	}
    50  
    51  	return as.client.Do(req, nil)
    52  }
    53  
    54  // Disconnects the agent to the Buildkite Agent API
    55  func (as *AgentsService) Disconnect() (*Response, error) {
    56  	req, err := as.client.NewRequest("POST", "disconnect", nil)
    57  	if err != nil {
    58  		return nil, err
    59  	}
    60  
    61  	return as.client.Do(req, nil)
    62  }