Skip to content

Commit

Permalink
Add obfuscators to wizard (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbauriedel authored Nov 18, 2024
1 parent 573a371 commit 5a97d3a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
45 changes: 43 additions & 2 deletions internal/config/wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ func (w *Wizard) AddStringVar(callback *string, name, defaultValue, usage string
})
}

// AddStringSliceVar adds argument for a string slice variable
// AddSliceVarFromString reads a single string from stdin. This string will be separated by ',' and the resulting slice will be returned
//
// callback: Variable to save the input to
// name: Internal name
// defaultValue: Default
// usage: usage string
// required: bool
// dependency: Add dependency function to validate if that argument will be added or not
func (w *Wizard) AddStringSliceVar(callback *[]string, name string, defaultValue []string, usage string, required bool, dependency func() bool) {
func (w *Wizard) AddSliceVarFromString(callback *[]string, name string, defaultValue []string, usage string, required bool, dependency func() bool) {
w.Arguments = append(w.Arguments, argument{
name: name,
inputFunction: func() {
Expand Down Expand Up @@ -128,6 +128,47 @@ func (w *Wizard) AddBoolVar(callback *bool, name string, defaultValue bool, usag
})
}

// AddStringSliceVar adds argument for a slice of strings.
//
// callback: Variable to save the input to
// name: Internal name
// defaultValue: Should that slice be collected via default?
// initialPrompt: The initial stdout message to ask if you want to collect
// inputPrompt: The recurring stdout message for each slice
// dependency: Add dependency function to validate if that argument will be added or not
func (w *Wizard) AddStringSliceVar(callback *[]string, name string, defaultValue bool, initialPrompt string, inputPrompt string, dependency func() bool) {
arg := argument{
name: name,
dependency: dependency,
}

arg.inputFunction = func() {
var (
collect bool
inputs []string
)

w.newBoolPrompt(&collect, defaultValue, initialPrompt)

if !collect {
return
}

for collect {
var input string

w.newStringPrompt(&input, inputPrompt, true)
inputs = append(inputs, input)

w.newBoolPrompt(&collect, false, "Collect more?")
}

*callback = inputs
}

w.Arguments = append(w.Arguments, arg)
}

func (w *Wizard) AddIcingaEndpoints(callback *[]icingaapi.Endpoint, name, usage string, dependency func() bool) {
w.Arguments = append(w.Arguments, argument{
name: name,
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,9 @@ func startConfigWizard(conf *config.Config) {

// Define arguments for interactive input via stdin
wizard.AddStringVar(&conf.General.OutputFile, "output", util.BuildFileName(), "Filename for resulting zip", true, nil)
wizard.AddStringSliceVar(&conf.General.EnabledModules, "enable", []string{"all"}, "Which modules should be enabled? (Comma separated list of modules)", false, nil)
wizard.AddSliceVarFromString(&conf.General.EnabledModules, "enable", []string{"all"}, "Which modules should be enabled? (Comma separated list of modules)", false, nil)
wizard.AddBoolVar(&detailedCollection, "detailed", true, "Enable detailed collection including logs and more (recommended)?", nil)
wizard.AddStringSliceVar(&conf.General.ExtraObfuscators, "obfuscators", false, "Do you want to define some custom obfuscators (passwords, secrets etc.)", "Add custom obfuscator", nil)

// Collect Icinga 2 API endpoints if module 'icinga2' is enabled
// Because we only add this when module 'icinga2' or 'all' is enabled, this needs to be after saving the enabled modules
Expand Down

0 comments on commit 5a97d3a

Please sign in to comment.