Merge pull request #6145 from projectdiscovery/jira-improvements

feat: added bearer support to jira reporting for self hosted + misc
This commit is contained in:
Ice3man 2025-04-03 19:13:02 +05:30 committed by GitHub
commit 566b1f9860
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,6 +3,7 @@ package jira
import ( import (
"fmt" "fmt"
"io" "io"
"net/http"
"net/url" "net/url"
"strings" "strings"
"sync" "sync"
@ -68,9 +69,12 @@ type Options struct {
// AccountID is the accountID of the jira user. // AccountID is the accountID of the jira user.
AccountID string `yaml:"account-id" json:"account_id" validate:"required"` AccountID string `yaml:"account-id" json:"account_id" validate:"required"`
// Email is the email of the user for jira instance // Email is the email of the user for jira instance
Email string `yaml:"email" json:"email" validate:"required,email"` Email string `yaml:"email" json:"email"`
// PersonalAccessToken is the personal access token for jira instance.
// If this is set, Bearer Auth is used instead of Basic Auth.
PersonalAccessToken string `yaml:"personal-access-token" json:"personal_access_token"`
// Token is the token for jira instance. // Token is the token for jira instance.
Token string `yaml:"token" json:"token" validate:"required"` Token string `yaml:"token" json:"token"`
// ProjectName is the name of the project. // ProjectName is the name of the project.
ProjectName string `yaml:"project-name" json:"project_name"` ProjectName string `yaml:"project-name" json:"project_name"`
// ProjectID is the ID of the project (optional) // ProjectID is the ID of the project (optional)
@ -103,14 +107,28 @@ func New(options *Options) (*Integration, error) {
if !options.Cloud { if !options.Cloud {
username = options.AccountID username = options.AccountID
} }
tp := jira.BasicAuthTransport{
Username: username, var httpclient *http.Client
Password: options.Token, if options.PersonalAccessToken != "" {
bearerTp := jira.BearerAuthTransport{
Token: options.PersonalAccessToken,
}
if options.HttpClient != nil {
bearerTp.Transport = options.HttpClient.HTTPClient.Transport
}
httpclient = bearerTp.Client()
} else {
basicTp := jira.BasicAuthTransport{
Username: username,
Password: options.Token,
}
if options.HttpClient != nil {
basicTp.Transport = options.HttpClient.HTTPClient.Transport
}
httpclient = basicTp.Client()
} }
if options.HttpClient != nil {
tp.Transport = options.HttpClient.HTTPClient.Transport jiraClient, err := jira.NewClient(httpclient, options.URL)
}
jiraClient, err := jira.NewClient(tp.Client(), options.URL)
if err != nil { if err != nil {
return nil, err return nil, err
} }