mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-06-06 01:18:50 +00:00
Remove code to read agent-id.conf (#2009)
I want to have c805c87e90
published at
least for 2 days ...
... so the migration did happen
This commit is contained in:
parent
2e851ba4a0
commit
3a85559763
4 changed files with 15 additions and 35 deletions
|
@ -112,11 +112,6 @@ func run(c *cli.Context) error {
|
||||||
|
|
||||||
agentConfig := readAgentConfig(agentConfigPath)
|
agentConfig := readAgentConfig(agentConfigPath)
|
||||||
|
|
||||||
// deprecated
|
|
||||||
if agentConfig.AgentID == defaultAgentIDValue {
|
|
||||||
agentConfig.AgentID = readAgentID(c.String("agent-id-config-path"))
|
|
||||||
}
|
|
||||||
|
|
||||||
agentToken := c.String("grpc-token")
|
agentToken := c.String("grpc-token")
|
||||||
authClient := agentRpc.NewAuthGrpcClient(authConn, agentToken, agentConfig.AgentID)
|
authClient := agentRpc.NewAuthGrpcClient(authConn, agentToken, agentConfig.AgentID)
|
||||||
authInterceptor, err := agentRpc.NewAuthInterceptor(authClient, 30*time.Minute)
|
authInterceptor, err := agentRpc.NewAuthInterceptor(authClient, 30*time.Minute)
|
||||||
|
|
|
@ -19,7 +19,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"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
|
|
||||||
}
|
|
||||||
|
|
|
@ -30,17 +30,32 @@ func TestReadAgentIDFileExists(t *testing.T) {
|
||||||
if !assert.NoError(t, errTmpF) {
|
if !assert.NoError(t, errTmpF) {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
defer os.Remove(tmpF.Name())
|
||||||
|
|
||||||
|
// there is an existing config
|
||||||
errWrite := os.WriteFile(tmpF.Name(), []byte(`{"agent_id":3}`), 0o644)
|
errWrite := os.WriteFile(tmpF.Name(), []byte(`{"agent_id":3}`), 0o644)
|
||||||
if !assert.NoError(t, errWrite) {
|
if !assert.NoError(t, errWrite) {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// read existing config
|
||||||
actual := readAgentConfig(tmpF.Name())
|
actual := readAgentConfig(tmpF.Name())
|
||||||
assert.EqualValues(t, AgentConfig{3}, actual)
|
assert.EqualValues(t, AgentConfig{3}, actual)
|
||||||
|
|
||||||
|
// update existing config and check
|
||||||
actual.AgentID = 33
|
actual.AgentID = 33
|
||||||
writeAgentConfig(actual, tmpF.Name())
|
writeAgentConfig(actual, tmpF.Name())
|
||||||
actual = readAgentConfig(tmpF.Name())
|
actual = readAgentConfig(tmpF.Name())
|
||||||
assert.EqualValues(t, 33, actual.AgentID)
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,13 +208,4 @@ var flags = []cli.Flag{
|
||||||
Usage: "duration to wait before retrying to connect to the server",
|
Usage: "duration to wait before retrying to connect to the server",
|
||||||
Value: time.Second * 2,
|
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,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue