Skip to content

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

Open
hgresa24 wants to merge 1 commit into
SAP:masterfrom
hgresa24:feature/blackduck-custom-useragent
Open

set custom User-Agent header for BlackDuck API requests#5782
hgresa24 wants to merge 1 commit into
SAP:masterfrom
hgresa24:feature/blackduck-custom-useragent

Conversation

@hgresa24
Copy link
Copy Markdown
Contributor

@hgresa24 hgresa24 commented May 8, 2026

Description

This chang sets a custom User-Agent header to BlackDuck API requests so the server can identify that piper is calling it and which step. The User-Agent follows the format piper--, for example piper-detectExecuteScan-6bda91c.

  • Tests
  • Documentation
  • Inner source library needs updating

@hgresa24 hgresa24 requested a review from a team as a code owner May 8, 2026 12:04
@jitendk
Copy link
Copy Markdown
Contributor

jitendk commented May 8, 2026

/it-go

httpClient piperhttp.Sender
serverURL string
projectVersion *ProjectVersion
UserAgent string
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: UserAgent can be silently cleared by authenticate() JSON unmarshalling

The authenticate() method does json.Unmarshal(respBody, b), where b is a pointer to the Client struct. Because UserAgent has no json:"-" tag, if the BlackDuck authentication endpoint ever returns a JSON key that case-insensitively matches "useragent" (e.g. "UserAgent": ""), the field will be zeroed out, silently removing the custom User-Agent from all subsequent requests.

Even without that scenario today, the field should be marked json:"-" to make the intent explicit — this field is not part of the API contract with BlackDuck and must never be overwritten by deserializing a server response.

Consider adding the json:"-" tag to protect it

@piotrskindel-sap piotrskindel-sap force-pushed the feature/blackduck-custom-useragent branch from 625eb2c to 4e7975a Compare May 15, 2026 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants