Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/detectExecuteScan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/blackduck/blackduck.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ type Client struct {
httpClient piperhttp.Sender
serverURL string
projectVersion *ProjectVersion
UserAgent string
}

// NewClient creates a new BlackDuck client
Expand Down Expand Up @@ -543,6 +544,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)
Expand Down
Loading