diff --git a/cli/cmd/runner_register.go b/cli/cmd/runner_register.go index d83efce6..413d20af 100644 --- a/cli/cmd/runner_register.go +++ b/cli/cmd/runner_register.go @@ -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 {