mirror of
https://github.com/SAP/jenkins-library.git
synced 2026-06-19 22:58:55 +02:00
set custom User-Agent header for BlackDuck API requests (#5782)
This commit is contained in:
@@ -141,6 +141,11 @@ func newBlackduckSystem(config detectExecuteScanOptions) *blackduckSystem {
|
||||
sys := blackduckSystem{
|
||||
Client: bd.NewClient(config.Token, config.ServerURL, &piperhttp.Client{}),
|
||||
}
|
||||
commitShortSHA := "unknown"
|
||||
if len(GitCommit) >= 7 {
|
||||
commitShortSHA = GitCommit[:7]
|
||||
}
|
||||
sys.Client.UserAgent = fmt.Sprintf("piper-detectExecuteScan-%s", commitShortSHA)
|
||||
return &sys
|
||||
}
|
||||
|
||||
|
||||
@@ -250,6 +250,7 @@ type Client struct {
|
||||
httpClient piperhttp.Sender
|
||||
serverURL string
|
||||
projectVersion *ProjectVersion
|
||||
UserAgent string `json:"-"`
|
||||
}
|
||||
|
||||
// NewClient creates a new BlackDuck client
|
||||
@@ -599,6 +600,10 @@ func (b *Client) sendRequest(method, apiEndpoint string, params map[string]strin
|
||||
header.Add("Authorization", fmt.Sprintf("Bearer %v", b.BearerToken))
|
||||
}
|
||||
|
||||
if b.UserAgent != "" {
|
||||
header.Set("User-Agent", b.UserAgent)
|
||||
}
|
||||
|
||||
response, err := b.httpClient.SendRequest(method, blackDuckAPIUrl.String(), nil, header, nil)
|
||||
if err != nil {
|
||||
return responseBody, fmt.Errorf("request to BlackDuck API failed: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user