model

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

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

View Source
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

func ParseCommit(sha string) (string, error)

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

type Documentation struct {
	URL   string `json:"url"`
	Short string `json:"short"`
}

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 Repo

type Repo struct {
	Name   string `json:"name"`
	Commit string `json:"commit"`
}

Repo is the analyzed repository and the commit the result was computed at.

type RepoRef

type RepoRef struct {
	Host string
	Org  string
	Repo string
}

RepoRef identifies a repository the server serves or scans, as parsed from a platform/owner/repo request path.

func ParseRepoRef

func ParseRepoRef(host, org, repo string) (RepoRef, error)

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).

func (RepoRef) Name

func (r RepoRef) Name() string

Name returns the canonical repository name, host/org/repo, as used in the JSON2 repo.name field and as the object-key prefix.

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.

func Parse

func Parse(data []byte) (*Result, error)

Parse decodes canonical Scorecard JSON2 bytes into a Result for introspection.

type Scorecard

type Scorecard struct {
	Version string `json:"version"`
	Commit  string `json:"commit"`
}

Scorecard is the version of the Scorecard engine that produced the result.

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"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL