Commit fc4488da authored by Kamil Trzciński's avatar Kamil Trzciński 🔴

Added option to verify registered runners and possible delete the removed ones

parent 06647ab6
package commands
import (
"github.com/codegangsta/cli"
log "github.com/Sirupsen/logrus"
"github.com/ayufan/gitlab-ci-multi-runner/common"
)
func runVerify(c *cli.Context) {
config := &common.Config{}
err := config.LoadConfig(c.String("config"))
if err != nil {
log.Fatalln(err)
return
}
// verify if runner exist
runners := []*common.RunnerConfig{}
for _, runner := range config.Runners {
if common.VerifyRunner(runner.URL, runner.Token) {
runners = append(runners, runner)
}
}
if !c.Bool("delete") {
return
}
// check if anything changed
if len(config.Runners) == len(runners) {
return
}
config.Runners = runners
// save config file
err = config.SaveConfig(c.String("config"))
if err != nil {
log.Fatalln("Failed to update", c.String("config"), err)
}
log.Println("Updated", c.String("config"))
}
func init() {
common.RegisterCommand(cli.Command{
Name: "verify",
Usage: "verify all registered runners",
Action: runVerify,
Flags: []cli.Flag{
cli.StringFlag{
Name: "c, config",
Value: "config.toml",
Usage: "Config file",
EnvVar: "CONFIG_FILE",
},
cli.BoolFlag{
Name: "delete",
Usage: "Delete no longer existing runners?",
},
},
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment