Skip to content

Find, verify, and analyze leaked credentials

Analyzer capitalization (#3188)

Honab8c843fec86
diff --git a/pkg/analyzer/analyzers/analyzers.go b/pkg/analyzer/analyzers/analyzers.go
index d33c0185b..6b0473425 100644
--- a/pkg/analyzer/analyzers/analyzers.go
+++ b/pkg/analyzer/analyzers/analyzers.go
@@ -64,26 +64,26 @@ const (
// selection. TODO: Change slice type to Analyzer interface when all available
// analyzers implement it.
var AvailableAnalyzers = []string{
- "airbrake",
- "asana",
- "bitbucket",
- "github",
- "gitlab",
- "huggingface",
- "mailchimp",
- "mailgun",
- "mysql",
- "openai",
- "opsgenie",
- "postgres",
- "postman",
- "sendgrid",
- "shopify",
- "slack",
- "sourcegraph",
- "square",
- "stripe",
- "twilio",
+ "Airbrake",
+ "Asana",
+ "Bitbucket",
+ "GitHub",
+ "GitLab",
+ "HuggingFace",
+ "Mailchimp",
+ "Mailgun",
+ "MySQL",
+ "OpenAI",
+ "Opsgenie",
+ "Postgres",
+ "Postman",
+ "Sendgrid",
+ "Shopify",
+ "Slack",
+ "Sourcegraph",
+ "Square",
+ "Stripe",
+ "Twilio",
}
type PermissionStatus struct {
diff --git a/pkg/analyzer/cli.go b/pkg/analyzer/cli.go
index bc94ccb8a..677dbc6f1 100644
--- a/pkg/analyzer/cli.go
+++ b/pkg/analyzer/cli.go
@@ -42,7 +42,12 @@ func Command(app *kingpin.Application) *kingpin.CmdClause {
"Type of key to analyze. Omit to interactively choose. Available key types: %s",
strings.Join(analyzers.AvailableAnalyzers, ", "),
)
- analyzeKeyType = cli.Arg("key-type", keyTypeHelp).Enum(analyzers.AvailableAnalyzers...)
+ // Lowercase the available analyzers.
+ availableAnalyzers := make([]string, len(analyzers.AvailableAnalyzers))
+ for i, a := range analyzers.AvailableAnalyzers {
+ availableAnalyzers[i] = strings.ToLower(a)
+ }
+ analyzeKeyType = cli.Arg("key-type", keyTypeHelp).Enum(availableAnalyzers...)
return cli
}
@@ -56,7 +61,7 @@ func Run(cmd string) {
if secretInfo.Cfg == nil {
secretInfo.Cfg = &config.Config{}
}
- switch keyType {
+ switch strings.ToLower(keyType) {
case "github":
github.AnalyzeAndPrintPermissions(secretInfo.Cfg, secretInfo.Parts["key"])
case "sendgrid":
diff --git a/pkg/analyzer/tui/form.go b/pkg/analyzer/tui/form.go
index e7d1c8cb8..0c71c4ffd 100644
--- a/pkg/analyzer/tui/form.go
+++ b/pkg/analyzer/tui/form.go
@@ -3,6 +3,7 @@ package tui
import (
"fmt"
"slices"
+ "strings"
"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
@@ -21,7 +22,7 @@ type FormPage struct {
func NewFormPage(c *common.Common, keyType string) FormPage {
var inputs []textinputs.InputConfig
- switch keyType {
+ switch strings.ToLower(keyType) {
case "twilio":
inputs = []textinputs.InputConfig{{
Label: "SID",
@@ -62,7 +63,7 @@ func NewFormPage(c *common.Common, keyType string) FormPage {
form := textinputs.New(inputs).
SetHeader(titleStyle.Render(fmt.Sprintf("Configuring %s analyzer", keyType))).
- SetFooter("⚠️ Running TruffleHog Analyze will send a lot of requests ⚠️").
+ SetFooter("⚠️ Running TruffleHog Analyze will send a lot of requests ⚠️\n\n🚧 Please confirm you have permission to run TruffleHog Analyze against this secret 🚧").
SetSubmitMsg("Run TruffleHog Analyze")
return FormPage{
Common: c,
diff --git a/pkg/analyzer/tui/tui.go b/pkg/analyzer/tui/tui.go
index 2472c6a49..c06f6411a 100644
--- a/pkg/analyzer/tui/tui.go
+++ b/pkg/analyzer/tui/tui.go
@@ -3,7 +3,7 @@ package tui
import (
"errors"
"fmt"
- "slices"
+ "strings"
tea "github.com/charmbracelet/bubbletea"
"github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/analyzers"
@@ -31,7 +31,15 @@ var AbortError error = errors.New("command aborted")
func Run(keyType string) (string, *SecretInfo, error) {
// If a keyType is provided, make sure it's in the list of AvailableAnalyzers.
if keyType != "" {
- if _, ok := slices.BinarySearch(analyzers.AvailableAnalyzers, keyType); !ok {
+ var found bool
+ for _, a := range analyzers.AvailableAnalyzers {
+ if strings.EqualFold(a, keyType) {
+ keyType = a
+ found = true
+ break
+ }
+ }
+ if !found {
return "", nil, fmt.Errorf("Unrecognized command %q", keyType)
}
}