-
Notifications
You must be signed in to change notification settings - Fork 1
/
unregister.go
68 lines (56 loc) · 1.46 KB
/
unregister.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package commands
import (
"github.com/codegangsta/cli"
log "github.com/Sirupsen/logrus"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/network"
)
type UnregisterCommand struct {
configOptions
common.RunnerCredentials
network common.Network
Name string `toml:"name" json:"name" short:"n" long:"name" description:"Name of the runner you wish to unregister"`
}
func (c *UnregisterCommand) Execute(context *cli.Context) {
userModeWarning(false)
err := c.loadConfig()
if err != nil {
log.Fatalln(err)
return
}
if len(c.Name) > 0 {
runnerConfig, err := c.RunnerByName(c.Name)
if err != nil {
log.Fatalln(err)
return
}
c.RunnerCredentials = runnerConfig.RunnerCredentials
}
if !c.network.DeleteRunner(c.RunnerCredentials) {
log.Fatalln("Failed to delete runner", c.Name)
return
}
runners := []*common.RunnerConfig{}
for _, otherRunner := range c.config.Runners {
if otherRunner.RunnerCredentials == c.RunnerCredentials {
continue
}
runners = append(runners, otherRunner)
}
// check if anything changed
if len(c.config.Runners) == len(runners) {
return
}
c.config.Runners = runners
// save config file
err = c.saveConfig()
if err != nil {
log.Fatalln("Failed to update", c.ConfigFile, err)
}
log.Println("Updated", c.ConfigFile)
}
func init() {
common.RegisterCommand2("unregister", "unregister specific runner", &UnregisterCommand{
network: &network.GitLabClient{},
})
}