Add postman to tui (#2895)

This commit is contained in:
Hon 2024-05-29 16:07:23 -07:00 committed by GitHub
parent 0024b6ce77
commit 793231370e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 100 additions and 11 deletions

View file

@ -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."),

View file

@ -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)
}

View file

@ -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