Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
Add postman to tui (#2895)
Hon793231370e6c
diff --git a/pkg/tui/pages/source_select/source_select.go b/pkg/tui/pages/source_select/source_select.goindex 37cc77489..1cbafc752 100644--- a/pkg/tui/pages/source_select/source_select.go+++ b/pkg/tui/pages/source_select/source_select.go@@ -64,8 +64,9 @@ func New(c common.Common) *SourceSelect {// Open source sources.OssItem("Git", "Scan git repositories."),OssItem("GitHub", "Scan GitHub repositories and/or organizations."),- OssItem("GitLab", "Scan GitLab repositories."),OssItem("Filesystem", "Scan your filesystem by selecting what directories to scan."),+ OssItem("Postman", "Scan a collection, workspace, or environment from Postman, the API platform."),+ OssItem("GitLab", "Scan GitLab repositories."),OssItem("AWS S3", "Scan Amazon S3 buckets."),OssItem("CircleCI", "Scan CircleCI, a CI/CD platform."),OssItem("Syslog", "Scan syslog, event data logs."),diff --git a/pkg/tui/sources/postman/postman.go b/pkg/tui/sources/postman/postman.gonew file mode 100644index 000000000..7b0451f86--- /dev/null+++ b/pkg/tui/sources/postman/postman.go@@ -0,0 +1,83 @@+package postman++import (+ "strings"++ "github.com/trufflesecurity/trufflehog/v3/pkg/tui/common"+ "github.com/trufflesecurity/trufflehog/v3/pkg/tui/components/textinputs"+)++type postmanCmdModel struct {+ textinputs.Model+}++func GetNote() string {+ return "Please enter an ID for a workspace, collection, or environment."+}++func GetFields() postmanCmdModel {+ token := textinputs.InputConfig{+ Label: "Postman token",+ Key: "token",+ Required: true,+ Help: "Postman API key",+ Placeholder: "PMAK-",+ }+ workspace := textinputs.InputConfig{+ Label: "Workspace ID",+ Key: "workspace",+ Required: false,+ Help: "ID for workspace",+ }+ collection := textinputs.InputConfig{+ Label: "Collection ID",+ Key: "collection",+ Required: false,+ Help: "ID for an API collection",+ }+ environment := textinputs.InputConfig{+ Label: "Environment ID",+ Key: "environment",+ Required: false,+ Help: "ID for an environment",+ }++ return postmanCmdModel{textinputs.New([]textinputs.InputConfig{token, workspace, collection, environment})}+}++func findFirstNonEmptyKey(inputs map[string]textinputs.Input, keys []string) string {+ for _, key := range keys {+ if val, ok := inputs[key]; ok && val.Value != "" {+ return key+ }+ }+ return ""+}++func (m postmanCmdModel) Cmd() string {+ var command []string+ command = append(command, "trufflehog", "postman")++ inputs := m.GetInputs()+ keys := []string{"workspace", "collection", "environment"}++ command = append(command, "--token="+inputs["token"].Value)+ key := findFirstNonEmptyKey(inputs, keys)+ if key != "" {+ command = append(command, "--"+key+"="+inputs[key].Value)+ }+ return strings.Join(command, " ")+}++func (m postmanCmdModel) Summary() string {+ inputs := m.GetInputs()+ labels := m.GetLabels()+ keys := []string{"token", "workspace", "collection", "environment"}++ summaryKeys := []string{"token"}+ key := findFirstNonEmptyKey(inputs, keys[1:])+ if key != "" {+ summaryKeys = append(summaryKeys, key)+ }+ return common.SummarizeSource(summaryKeys, inputs, labels)+}diff --git a/pkg/tui/sources/sources.go b/pkg/tui/sources/sources.goindex 8269fcaf0..b65bf811f 100644--- a/pkg/tui/sources/sources.go+++ b/pkg/tui/sources/sources.go@@ -11,6 +11,7 @@ import ("github.com/trufflesecurity/trufflehog/v3/pkg/tui/sources/git""github.com/trufflesecurity/trufflehog/v3/pkg/tui/sources/github""github.com/trufflesecurity/trufflehog/v3/pkg/tui/sources/gitlab"+ "github.com/trufflesecurity/trufflehog/v3/pkg/tui/sources/postman""github.com/trufflesecurity/trufflehog/v3/pkg/tui/sources/s3""github.com/trufflesecurity/trufflehog/v3/pkg/tui/sources/syslog")@@ -20,6 +21,8 @@ func GetSourceNotes(sourceName string) string {switch source {case "github":return github.GetNote()+ case "postman":+ return postman.GetNote()default:return ""@@ -36,24 +39,26 @@ func GetSourceFields(sourceName string) CmdModel {source := strings.ToLower(sourceName)switch source {+ case "aws s3":+ return s3.GetFields()+ case "circleci":+ return circleci.GetFields()+ case "docker":+ return docker.GetFields()+ case "filesystem":+ return filesystem.GetFields()+ case "gcs (google cloud storage)":+ return gcs.GetFields()case "git":return git.GetFields()case "github":return github.GetFields()case "gitlab":return gitlab.GetFields()- case "filesystem":- return filesystem.GetFields()- case "aws s3":- return s3.GetFields()- case "gcs (google cloud storage)":- return gcs.GetFields()+ case "postman":+ return postman.GetFields()case "syslog":return syslog.GetFields()- case "circleci":- return circleci.GetFields()- case "docker":- return docker.GetFields()}return nil