mirror of
https://github.com/trufflesecurity/trufflehog.git
synced 2024-11-10 07:04:24 +00:00
Analyzer capitalization (#3188)
* capitalization * Lowercase analyze labels for the subcommand * Canonicalize input and lowercase when matching command * add warning --------- Co-authored-by: Miccah Castorina <m.castorina93@gmail.com>
This commit is contained in:
parent
a8777fcad9
commit
ab8c843fec
4 changed files with 40 additions and 26 deletions
|
@ -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 {
|
||||
|
|
|
@ -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":
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue