feat(runner): support flag --stdin-registration-token

This commit is contained in:
Denis Gukov 2024-10-13 09:26:22 +00:00
parent 2efef31213
commit 151106ac3f

View File

@ -1,18 +1,40 @@
package cmd
import (
"io"
"os"
"github.com/ansible-semaphore/semaphore/services/runners"
"github.com/ansible-semaphore/semaphore/util"
"github.com/spf13/cobra"
)
var runnerRegisterArgs struct {
stdinRegistrationToken bool
}
func init() {
runnerRegisterCmd.PersistentFlags().BoolVar(&runnerRegisterArgs.stdinRegistrationToken, "stdin-registration-token", false, "Read registration token from stdin")
runnerCmd.AddCommand(runnerRegisterCmd)
}
func registerRunner() {
util.ConfigInit(configPath, noConfig)
if runnerRegisterArgs.stdinRegistrationToken {
tokenBytes, err := io.ReadAll(os.Stdin)
if err != nil {
panic(err)
}
if len(tokenBytes) == 0 {
panic("Empty token")
}
util.Config.Runner.Token = string(tokenBytes)
}
taskPool := runners.JobPool{}
err := taskPool.Register()
if err != nil {