fix(release): outside services see the build's real version in Minstrel's User-Agent (#8129)
release / web (push) Successful in 1m37s
release / go (push) Successful in 2m1s
release / govulncheck (push) Successful in 19s
release / integration (push) Failing after 4m20s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 3m47s
release / android (push) Canceled after 4m27s
release / web (push) Successful in 1m37s
release / go (push) Successful in 2m1s
release / govulncheck (push) Successful in 19s
release / integration (push) Failing after 4m20s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 3m47s
release / android (push) Canceled after 4m27s
MusicBrainz, the Cover Art Archive and AcoustID ask a client to name itself with a version and a contact. Minstrel sent three different strings: Minstrel/1.0 to MusicBrainz, Minstrel/dev to the Cover Art Archive and no version at all to AcoustID, whatever the build. All three now come from buildinfo.UserAgent, which carries buildinfo.Version and the operator's contact address when one is configured, else the project URL. ProjectURL is that one place to repoint when the project moves (#7897). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -210,15 +210,11 @@ func run() error {
|
|||||||
acoustIDLookup := library.NewAcoustIDLookupWorker(pool, logger.With("component", "acoustid_lookup"),
|
acoustIDLookup := library.NewAcoustIDLookupWorker(pool, logger.With("component", "acoustid_lookup"),
|
||||||
acoustIDSettings, acoustIDClient)
|
acoustIDSettings, acoustIDClient)
|
||||||
|
|
||||||
contact := cfg.Library.ContactEmail
|
|
||||||
if contact == "" {
|
|
||||||
contact = "https://git.fabledsword.com/bvandeusen/minstrel"
|
|
||||||
}
|
|
||||||
// Swap in the production User-Agent + MinPeriod on the registered
|
// Swap in the production User-Agent + MinPeriod on the registered
|
||||||
// MBCAA provider. init() registered it with default config; this
|
// MBCAA provider. init() registered it with default config; this
|
||||||
// updates the running instance.
|
// updates the running instance.
|
||||||
coverart.NewMBCAAProviderFromConfig(coverart.FetcherConfig{
|
coverart.NewMBCAAProviderFromConfig(coverart.FetcherConfig{
|
||||||
UserAgent: fmt.Sprintf("Minstrel/dev (%s)", contact),
|
UserAgent: buildinfo.UserAgent(cfg.Library.ContactEmail),
|
||||||
MinPeriod: time.Second,
|
MinPeriod: time.Second,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.fabledsword.com/bvandeusen/minstrel/internal/buildinfo"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultBaseURL is the lookup endpoint.
|
// DefaultBaseURL is the lookup endpoint.
|
||||||
@@ -45,7 +47,6 @@ const (
|
|||||||
// bodyLimit caps the response read. A lookup with meta=recordings for a
|
// bodyLimit caps the response read. A lookup with meta=recordings for a
|
||||||
// popular song runs to tens of kilobytes.
|
// popular song runs to tens of kilobytes.
|
||||||
bodyLimit = 2 << 20
|
bodyLimit = 2 << 20
|
||||||
userAgent = "Minstrel ( https://git.fabledsword.com/bvandeusen/minstrel )"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// The server's error codes that the worker treats differently.
|
// The server's error codes that the worker treats differently.
|
||||||
@@ -127,7 +128,7 @@ func (c *Client) Lookup(ctx context.Context, apiKey, fingerprint string, duratio
|
|||||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
req.Header.Set("Content-Encoding", "gzip")
|
req.Header.Set("Content-Encoding", "gzip")
|
||||||
req.Header.Set("Accept", "application/json")
|
req.Header.Set("Accept", "application/json")
|
||||||
req.Header.Set("User-Agent", userAgent)
|
req.Header.Set("User-Agent", buildinfo.UserAgent(""))
|
||||||
|
|
||||||
resp, err := c.http.Do(req)
|
resp, err := c.http.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -29,3 +29,19 @@ var Channel = "local"
|
|||||||
|
|
||||||
// Started is when this process started, for the admin Overview's uptime.
|
// Started is when this process started, for the admin Overview's uptime.
|
||||||
var Started = time.Now()
|
var Started = time.Now()
|
||||||
|
|
||||||
|
// ProjectURL is where Minstrel's source lives. Outside services that ask a
|
||||||
|
// client to say how to reach its maker are pointed here.
|
||||||
|
const ProjectURL = "https://git.fabledsword.com/bvandeusen/minstrel"
|
||||||
|
|
||||||
|
// UserAgent is how Minstrel names itself to outside services (MusicBrainz,
|
||||||
|
// the Cover Art Archive, AcoustID), which ask for the app's name, its
|
||||||
|
// version and a contact, so a release can be told from a dev build in
|
||||||
|
// their logs. contact is the operator's address when one is configured;
|
||||||
|
// without one the project's URL stands in.
|
||||||
|
func UserAgent(contact string) string {
|
||||||
|
if contact == "" {
|
||||||
|
contact = ProjectURL
|
||||||
|
}
|
||||||
|
return "Minstrel/" + Version + " ( " + contact + " )"
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package buildinfo
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
// The User-Agent carries the build's own version, so MusicBrainz and the
|
||||||
|
// others can tell a release from a dev build, and a contact: the operator's
|
||||||
|
// when set, the project's otherwise.
|
||||||
|
func TestUserAgent_NamesTheVersionAndAContact(t *testing.T) {
|
||||||
|
was := Version
|
||||||
|
t.Cleanup(func() { Version = was })
|
||||||
|
Version = "2026.11.28.1700"
|
||||||
|
|
||||||
|
if got, want := UserAgent("admin@example.com"), "Minstrel/2026.11.28.1700 ( admin@example.com )"; got != want {
|
||||||
|
t.Errorf("with a contact: %q, want %q", got, want)
|
||||||
|
}
|
||||||
|
if got, want := UserAgent(""), "Minstrel/2026.11.28.1700 ( "+ProjectURL+" )"; got != want {
|
||||||
|
t.Errorf("without one: %q, want %q", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,15 +10,13 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.fabledsword.com/bvandeusen/minstrel/internal/buildinfo"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultBaseURL is the public MusicBrainz web service.
|
// DefaultBaseURL is the public MusicBrainz web service.
|
||||||
const DefaultBaseURL = "https://musicbrainz.org/ws/2"
|
const DefaultBaseURL = "https://musicbrainz.org/ws/2"
|
||||||
|
|
||||||
// UserAgent identifies Minstrel. MusicBrainz refuses requests without a
|
|
||||||
// descriptive one.
|
|
||||||
const UserAgent = "Minstrel/1.0 ( https://git.fabledsword.com/bvandeusen/minstrel )"
|
|
||||||
|
|
||||||
// DefaultTimeout bounds one request. A browse page with track
|
// DefaultTimeout bounds one request. A browse page with track
|
||||||
// lists is the slowest thing asked for.
|
// lists is the slowest thing asked for.
|
||||||
const DefaultTimeout = 20 * time.Second
|
const DefaultTimeout = 20 * time.Second
|
||||||
@@ -130,7 +128,8 @@ func (c *Client) once(ctx context.Context, full string, out any) (retry bool, er
|
|||||||
return false, fmt.Errorf("musicbrainz: build request: %w", err)
|
return false, fmt.Errorf("musicbrainz: build request: %w", err)
|
||||||
}
|
}
|
||||||
req.Header.Set("Accept", "application/json")
|
req.Header.Set("Accept", "application/json")
|
||||||
req.Header.Set("User-Agent", UserAgent)
|
// MusicBrainz refuses requests without a descriptive User-Agent.
|
||||||
|
req.Header.Set("User-Agent", buildinfo.UserAgent(""))
|
||||||
|
|
||||||
resp, err := c.httpClient().Do(req)
|
resp, err := c.httpClient().Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.fabledsword.com/bvandeusen/minstrel/internal/buildinfo"
|
||||||
"git.fabledsword.com/bvandeusen/minstrel/internal/musicbrainz"
|
"git.fabledsword.com/bvandeusen/minstrel/internal/musicbrainz"
|
||||||
"git.fabledsword.com/bvandeusen/minstrel/internal/providers"
|
"git.fabledsword.com/bvandeusen/minstrel/internal/providers"
|
||||||
)
|
)
|
||||||
@@ -16,8 +17,6 @@ import (
|
|||||||
var mbBaseURL = "https://musicbrainz.org/ws/2"
|
var mbBaseURL = "https://musicbrainz.org/ws/2"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// mbUserAgent identifies the app — MusicBrainz rejects requests without one.
|
|
||||||
mbUserAgent = musicbrainz.UserAgent
|
|
||||||
// artistTagWeightFactor down-weights artist-level fallback tags relative
|
// artistTagWeightFactor down-weights artist-level fallback tags relative
|
||||||
// to recording-specific tags — the artist's overall character is a coarser
|
// to recording-specific tags — the artist's overall character is a coarser
|
||||||
// signal than a tag on the exact recording.
|
// signal than a tag on the exact recording.
|
||||||
@@ -38,8 +37,9 @@ type musicbrainzProvider struct {
|
|||||||
func init() {
|
func init() {
|
||||||
Register(&musicbrainzProvider{
|
Register(&musicbrainzProvider{
|
||||||
client: providers.NewHTTPClient(providers.HTTPOptions{
|
client: providers.NewHTTPClient(providers.HTTPOptions{
|
||||||
Name: "musicbrainz",
|
Name: "musicbrainz",
|
||||||
UserAgent: mbUserAgent,
|
// MusicBrainz rejects requests without one.
|
||||||
|
UserAgent: buildinfo.UserAgent(""),
|
||||||
HTTPClient: &http.Client{Timeout: 30 * time.Second},
|
HTTPClient: &http.Client{Timeout: 30 * time.Second},
|
||||||
// MusicBrainz's 1 request/second is per address: share it with
|
// MusicBrainz's 1 request/second is per address: share it with
|
||||||
// the release catalogue.
|
// the release catalogue.
|
||||||
|
|||||||
Reference in New Issue
Block a user