mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-03 06:08:42 +00:00
Add agent functions (#1754)
This commit is contained in:
parent
3605979df0
commit
1f9d943564
3 changed files with 83 additions and 0 deletions
|
@ -54,6 +54,9 @@ const (
|
|||
pathPipelineQueue = "%s/api/pipelines"
|
||||
pathQueue = "%s/api/queue"
|
||||
pathLogLevel = "%s/api/log-level"
|
||||
pathAgents = "%s/api/agents"
|
||||
pathAgent = "%s/api/agents/%d"
|
||||
pathAgentTasks = "%s/api/agents/%d/tasks"
|
||||
// TODO: implement endpoints
|
||||
// pathFeed = "%s/api/user/feed"
|
||||
// pathVersion = "%s/version"
|
||||
|
@ -515,6 +518,41 @@ func (c *client) CronGet(owner, repo string, cronID int64) (*Cron, error) {
|
|||
return out, c.get(uri, out)
|
||||
}
|
||||
|
||||
func (c *client) AgentList() ([]*Agent, error) {
|
||||
out := make([]*Agent, 0, 5)
|
||||
uri := fmt.Sprintf(pathAgents, c.addr)
|
||||
return out, c.get(uri, &out)
|
||||
}
|
||||
|
||||
func (c *client) Agent(agentID int64) (*Agent, error) {
|
||||
out := new(Agent)
|
||||
uri := fmt.Sprintf(pathAgent, c.addr, agentID)
|
||||
return out, c.get(uri, out)
|
||||
}
|
||||
|
||||
func (c *client) AgentCreate(in *Agent) (*Agent, error) {
|
||||
out := new(Agent)
|
||||
uri := fmt.Sprintf(pathAgents, c.addr)
|
||||
return out, c.post(uri, in, out)
|
||||
}
|
||||
|
||||
func (c *client) AgentUpdate(in *Agent) (*Agent, error) {
|
||||
out := new(Agent)
|
||||
uri := fmt.Sprintf(pathAgent, c.addr, in.ID)
|
||||
return out, c.patch(uri, in, out)
|
||||
}
|
||||
|
||||
func (c *client) AgentDelete(agentID int64) error {
|
||||
uri := fmt.Sprintf(pathAgent, c.addr, agentID)
|
||||
return c.delete(uri)
|
||||
}
|
||||
|
||||
func (c *client) AgentTasksList(agentID int64) ([]*Task, error) {
|
||||
out := make([]*Task, 0, 5)
|
||||
uri := fmt.Sprintf(pathAgentTasks, c.addr, agentID)
|
||||
return out, c.get(uri, &out)
|
||||
}
|
||||
|
||||
//
|
||||
// http request helper functions
|
||||
//
|
||||
|
|
|
@ -198,4 +198,22 @@ type Client interface {
|
|||
|
||||
// CronUpdate update an existing cron job of a repo
|
||||
CronUpdate(owner, repo string, cron *Cron) (*Cron, error)
|
||||
|
||||
// AgentList returns a list of all registered agents
|
||||
AgentList() ([]*Agent, error)
|
||||
|
||||
// Agent returns an agent by id
|
||||
Agent(int64) (*Agent, error)
|
||||
|
||||
// AgentCreate creates a new agent
|
||||
AgentCreate(*Agent) (*Agent, error)
|
||||
|
||||
// AgentUpdate updates an existing agent
|
||||
AgentUpdate(*Agent) (*Agent, error)
|
||||
|
||||
// AgentDelete deletes an agent
|
||||
AgentDelete(int64) error
|
||||
|
||||
// AgentTasksList returns a list of all tasks executed by an agent
|
||||
AgentTasksList(int64) ([]*Task, error)
|
||||
}
|
||||
|
|
|
@ -196,4 +196,31 @@ type (
|
|||
Branch string `json:"branch"`
|
||||
Variables map[string]string `json:"variables"`
|
||||
}
|
||||
|
||||
// Agent is the JSON data for an agent
|
||||
Agent struct {
|
||||
ID int64 `json:"id"`
|
||||
Created int64 `json:"created"`
|
||||
Updated int64 `json:"updated"`
|
||||
Name string `json:"name"`
|
||||
OwnerID int64 `json:"owner_id"`
|
||||
Token string `json:"token"`
|
||||
LastContact int64 `json:"last_contact"`
|
||||
Platform string `json:"platform"`
|
||||
Backend string `json:"backend"`
|
||||
Capacity int32 `json:"capacity"`
|
||||
Version string `json:"version"`
|
||||
NoSchedule bool `json:"no_schedule"`
|
||||
}
|
||||
|
||||
// Task is the JSON data for a task
|
||||
Task struct {
|
||||
ID string `json:"id"`
|
||||
Data []byte `json:"data"`
|
||||
Labels map[string]string `json:"labels"`
|
||||
Dependencies []string `json:"dependencies"`
|
||||
RunOn []string `json:"run_on"`
|
||||
DepStatus map[string]string `json:"dep_status"`
|
||||
AgentID int64 `json:"agent_id"`
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue