From 48b4b273eec7f62016f5f935c0c5bcc66f34a0a0 Mon Sep 17 00:00:00 2001 From: Tobias Trabelsi Date: Mon, 13 Nov 2023 21:01:32 +0100 Subject: [PATCH] smaller json and fix header --- internal/models/structs.go | 5 +++++ internal/woodpecker/agent.go | 7 ++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/models/structs.go b/internal/models/structs.go index 34670bc..6fa50d1 100644 --- a/internal/models/structs.go +++ b/internal/models/structs.go @@ -90,3 +90,8 @@ type Agent struct { type AgentList struct { Agents []Agent } + +type AgentRequest struct { + Name string `json:"name"` + NoSchedule bool `json:"no_schedule"` +} diff --git a/internal/woodpecker/agent.go b/internal/woodpecker/agent.go index f0cfac5..2195b53 100644 --- a/internal/woodpecker/agent.go +++ b/internal/woodpecker/agent.go @@ -98,7 +98,7 @@ func ListAgents(cfg *config.Config) (*models.AgentList, error) { func CreateWoodpeckerAgent(cfg *config.Config) (*models.Agent, error) { name := fmt.Sprintf("woodpecker-autoscaler-agent-%s", utils.RandStringBytes(5)) - agentRequest := models.Agent{ + agentRequest := models.AgentRequest{ Name: name, NoSchedule: false, } @@ -113,13 +113,10 @@ func CreateWoodpeckerAgent(cfg *config.Config) (*models.Agent, error) { if err != nil { 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)) resp, err := http.DefaultClient.Do(req) - log.WithFields(log.Fields{ - "Caller": "CreateWoodpeckerAgent", - }).Debugf("Response from woodpecker: %s", resp.Body) if err != nil { return nil, errors.New(fmt.Sprintf("Could not create new Agent: %s", err.Error())) }