Update Jenkins in tui (#2925)

This commit is contained in:
Hon 2024-06-05 18:34:01 -07:00 committed by GitHub
parent b0fd70c0ff
commit 4b3f834859
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 85 additions and 1 deletions

View file

@ -65,6 +65,7 @@ func New(c common.Common) *SourceSelect {
OssItem("Git", "Scan git repositories."), OssItem("Git", "Scan git repositories."),
OssItem("GitHub", "Scan GitHub repositories and/or organizations."), OssItem("GitHub", "Scan GitHub repositories and/or organizations."),
OssItem("Filesystem", "Scan your filesystem by selecting what directories to scan."), OssItem("Filesystem", "Scan your filesystem by selecting what directories to scan."),
OssItem("Jenkins", "Scan Jenkins, a CI/CD platform. (Recently open-sourced from enterprise!)"),
OssItem("Elasticsearch", "Scan your Elasticsearch cluster or Elastic Cloud instance."), OssItem("Elasticsearch", "Scan your Elasticsearch cluster or Elastic Cloud instance."),
OssItem("Postman", "Scan a collection, workspace, or environment from Postman, the API platform."), OssItem("Postman", "Scan a collection, workspace, or environment from Postman, the API platform."),
OssItem("GitLab", "Scan GitLab repositories."), OssItem("GitLab", "Scan GitLab repositories."),
@ -80,7 +81,6 @@ func New(c common.Common) *SourceSelect {
EnterpriseItem("Buildkite", "Scan Buildkite, a CI/CD platform."), EnterpriseItem("Buildkite", "Scan Buildkite, a CI/CD platform."),
EnterpriseItem("Confluence", "Scan Atlassian's web-based wiki and knowledge base."), EnterpriseItem("Confluence", "Scan Atlassian's web-based wiki and knowledge base."),
EnterpriseItem("Gerrit", "Scan Gerrit, a code collaboration tool"), EnterpriseItem("Gerrit", "Scan Gerrit, a code collaboration tool"),
EnterpriseItem("Jenkins ", "Scan Jenkins, a CI/CD platform."),
EnterpriseItem("Jira", "Scan Atlassian's issue & project tracking software."), EnterpriseItem("Jira", "Scan Atlassian's issue & project tracking software."),
EnterpriseItem("Slack", "Scan Slack, a messaging and communication platform."), EnterpriseItem("Slack", "Scan Slack, a messaging and communication platform."),
EnterpriseItem("Microsoft Teams", "Scan Microsoft Teams, a messaging and communication platform."), EnterpriseItem("Microsoft Teams", "Scan Microsoft Teams, a messaging and communication platform."),

View file

@ -0,0 +1,79 @@
package jenkins
import (
"strings"
"github.com/trufflesecurity/trufflehog/v3/pkg/tui/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/tui/components/textinputs"
)
type jenkinsCmdModel struct {
textinputs.Model
}
func GetNote() string {
return "If no username and password are provided, TruffleHog will attempt an unauthenticated Jenkins scan."
}
func GetFields() jenkinsCmdModel {
return jenkinsCmdModel{textinputs.New([]textinputs.InputConfig{
{
Label: "Endpoint URL",
Key: "url",
Required: true,
Help: "URL of the Jenkins server.",
Placeholder: "https://jenkins.example.com",
},
{
Label: "Username",
Key: "username",
Required: false,
Help: "For authenticated scans - pairs with password.",
},
{
Label: "Password",
Key: "password",
Required: false,
Help: "For authenticated scans - pairs with username.",
}})}
}
func checkIsAuthenticated(inputs map[string]textinputs.Input) bool {
username := inputs["username"].Value
password := inputs["password"].Value
return username != "" && password != ""
}
func (m jenkinsCmdModel) Cmd() string {
var command []string
command = append(command, "trufflehog", "jenkins")
inputs := m.GetInputs()
keys := []string{"url"}
if checkIsAuthenticated(inputs) {
keys = append(keys, "username", "password")
}
for _, key := range keys {
val, ok := inputs[key]
if !ok || val.Value == "" {
continue
}
command = append(command, "--"+key+"="+val.Value)
}
return strings.Join(command, " ")
}
func (m jenkinsCmdModel) Summary() string {
inputs := m.GetInputs()
labels := m.GetLabels()
summaryKeys := []string{"url"}
if checkIsAuthenticated(inputs) {
summaryKeys = append(summaryKeys, "username", "password")
}
return common.SummarizeSource(summaryKeys, inputs, labels)
}

View file

@ -12,6 +12,7 @@ import (
"github.com/trufflesecurity/trufflehog/v3/pkg/tui/sources/git" "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/github"
"github.com/trufflesecurity/trufflehog/v3/pkg/tui/sources/gitlab" "github.com/trufflesecurity/trufflehog/v3/pkg/tui/sources/gitlab"
"github.com/trufflesecurity/trufflehog/v3/pkg/tui/sources/jenkins"
"github.com/trufflesecurity/trufflehog/v3/pkg/tui/sources/postman" "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/s3"
"github.com/trufflesecurity/trufflehog/v3/pkg/tui/sources/syslog" "github.com/trufflesecurity/trufflehog/v3/pkg/tui/sources/syslog"
@ -26,6 +27,8 @@ func GetSourceNotes(sourceName string) string {
return postman.GetNote() return postman.GetNote()
case "elasticsearch": case "elasticsearch":
return elasticsearch.GetNote() return elasticsearch.GetNote()
case "jenkins":
return jenkins.GetNote()
default: default:
return "" return ""
@ -60,6 +63,8 @@ func GetSourceFields(sourceName string) CmdModel {
return github.GetFields() return github.GetFields()
case "gitlab": case "gitlab":
return gitlab.GetFields() return gitlab.GetFields()
case "jenkins":
return jenkins.GetFields()
case "postman": case "postman":
return postman.GetFields() return postman.GetFields()
case "syslog": case "syslog":