Skip to content

feat: add Go module proxy collector - #3166

Open
ChrisJr404 wants to merge 1 commit into
guacsec:mainfrom
ChrisJr404:collector-gomod
Open

feat: add Go module proxy collector#3166
ChrisJr404 wants to merge 1 commit into
guacsec:mainfrom
ChrisJr404:collector-gomod

Conversation

@ChrisJr404

Copy link
Copy Markdown

Adds a collector that ingests Go modules straight from the module proxy (proxy.golang.org) so golang purls can be pulled without cloning anything.

For each golang purl it figures out the module path. If the purl carries a version it fetches just that one; if not, it hits @v/list and expands to every version the proxy knows about. Per version it grabs the .info (version metadata, JSON) and the .mod (the go.mod file) and emits a document for each. Bare module paths work too, which matters because a purl lowercases the namespace and the proxy needs the real casing for modules like github.com/BurntSushi/toml — that's why the case-encoding (! before each uppercase letter) lives in escapePath and gets exercised through the bare-path route. Shape follows the deps.dev and pypi collectors: version.UATransport client, poll/once modes, dedupe across poll cycles, purl parsing via packageurl-go.

I added a GO_MOD document type constant alongside the existing ones. This PR is scoped to collection like the issue asks; wiring a processor/parser for the new type is a sensible follow-up.

Tests spin up an httptest server backed by a testdata tree laid out like the proxy's escaped paths, then drive everything through collector.Collect. The .info docs go through dochelper.DocTreeEqual; go.mod is plain text so those are compared on raw bytes since the tree helper normalizes blobs as JSON. Cases cover a pinned version, version expansion via @v/list, the uppercase case-encoding, bare paths, dedupe, non-golang purls getting skipped, and a missing module emitting nothing. escapePath also has its own unit test.

go build ./..., go vet, gofmt, and go test ./pkg/handler/collector/gomod/... all pass locally.

Fixes #215

Adds a collector that pulls module metadata from the Go module proxy
(proxy.golang.org) for golang purls. For each module it lists versions
via @v/list when the purl has none, then fetches the .info and .mod for
each version and emits them as documents.

Scoped to collection per the issue; processor/parser wiring for the
GO_MOD document type can follow.

Signed-off-by: Chris (ChrisJr404) <11917633+ChrisJr404@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[collector] Golang module proxy collector

1 participant