-
Notifications
You must be signed in to change notification settings - Fork 3
/
reset_cmd.go
88 lines (73 loc) · 2.13 KB
/
reset_cmd.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) R.I. Pienaar and the Choria Project contributors
//
// SPDX-License-Identifier: Apache-2.0
package machineroom
import (
"fmt"
"os"
"path/filepath"
"github.com/AlecAivazis/survey/v2"
"github.com/choria-io/fisk"
)
func (c *cliInstance) resetCommand(_ *fisk.ParseContext) error {
_, log, err := c.CommonConfigure()
if err != nil {
return err
}
opts := c.opts
log.Warnf("Ensure that the process is stopped prior to resetting")
if !c.force {
var ok bool
err = survey.AskOne(&survey.Confirm{
Message: fmt.Sprintf("Really reset the %s agent", opts.Name),
}, &ok)
if err != nil {
return err
}
if !ok {
fmt.Println("Cancelling reset operation")
return nil
}
}
log.Warnf("Removing state storage directory %s", opts.ServerStorageDirectory)
err = os.RemoveAll(opts.ServerStorageDirectory)
if err != nil {
log.Errorf("Could not remove storage directory: %v", err)
}
log.Warnf("Removing autonomous agent store %s", opts.MachinesDirectory)
err = os.RemoveAll(opts.MachinesDirectory)
if err != nil {
log.Errorf("Could not remove autonomous agent store: %v", err)
}
log.Warnf("Removing instance facts file %s", opts.FactsFile)
err = os.Remove(opts.FactsFile)
if err != nil {
log.Warnf("Could not remove facts file: %v", err)
}
log.Warnf("Removing JWT file %s", opts.ServerJWTFile)
err = os.Remove(opts.ServerJWTFile)
if err != nil {
log.Errorf("Could not remove jwt file: %v", err)
}
log.Warnf("Removing Seed file %s", opts.ServerJWTFile)
err = os.Remove(opts.ServerSeedFile)
if err != nil {
log.Errorf("Could not remove seed file: %v", err)
}
if opts.ConfigurationDirectory != "" {
for _, f := range []string{defaultCaFile, defaultCertFile, defaultKeyFile, defaultNatsNkeyFile, defaultNatsCredentialFile} {
path := filepath.Join(opts.ConfigurationDirectory, f)
log.Warnf("Removing x509 file %v", path)
err = os.Remove(path)
if err != nil {
log.Errorf("Could not remove %s: %v", f, err)
}
}
}
log.Warnf("Removing configuration file %v", c.cfgFile)
err = os.Remove(c.cfgFile)
if err != nil {
log.Warnf("Could not remove configuration file: %v", err)
}
return nil
}