set custom User-Agent header for BlackDuck API requests (#5782)

This commit is contained in:
hgresa24
2026-06-15 12:30:34 +00:00
committed by GitHub
parent 28e2572016
commit b023a18c62
2 changed files with 10 additions and 0 deletions
+5
View File
@@ -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
}
+5
View File
@@ -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)