Files
trufflehog/pkg/tui/pages/source_configure/trufflehog_configure.go
Richard Gomez f5025fd382
Lint / golangci-lint (push) Waiting to run
Lint / semgrep (push) Waiting to run
Release / Release (push) Waiting to run
Scan for secrets / test (push) Waiting to run
Snifftest / Run Snifftest (push) Waiting to run
Test / test (push) Waiting to run
Test / test-community (push) Waiting to run
Add --results flag (#2372)
This is a follow-up to #2107 and #2335. It adds a new (hidden) --results flag that allows a user to show any combination of verified, unverified, and indeterminate secrets.
2024-03-15 10:19:31 -04:00

117 lines
2.9 KiB
Go

package source_configure
import (
"runtime"
"strconv"
"strings"
"github.com/trufflesecurity/trufflehog/v3/pkg/tui/components/textinputs"
)
type truffleCmdModel struct {
textinputs.Model
}
func GetTrufflehogConfiguration() truffleCmdModel {
verification := textinputs.InputConfig{
Label: "Skip Verification",
Key: "no-verification",
Required: false,
Help: "Check if a suspected secret is real or not",
Placeholder: "false",
}
verifiedResults := textinputs.InputConfig{
Label: "Verified results",
Key: "only-verified",
Required: false,
Help: "Return only verified results",
Placeholder: "false",
}
jsonOutput := textinputs.InputConfig{
Label: "JSON output",
Key: "json",
Required: false,
Help: "Output results to JSON",
Placeholder: "false",
}
excludeDetectors := textinputs.InputConfig{
Label: "Exclude detectors",
Key: "exclude_detectors",
Required: false,
Help: "Comma separated list of detector types to exclude. Protobuf name or IDs may be used, as well as ranges. IDs defined here take precedence over the include list.",
Placeholder: "",
}
concurrency := textinputs.InputConfig{
Label: "Concurrency",
Key: "concurrency",
Required: false,
Help: "Number of concurrent workers.",
Placeholder: strconv.Itoa(runtime.NumCPU()),
}
return truffleCmdModel{textinputs.New([]textinputs.InputConfig{jsonOutput, verification, verifiedResults, excludeDetectors, concurrency}).SetSkip(true)}
}
func (m truffleCmdModel) Cmd() string {
var command []string
inputs := m.GetInputs()
if isTrue(inputs["json"].Value) {
command = append(command, "--json")
}
if isTrue(inputs["no-verification"].Value) {
command = append(command, "--no-verification")
}
if isTrue(inputs["only-verified"].Value) {
command = append(command, "--results=verified")
}
if inputs["exclude_detectors"].Value != "" {
cmd := "--exclude-detectors=" + strings.ReplaceAll(inputs["exclude_detectors"].Value, " ", "")
command = append(command, cmd)
}
if inputs["concurrency"].Value != "" {
command = append(command, "--concurrency="+inputs["concurrency"].Value)
}
return strings.Join(command, " ")
}
func (m truffleCmdModel) Summary() string {
summary := strings.Builder{}
keys := []string{"no-verification", "only-verified", "json", "exclude_detectors", "concurrency"}
inputs := m.GetInputs()
labels := m.GetLabels()
for _, key := range keys {
if inputs[key].Value != "" {
summary.WriteString("\t" + labels[key] + ": " + inputs[key].Value + "\n")
}
}
if summary.Len() == 0 {
summary.WriteString("\tRunning with defaults\n")
}
summary.WriteString("\n")
return summary.String()
}
func isTrue(val string) bool {
value := strings.ToLower(val)
isTrue, _ := strconv.ParseBool(value)
if isTrue || value == "yes" || value == "y" {
return true
}
return false
}