smaller json and fix header
All checks were successful
Pipeline was successful

This commit is contained in:
Tobias Trabelsi 2023-11-13 21:01:32 +01:00
parent 09c85fc3bd
commit 48b4b273ee
Signed by: lerentis
GPG Key ID: FF0C2839718CAF2E
2 changed files with 7 additions and 5 deletions

View File

@ -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"`
}

View File

@ -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()))
} }