Skip to content

Commit

Permalink
Add postman to tui (#2895)
Browse files Browse the repository at this point in the history
  • Loading branch information
hxnyk committed May 29, 2024
1 parent 0024b6c commit 7932313
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 11 deletions.
3 changes: 2 additions & 1 deletion pkg/tui/pages/source_select/source_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
Expand Down
83 changes: 83 additions & 0 deletions pkg/tui/sources/postman/postman.go
Original file line number Diff line number Diff line change
@@ -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)
}
25 changes: 15 additions & 10 deletions pkg/tui/sources/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -20,6 +21,8 @@ func GetSourceNotes(sourceName string) string {
switch source {
case "github":
return github.GetNote()
case "postman":
return postman.GetNote()

default:
return ""
Expand All @@ -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
Expand Down

0 comments on commit 7932313

Please sign in to comment.