Documentation
¶
Overview ¶
Package model defines a lean in-repo mirror of the OpenSSF Scorecard JSON2 wire format (Result), the repository reference the server routes on (RepoRef), and the provenance metadata (Provenance) that the server declares for every response.
Per design decision D13, this package deliberately does NOT import the go-swagger-generated models from ossf/scorecard-webapp (which drag in the full go-openapi runtime).
Note that half of D13's premise has expired: those generated models are no longer only upstream. They were imported into this repository as api/app/generated/models, and the go-openapi runtime is now a direct dependency of this module regardless of what this package does. The remaining argument is narrower but still holds — this package exists to unmarshal a handful of fields, and depending on the generated models to do it would couple the cache path to the API's generated code. Revisit when the two serving-tier implementations converge (design W10).
Live results are formatted via pkg/scorecard.AsJSON2() and cached bytes are passed through unchanged; Result exists only to unmarshal the fields the server must introspect (score for the badge; repo commit, date, and version for freshness and provenance). It mirrors the canonical shape of pkg/scorecard.JSONScorecardResultV2 exactly.
Provenance is delivered out of band (HTTP response headers and /capabilities), never embedded in the canonical JSON2 body, so webapp-compatible clients such as scorecard-mcp parse the body unchanged (design D4/D12).
Index ¶
Constants ¶
const ( HostGitHub = "github.com" HostGitLab = "gitlab.com" DefaultHost = HostGitHub )
Supported SCM hosts. An empty host defaults to DefaultHost.
Variables ¶
This section is empty.
Functions ¶
func ParseCommit ¶
ParseCommit validates an optional commit SHA. An empty string denotes the latest result; a non-empty value must be a 40-character hex SHA and is normalized to lowercase.
Types ¶
type Check ¶
type Check struct {
Details []string `json:"details"`
Score int `json:"score"`
Reason string `json:"reason"`
Name string `json:"name"`
Documentation Documentation `json:"documentation"`
Annotations []string `json:"annotations,omitempty"`
}
Check is a single Scorecard check result. Details is nullable in the wire format; Annotations is present only when annotations were requested.
type Documentation ¶
Documentation links a check to its human-readable explanation.
type Provenance ¶
type Provenance struct {
// Source is whether the result was cached or freshly scanned.
Source Source
// Commit is the resolved commit SHA the result was computed at.
Commit string
// Date is the result's JSON2 generation date.
Date string
// ScorecardVersion is the engine version that produced the result.
ScorecardVersion string
// Complete reports whether every check produced a conclusive (non-negative)
// score. This one source-agnostic rule applies to live, cached, and upstream
// results alike (see scan.Complete).
Complete bool
}
Provenance describes where a served result came from and how complete it is. The server declares it out of band (HTTP response headers and /capabilities), never inside the canonical JSON2 body, so webapp-compatible clients parse the body unchanged (design D4/D12).
Scorecard results are heuristic signals, not a verdict: provenance lets a client report source, freshness, and completeness rather than assume them.
func ProvenanceFrom ¶
func ProvenanceFrom(r *Result, src Source, complete bool) Provenance
ProvenanceFrom derives provenance from a parsed result and the source it was obtained from.
type RepoRef ¶
RepoRef identifies a repository the server serves or scans, as parsed from a platform/owner/repo request path.
func ParseRepoRef ¶
ParseRepoRef validates and normalizes a platform/owner/repo reference. An empty host defaults to github.com; github.com and gitlab.com are supported. The org and repo segments must be non-empty and safe to use as object-key path components (no separators, no "." or "..", no control characters).
type Result ¶
type Result struct {
Date string `json:"date"`
Repo Repo `json:"repo"`
Scorecard Scorecard `json:"scorecard"`
Score float64 `json:"score"`
Checks []Check `json:"checks"`
Metadata []string `json:"metadata,omitempty"`
}
Result mirrors the canonical Scorecard JSON2 result body, matching the field layout and JSON tags of pkg/scorecard.JSONScorecardResultV2.
It is used to introspect a result (score, resolved commit, generation date, version); the server serves the original JSON2 bytes rather than re-marshaling this struct, so wire compatibility never depends on it.
Metadata uses omitempty because pkg/scorecard emits "metadata": null while a Scorecard-webapp response omits it entirely; a []string decodes both forms.
type Source ¶
type Source string
Source indicates how a served result was obtained.
const ( // SourceCached means the result was served from the store. SourceCached Source = "cached" // SourceLive means the result was produced by an on-demand scan. SourceLive Source = "live" // SourceUpstream means the result was fetched from an upstream Scorecard API // (the result fallback), not produced locally. SourceUpstream Source = "upstream" )