From 3a85559763a5a9df197ffc04a4c22294ccf5097b Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 19 Jul 2023 22:09:06 +0200 Subject: [PATCH] Remove code to read agent-id.conf (#2009) I want to have c805c87e9035898e712c918cbbdda9c4394013e5 published at least for 2 days ... ... so the migration did happen --- cmd/agent/agent.go | 5 ----- cmd/agent/config.go | 21 --------------------- cmd/agent/config_test.go | 15 +++++++++++++++ cmd/agent/flags.go | 9 --------- 4 files changed, 15 insertions(+), 35 deletions(-) diff --git a/cmd/agent/agent.go b/cmd/agent/agent.go index 96f1b23be..a83d5c627 100644 --- a/cmd/agent/agent.go +++ b/cmd/agent/agent.go @@ -112,11 +112,6 @@ func run(c *cli.Context) error { agentConfig := readAgentConfig(agentConfigPath) - // deprecated - if agentConfig.AgentID == defaultAgentIDValue { - agentConfig.AgentID = readAgentID(c.String("agent-id-config-path")) - } - agentToken := c.String("grpc-token") authClient := agentRpc.NewAuthGrpcClient(authConn, agentToken, agentConfig.AgentID) authInterceptor, err := agentRpc.NewAuthInterceptor(authClient, 30*time.Minute) diff --git a/cmd/agent/config.go b/cmd/agent/config.go index 776612237..1b6ef3b5e 100644 --- a/cmd/agent/config.go +++ b/cmd/agent/config.go @@ -19,7 +19,6 @@ import ( "bytes" "encoding/json" "os" - "strconv" "strings" "github.com/rs/zerolog/log" @@ -72,23 +71,3 @@ func writeAgentConfig(conf AgentConfig, agentConfigPath string) { } } } - -// deprecated -func readAgentID(agentIDConfigPath string) int64 { - const defaultAgentIDValue = int64(-1) - - rawAgentID, fileErr := os.ReadFile(agentIDConfigPath) - if fileErr != nil { - log.Debug().Err(fileErr).Msgf("could not open agent-id config file from %s", agentIDConfigPath) - return defaultAgentIDValue - } - - strAgentID := strings.TrimSpace(string(rawAgentID)) - agentID, parseErr := strconv.ParseInt(strAgentID, 10, 64) - if parseErr != nil { - log.Warn().Err(parseErr).Msg("could not parse agent-id config file content to int64") - return defaultAgentIDValue - } - - return agentID -} diff --git a/cmd/agent/config_test.go b/cmd/agent/config_test.go index 5e8219ed2..6ae724e1a 100644 --- a/cmd/agent/config_test.go +++ b/cmd/agent/config_test.go @@ -30,17 +30,32 @@ func TestReadAgentIDFileExists(t *testing.T) { if !assert.NoError(t, errTmpF) { t.FailNow() } + defer os.Remove(tmpF.Name()) + // there is an existing config errWrite := os.WriteFile(tmpF.Name(), []byte(`{"agent_id":3}`), 0o644) if !assert.NoError(t, errWrite) { t.FailNow() } + // read existing config actual := readAgentConfig(tmpF.Name()) assert.EqualValues(t, AgentConfig{3}, actual) + // update existing config and check actual.AgentID = 33 writeAgentConfig(actual, tmpF.Name()) actual = readAgentConfig(tmpF.Name()) assert.EqualValues(t, 33, actual.AgentID) + + tmpF2, errTmpF := os.CreateTemp("", "tmp_") + if !assert.NoError(t, errTmpF) { + t.FailNow() + } + defer os.Remove(tmpF2.Name()) + + // write new config + writeAgentConfig(actual, tmpF2.Name()) + actual = readAgentConfig(tmpF2.Name()) + assert.EqualValues(t, 33, actual.AgentID) } diff --git a/cmd/agent/flags.go b/cmd/agent/flags.go index 5e6125b62..e814ac5db 100644 --- a/cmd/agent/flags.go +++ b/cmd/agent/flags.go @@ -208,13 +208,4 @@ var flags = []cli.Flag{ Usage: "duration to wait before retrying to connect to the server", Value: time.Second * 2, }, - - // DEPRECATED - &cli.StringFlag{ - EnvVars: []string{"WOODPECKER_AGENT_ID_FILE"}, - Name: "agent-id-config-path", - Usage: "agent-id config file path", - Value: "/etc/woodpecker/agent-id.conf", - Hidden: true, - }, }