/
settings.go
110 lines (84 loc) · 2.59 KB
/
settings.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package cli
import (
"fmt"
"os"
"github.com/github/vulcanizer"
"github.com/spf13/cobra"
)
func init() {
setupReloadSecureCommand()
rootCmd.AddCommand(cmdSettings)
}
func setupReloadSecureCommand() {
cmdSettingsReloadSecure.Flags().StringP("keystore_password", "", "", "Keystore password to reload the secure settings if enabled")
cmdSettings.AddCommand(cmdSettingsReloadSecure)
}
func printSettings(settings []vulcanizer.Setting, name string) {
if len(settings) == 0 {
fmt.Printf("No %s are set.\n", name)
return
}
header := []string{name, "Value"}
rows := [][]string{}
for _, setting := range settings {
row := []string{
setting.Setting,
setting.Value,
}
rows = append(rows, row)
}
table := renderTable(rows, header)
fmt.Println(table)
}
var cmdSettings = &cobra.Command{
Use: "settings",
Short: "Display all the settings of the cluster.",
Long: `This command displays all the transient and persistent settings that have been set on the given cluster.`,
Run: func(cmd *cobra.Command, args []string) {
v := getClient()
clusterSettings, err := v.GetClusterSettings()
if err != nil {
fmt.Printf("Error getting settings: %s\n", err)
os.Exit(1)
}
printSettings(clusterSettings.PersistentSettings, "persistent settings")
printSettings(clusterSettings.TransientSettings, "transient settings")
},
}
var cmdSettingsReloadSecure = &cobra.Command{
Use: "reload",
Short: "Reload the secure settings.",
Long: `This command calls the reload secure settings API on all nodes.`,
Run: func(cmd *cobra.Command, args []string) {
v := getClient()
password, err := cmd.Flags().GetString("keystore_password")
if err != nil {
fmt.Printf("Could not retrieve required argument: keystore_password. Error: %s\n", err)
os.Exit(1)
}
var reloadResponse vulcanizer.ReloadSecureSettingsResponse
var reloadError error
if password == "" {
reloadResponse, reloadError = v.ReloadSecureSettings()
} else {
reloadResponse, reloadError = v.ReloadSecureSettingsWithPassword(password)
}
if reloadError != nil {
fmt.Printf("Error reloading secure settings settings: %s\n", reloadError)
os.Exit(1)
}
header := []string{"Node", "Reload status"}
rows := [][]string{}
for _, node := range reloadResponse.Nodes {
row := []string{node.Name}
if node.ReloadException == nil {
row = append(row, "Successfully reloaded")
} else {
row = append(row, fmt.Sprintf("Exception type: %s, reason: %s", node.ReloadException.Type, node.ReloadException.Reason))
}
rows = append(rows, row)
}
table := renderTable(rows, header)
fmt.Println(table)
},
}