This commit is contained in:
parent
09c85fc3bd
commit
48b4b273ee
@ -90,3 +90,8 @@ type Agent struct {
|
|||||||
type AgentList struct {
|
type AgentList struct {
|
||||||
Agents []Agent
|
Agents []Agent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AgentRequest struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
NoSchedule bool `json:"no_schedule"`
|
||||||
|
}
|
||||||
|
@ -98,7 +98,7 @@ func ListAgents(cfg *config.Config) (*models.AgentList, error) {
|
|||||||
|
|
||||||
func CreateWoodpeckerAgent(cfg *config.Config) (*models.Agent, error) {
|
func CreateWoodpeckerAgent(cfg *config.Config) (*models.Agent, error) {
|
||||||
name := fmt.Sprintf("woodpecker-autoscaler-agent-%s", utils.RandStringBytes(5))
|
name := fmt.Sprintf("woodpecker-autoscaler-agent-%s", utils.RandStringBytes(5))
|
||||||
agentRequest := models.Agent{
|
agentRequest := models.AgentRequest{
|
||||||
Name: name,
|
Name: name,
|
||||||
NoSchedule: false,
|
NoSchedule: false,
|
||||||
}
|
}
|
||||||
@ -113,13 +113,10 @@ func CreateWoodpeckerAgent(cfg *config.Config) (*models.Agent, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New(fmt.Sprintf("Could not create agent request: %s", err.Error()))
|
return nil, errors.New(fmt.Sprintf("Could not create agent request: %s", err.Error()))
|
||||||
}
|
}
|
||||||
req.Header.Set("Accept", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", cfg.WoodpeckerApiToken))
|
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", cfg.WoodpeckerApiToken))
|
||||||
|
|
||||||
resp, err := http.DefaultClient.Do(req)
|
resp, err := http.DefaultClient.Do(req)
|
||||||
log.WithFields(log.Fields{
|
|
||||||
"Caller": "CreateWoodpeckerAgent",
|
|
||||||
}).Debugf("Response from woodpecker: %s", resp.Body)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New(fmt.Sprintf("Could not create new Agent: %s", err.Error()))
|
return nil, errors.New(fmt.Sprintf("Could not create new Agent: %s", err.Error()))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user