Documentation
¶
Overview ¶
Package tea is a client for the OWASP Transparency Exchange API.
It speaks both halves of the same API: the consumption operations any conformant server serves, and the publication operations that create the objects those consumers read. That is deliberate — they are one API at one root, and a client that treated them as two would have to be told twice which server it is talking to.
The default server is Vulnetix, but nothing here assumes it. A --server pointing at another organisation's TEA endpoint works for every read; writes will simply be refused by a server that does not know the caller, which is the correct outcome rather than something to guard against locally.
Index ¶
- Constants
- Variables
- func AdvertisedVersions(doc *WellKnown) []string
- func ArtifactTypeForFile(path string) string
- func ContentDigest(body []byte) string
- func IsPublicServer(root string) bool
- func IsURI(raw string) bool
- func MediaTypeForFile(path string) string
- func NormaliseDomain(in string) (string, error)
- func PublicationBase(root string) string
- func RootFrom(doc *WellKnown) string
- func RootsFrom(doc *WellKnown) []string
- func ServerForCatalogue(name string) (string, error)
- func TEIForVersion(raw, version string) string
- func ValidIDType(s string) (string, bool)
- func VersionFromRoot(root string) string
- type AccessPolicy
- type AccessStatus
- type Artifact
- type Candidate
- type Checksum
- type Client
- func (c *Client) AccessPolicy(ctx context.Context, uuid string) (*AccessStatus, error)
- func (c *Client) AttachSignature(ctx context.Context, artifactUUID string, formatIndex int, sig map[string]any) error
- func (c *Client) ComponentRelease(ctx context.Context, uuid string) (*ComponentReleaseDetail, error)
- func (c *Client) CreateArtifact(ctx context.Context, collectionUUID, name, artifactType string, ...) (*Artifact, error)
- func (c *Client) CreateComponent(ctx context.Context, name string, identifiers []Identifier, ...) (*Product, error)
- func (c *Client) CreateComponentRelease(ctx context.Context, componentUUID, version, releaseDate string, ...) (*Release, error)
- func (c *Client) CreateDistribution(ctx context.Context, componentReleaseUUID string, d Distribution, ...) (*Distribution, error)
- func (c *Client) CreateProduct(ctx context.Context, name string, identifiers []Identifier, ...) (*Product, error)
- func (c *Client) CreateProductRelease(ctx context.Context, productUUID, version, releaseDate string, preRelease bool, ...) (*Release, error)
- func (c *Client) DeleteDistribution(ctx context.Context, uuid string) error
- func (c *Client) DeleteObject(ctx context.Context, segment, uuid string) error
- func (c *Client) DeleteProduct(ctx context.Context, uuid string) error
- func (c *Client) Do(ctx context.Context, method, path string, body any, out any, ...) error
- func (c *Client) DoPublish(ctx context.Context, method, path string, body any, out any, ...) error
- func (c *Client) LatestCollection(ctx context.Context, releaseUUID string) (*Collection, error)
- func (c *Client) ListComponents(ctx context.Context, o ListOptions) (*Page[Component], error)
- func (c *Client) ListProducts(ctx context.Context, o ListOptions) (*Page[Product], error)
- func (c *Client) Product(ctx context.Context, uuid string) (*Product, error)
- func (c *Client) ProductReleases(ctx context.Context, uuid string) (*Page[Release], error)
- func (c *Client) Products(ctx context.Context, pageSize int, pageToken string) (*Page[Product], error)
- func (c *Client) Publications(ctx context.Context) ([]map[string]any, error)
- func (c *Client) PublishCollection(ctx context.Context, releaseUUID string, reason UpdateReason) (*Collection, error)
- func (c *Client) ResolvePURL(ctx context.Context, purl string) ([]DiscoveryInfo, error)
- func (c *Client) ResolveTEI(ctx context.Context, tei string) ([]DiscoveryInfo, error)
- func (c *Client) SetAccessPolicy(ctx context.Context, uuid string, policy AccessPolicy) (*AccessStatus, error)
- func (c *Client) UploadArtifactFile(ctx context.Context, artifactUUID string, formatIndex int, ...) (map[string]any, error)
- func (c *Client) Version() string
- type Collection
- type Component
- type ComponentReleaseDetail
- type DiscoveryInfo
- type Distribution
- type Error
- type Format
- type Identifier
- type ListOptions
- type Page
- type Product
- type Release
- type ServerInfo
- type ShareGrant
- type TEI
- type UpdateReason
- type WellKnown
- type WellKnownEndpoint
Constants ¶
const ( LegacyServer = "https://www.vulnetix.com/tea/v0.4.0" LegacyPublicServer = "https://www.vulnetix.com/tea/public/v0.4.0" )
LegacyServer and LegacyPublicServer are the same two roots at TEA 0.4.0, for a caller that has to read the older shapes: `--server` takes either.
const ( CatalogueFirstParty = "first-party" CataloguePublic = "public" )
Catalogue names accepted by ServerForCatalogue.
const DefaultServer = "https://www.vulnetix.com/tea/v1.0.0"
DefaultServer is Vulnetix's own TEA root, at the current specification. It is the base advertised in https://vulnetix.com/.well-known/tea completed with "/v1.0.0", which is exactly how that document tells a client to build it.
const PublicServer = "https://www.vulnetix.com/tea/public/v1.0.0"
PublicServer is the open source catalogue root: the top GitHub projects by stars, published as products and components. It is a different root from DefaultServer, not a filtered view of it. It requires a credential but has no plan gate, so any valid ApiKey, including the shared community one, reads it.
Variables ¶
var Catalogues = []string{CatalogueFirstParty, CataloguePublic}
Catalogues lists the valid catalogue names, default first.
var IDTypes = []string{"CPE", "TEI", "PURL", "COMPLIANCE_DOCUMENT"}
IDTypes are the identifier types the server filters on.
var SupportedVersions = []string{"1.0.0", "0.4.0"}
SupportedVersions are the TEA specification versions this client speaks, newest first. The first entry is the default: it is chosen whenever the publisher advertises it.
Functions ¶
func AdvertisedVersions ¶
AdvertisedVersions is every distinct version a document offers, in the order first seen. It is what an error shows when nothing matched.
func ArtifactTypeForFile ¶
ArtifactTypeForFile maps a document to the TEA artifact type enum.
Defaults to OTHER rather than BOM: claiming a file is a bill of materials when it might not be tells a consumer to parse it as one.
func ContentDigest ¶
ContentDigest renders the RFC 9530 header for a body.
The server verifies this before storing anything, which is what makes an upload safe to retry: a truncated transfer fails loudly instead of being published under a checksum asserting it arrived intact.
func IsPublicServer ¶
IsPublicServer reports whether a root URL is the open source catalogue root, ignoring a trailing slash and letter case.
func MediaTypeForFile ¶
MediaTypeForFile guesses the media type of a transparency document from its name.
Only the formats TEA actually carries are recognised. Anything else becomes application/octet-stream rather than a guess: an artifact served under the wrong media type is one a consumer's parser will reject, and being wrong is worse than being unspecific.
func NormaliseDomain ¶
NormaliseDomain reduces what a person pastes — a bare domain, a URL, or a TEI — to the domain-name component discovery starts from.
func PublicationBase ¶
PublicationBase maps a server root to where the publication operations live. For a Vulnetix-shaped root (".../tea/v<version>") that is ".../tea/v1"; any other root is returned as it is, because publication is Vulnetix's extension and a server that has it serves it where it serves everything else.
func RootFrom ¶
RootFrom is the best root for a discovery document, or "" when the provider offers no version this client speaks.
func RootsFrom ¶
RootsFrom lists every root worth trying for a discovery document, best first (see RankCandidates for the rules). A caller fails over down the list on DNS or TLS errors, 5xx, and a 404 that carries no TEA error body, but not on 401 or 403.
func ServerForCatalogue ¶
ServerForCatalogue maps a catalogue name to its root URL. An empty name is the first party catalogue. Matching ignores case and surrounding space.
func TEIForVersion ¶
TEIForVersion renders a TEI in the spelling a server of the given version recognises. An unreadable TEI, and a version the CLI cannot place, are returned unchanged: the server's answer to what the user typed is better than a guess.
func ValidIDType ¶
ValidIDType normalises an identifier type to the server's upper case spelling and reports whether it is one the server filters on.
func VersionFromRoot ¶
VersionFromRoot reads the specification version out of a root URL such as https://host/tea/v1.0.0, normalised to major.minor.patch. A root without a full version segment (Vulnetix's own /tea/v1 alias, or a custom path) returns "": the version is not knowable from the URL alone.
Types ¶
type AccessPolicy ¶
type AccessPolicy struct {
ObjectKind string `json:"objectKind,omitempty"`
ObjectUUID string `json:"objectUuid,omitempty"`
Visibility string `json:"visibility"`
}
AccessPolicy is who may read an object.
type AccessStatus ¶
type AccessStatus struct {
UUID string `json:"uuid"`
Declared *AccessPolicy `json:"declared,omitempty"`
Effective AccessPolicy `json:"effective"`
InheritedFrom string `json:"inheritedFrom,omitempty"`
}
AccessStatus reports what an object declares against what is enforced.
type Artifact ¶
type Artifact struct {
UUID string `json:"uuid"`
Version int `json:"version,omitempty"`
Name string `json:"name"`
Type string `json:"type,omitempty"`
CreatedDate string `json:"createdDate,omitempty"`
Formats []Format `json:"formats,omitempty"`
}
Artifact is one published document.
type Candidate ¶
type Candidate struct {
Endpoint WellKnownEndpoint
// Version is the version exactly as the publisher advertised it. The URL is
// built from this string, so build metadata is preserved.
Version string
// Supported is the entry of the supported list it matched.
Supported string
}
Candidate is one (endpoint, version) pair a client can try.
func RankCandidates ¶
RankCandidates orders everything a client could try against a discovery document, best first.
The rules are the specification's: prefer the greatest version both sides support, break ties by the endpoint's priority (absent means 1), then by the order the publisher listed them. Every mutually supported version of every endpoint is a candidate, so the list also carries the fallbacks: the same endpoint at an older version comes after the other endpoints at the newer one.
A pre-release never matches, because the supported list holds stable versions only. Pointing a user's tooling at a provider's beta API is not a decision to make on their behalf.
type Client ¶
type Client struct {
BaseURL string
// PublishURL is where the publication operations are sent. Left empty it is
// worked out from BaseURL (see PublicationBase), which is right unless a caller
// is pointing at a server that serves publication somewhere unusual.
PublishURL string
Creds *auth.Credentials
HTTP *http.Client
// Err, when set, is returned by every request instead of sending it. It lets
// a caller that could not configure the client (conflicting flags, say)
// hand back a client that fails loudly rather than one that quietly talks
// to the wrong server.
Err error
}
Client talks to one TEA server.
func New ¶
func New(baseURL string, creds *auth.Credentials) *Client
New builds a client. Credentials may be nil: the consumption operations of a public catalogue need none, and requiring them would make the CLI useless for reading somebody else's open transparency log.
func (*Client) AccessPolicy ¶
AccessPolicy reads the policy in force for an object.
func (*Client) AttachSignature ¶
func (c *Client) AttachSignature(ctx context.Context, artifactUUID string, formatIndex int, sig map[string]any) error
AttachSignature records a detached signature and, crucially, the scheme it was produced with. The consumption API exposes only a URL, so a consumer without the scheme has to guess how to verify — which in practice means not verifying.
func (*Client) ComponentRelease ¶
func (c *Client) ComponentRelease(ctx context.Context, uuid string) (*ComponentReleaseDetail, error)
ComponentRelease reads a component release with its distributions. The consumption API only carries distributions on the object read, never on a list page, so this is the one call that answers "where do I get it".
func (*Client) CreateArtifact ¶
func (c *Client) CreateArtifact(ctx context.Context, collectionUUID, name, artifactType string, formats []Format, idempotencyKey string) (*Artifact, error)
CreateArtifact registers an artifact within a collection. It does not carry the bytes: those go up per format afterwards, so correcting a metadata field does not mean resending a multi-megabyte document.
func (*Client) CreateComponent ¶
func (c *Client) CreateComponent(ctx context.Context, name string, identifiers []Identifier, idempotencyKey string) (*Product, error)
CreateComponent registers a component.
A product is what somebody buys; a component is a thing that ships. They are separate objects in TEA because a release of one is not a release of the other, and only a component release can carry distributions.
func (*Client) CreateComponentRelease ¶
func (c *Client) CreateComponentRelease(ctx context.Context, componentUUID, version, releaseDate string, preRelease bool, idempotencyKey string) (*Release, error)
CreateComponentRelease publishes a release of a component.
func (*Client) CreateDistribution ¶
func (c *Client) CreateDistribution(ctx context.Context, componentReleaseUUID string, d Distribution, idempotencyKey string) (*Distribution, error)
CreateDistribution declares one delivered form of a component release.
Idempotent on the download URL, or on the description where a channel has no single file to fetch — so republishing a release updates its download links rather than listing each of them twice.
func (*Client) CreateProduct ¶
func (c *Client) CreateProduct(ctx context.Context, name string, identifiers []Identifier, idempotencyKey string) (*Product, error)
CreateProduct registers a product. The server assigns the UUID and the TEI — a TEI names the server's authority over the object, which a publisher cannot assert on its behalf.
func (*Client) CreateProductRelease ¶
func (c *Client) CreateProductRelease(ctx context.Context, productUUID, version, releaseDate string, preRelease bool, idempotencyKey string) (*Release, error)
CreateProductRelease publishes a release of a product.
func (*Client) DeleteDistribution ¶
DeleteDistribution withdraws a download link. It does not make anything already downloaded go away.
func (*Client) DeleteObject ¶
DeleteObject removes any published object by its kind's path segment.
Deleting a product does not reach the component published alongside it: they are separate objects with separate lineages, which is what lets a component outlive the product that first shipped it. Withdrawing everything therefore means naming both, and a CLI that could create a component but never remove one would leave that impossible from the terminal.
func (*Client) DeleteProduct ¶
DeleteProduct removes a product and everything beneath it.
func (*Client) Do ¶
func (c *Client) Do(ctx context.Context, method, path string, body any, out any, headers map[string]string) error
Do performs one request against the server's TEA root and decodes the result into out.
headers are applied last so a caller can set Idempotency-Key and Content-Digest, which are the two the publication API acts on and which a generic client would otherwise have no way to send.
func (*Client) DoPublish ¶
func (c *Client) DoPublish(ctx context.Context, method, path string, body any, out any, headers map[string]string) error
DoPublish is Do for the publication operations, which are not served at the version path (see PublicationBase).
func (*Client) LatestCollection ¶
LatestCollection reads the current collection for a product release.
func (*Client) ListComponents ¶
ListComponents lists components with paging, sorting and identifier filtering.
func (*Client) ListProducts ¶
ListProducts lists products with paging, sorting and identifier filtering.
func (*Client) ProductReleases ¶
ProductReleases lists a product's releases.
func (*Client) Products ¶
func (c *Client) Products(ctx context.Context, pageSize int, pageToken string) (*Page[Product], error)
Products lists products.
func (*Client) Publications ¶
Publications lists what this organisation has published, with the visibility of each — the half a publisher cannot see through the consumption API, because that API will not show anyone anything private.
func (*Client) PublishCollection ¶
func (c *Client) PublishCollection(ctx context.Context, releaseUUID string, reason UpdateReason) (*Collection, error)
PublishCollection publishes the next version of a release's collection.
func (*Client) ResolvePURL ¶
ResolvePURL resolves a Package URL to the product release it names, through the 1.0.0 operation that takes one directly. A 0.4.0 server has no such parameter; it answers with a 400, and the caller can fall back to a purl-typed TEI.
func (*Client) ResolveTEI ¶
ResolveTEI asks the server to resolve an identifier to the object it names.
The TEI is sent in the spelling the server speaks. A 1.0.0 server recognises only tei://domain/type/id and a 0.4.0 one only urn:tei:type:domain:id, so a TEI written the other way is converted when the root names its version. When it does not (the stable alias, a custom path), the TEI is sent as typed: Vulnetix accepts both, and another server's answer to what the user wrote is better than a guess about which it wanted.
GET /discovery returns an ARRAY of discovery-info — one TEI can resolve at more than one server. Decoding it into an object failed on every real response with "cannot unmarshal array into Go value of type map".
func (*Client) SetAccessPolicy ¶
func (c *Client) SetAccessPolicy(ctx context.Context, uuid string, policy AccessPolicy) (*AccessStatus, error)
SetAccessPolicy replaces an object's own policy.
Going public requires the server's confirmation parameter. That is not ceremony: no later request undoes it, because whatever was fetched while an object was public stays fetched.
type Collection ¶
type Collection struct {
UUID string `json:"uuid"`
Version int `json:"version"`
// Date is 0.4.0's name for when a collection version was made, and was
// optional. CreatedDate is 1.0.0's, and is required. Read it with When.
Date string `json:"date,omitempty"`
CreatedDate string `json:"createdDate,omitempty"`
BelongsTo string `json:"belongsTo,omitempty"`
UpdateReason *UpdateReason `json:"updateReason,omitempty"`
Artifacts []Artifact `json:"artifacts,omitempty"`
}
Collection is a versioned set of artifacts for one release.
func (Collection) When ¶
func (c Collection) When() string
When is when the collection version was made, whichever version of the specification said so. It is empty for a 0.4.0 server that left the date out.
type Component ¶
type Component struct {
UUID string `json:"uuid"`
Name string `json:"name"`
Identifiers []Identifier `json:"identifiers,omitempty"`
}
Component is a piece of software a product is built from. It is listed by GET /components and carries the same identifying fields as a product.
type ComponentReleaseDetail ¶
type ComponentReleaseDetail struct {
Release struct {
Release
Distributions []Distribution `json:"distributions,omitempty"`
} `json:"release"`
LatestCollection Collection `json:"latestCollection"`
}
ComponentReleaseDetail is what GET /componentRelease/{uuid} returns: the release and the collection currently published for it.
The two versions of the specification spell it differently. 0.4.0 wraps it, {"release": {...}, "latestCollection": {...}}; 1.0.0 puts latestCollection beside the release's own fields. UnmarshalJSON reads either, so a caller sees one shape whichever server answered. Marshalling keeps the wrapped form, which is what `--json` output has always been.
func (*ComponentReleaseDetail) UnmarshalJSON ¶
func (d *ComponentReleaseDetail) UnmarshalJSON(b []byte) error
UnmarshalJSON reads the wrapped 0.4.0 shape and the flat 1.0.0 one.
type DiscoveryInfo ¶
type DiscoveryInfo struct {
ProductReleaseUUID string `json:"productReleaseUuid"`
Servers []ServerInfo `json:"servers"`
}
DiscoveryInfo is one entry of the GET /discovery response: the product release a TEI resolves to, and where it can be read from.
type Distribution ¶
type Distribution struct {
DistributionID string `json:"distributionId,omitempty"`
Description string `json:"description,omitempty"`
Identifiers []Identifier `json:"identifiers,omitempty"`
URL string `json:"url,omitempty"`
SignatureURL string `json:"signatureUrl,omitempty"`
Checksums []Checksum `json:"checksums,omitempty"`
}
Distribution is one delivered form of a component release — `release-distribution` in the consumption schema.
Not to be confused with an artifact. An artifact is evidence ABOUT a release: an SBOM, a VEX document, an attestation. A distribution is the release as somebody installs it: a binary on a releases page, a Homebrew formula, a Scoop manifest. A consumer asking "how do I get 3.81.0 on macOS" wants the second, and an SBOM is not an answer to it.
type Error ¶
type Error struct {
Status int `json:"-"`
Code string `json:"error"`
Message string `json:"message,omitempty"`
Field string `json:"field,omitempty"`
}
Error is a TEA error response, in either the consumption or publication envelope. Both carry a machine-readable code; only the publication one carries a message and field.
func (*Error) IsInvalidPageToken ¶
IsInvalidPageToken reports a 1.0.0 server refusing a page token, because it was not issued for this request or a parameter now contradicts it. The remedy is to start the listing again without the token.
func (*Error) IsNoAcceptableFormat ¶
IsNoAcceptableFormat reports a 1.0.0 server saying the artifact has no format matching the request.
func (*Error) IsNotFound ¶
IsNotFound reports whether the server said the object does not exist, under either envelope's spelling.
func (*Error) IsNotImplemented ¶
IsNotImplemented reports a 1.0.0 server saying it does not provide an optional capability (CLE, /token). It is not a failure of the object: a client carries on without the capability.
func (*Error) IsSignatureNotFound ¶
IsSignatureNotFound reports a 1.0.0 server saying the artifact exists and has no signature for the format asked about.
type Format ¶
type Format struct {
MediaType string `json:"mediaType"`
Description string `json:"description,omitempty"`
URL string `json:"url,omitempty"`
SignatureURL string `json:"signatureUrl,omitempty"`
Checksums []Checksum `json:"checksums,omitempty"`
}
Format is one representation of an artifact.
type Identifier ¶
Identifier is a TEA identifier: a type and its value.
type ListOptions ¶
type ListOptions struct {
// PageSize is 1..100 on the server; 0 leaves it to the server (25).
PageSize int
// PageToken is the opaque token a previous page returned.
PageToken string
// IDType and IDValue together filter on one identifier, exactly: the server
// does no wildcard matching and no case folding.
IDType string
IDValue string
// SortField is "name" for products and components; SortOrder is asc or desc.
SortField string
SortOrder string
}
ListOptions are the parameters the list operations (GET /products and GET /components) accept. Zero values are left off the query string so the server applies its own defaults.
func (ListOptions) Query ¶
func (o ListOptions) Query() url.Values
Query renders the options as a query string.
type Page ¶
type Page[T any] struct { Results []T `json:"results"` HasNext bool `json:"hasNext"` NextPageToken string `json:"nextPageToken"` }
Page is the consumption API's pagination envelope.
type Product ¶
type Product struct {
UUID string `json:"uuid"`
Name string `json:"name"`
Identifiers []Identifier `json:"identifiers,omitempty"`
}
Product is a lineage of releases.
type Release ¶
type Release struct {
UUID string `json:"uuid"`
Product string `json:"product,omitempty"`
ProductName string `json:"productName,omitempty"`
Component string `json:"component,omitempty"`
ComponentName string `json:"componentName,omitempty"`
Version string `json:"version"`
CreatedDate string `json:"createdDate,omitempty"`
ReleaseDate string `json:"releaseDate,omitempty"`
PreRelease bool `json:"preRelease,omitempty"`
Identifiers []Identifier `json:"identifiers,omitempty"`
}
Release covers both flavours. The consumption API distinguishes a product release from a component release; the fields that differ are the parent and its name, so one struct carries both rather than duplicating the rest.
type ServerInfo ¶
type ServerInfo struct {
RootURL string `json:"rootUrl"`
Versions []string `json:"versions"`
Priority *float64 `json:"priority,omitempty"`
}
ServerInfo is one TEA server that can serve a resolved release, as advertised by GET /discovery (the `tea-server-info` schema).
type ShareGrant ¶
type ShareGrant struct {
}
ShareGrant entitles one organisation to read one object.
type TEI ¶
TEI is a TEI taken apart. For a purl, ID is the Package URL itself, whichever spelling it arrived in.
type UpdateReason ¶
UpdateReason says why a collection changed. Required on publication: a collection whose contents change without saying why is indistinguishable, to a consumer, from one that was tampered with.
type WellKnown ¶
type WellKnown struct {
SchemaVersion int `json:"schemaVersion"`
Endpoints []WellKnownEndpoint `json:"endpoints"`
}
WellKnown is the discovery document at /.well-known/tea.
func Discover ¶
Discover resolves a domain to a TEA root, following the specification: query DNS for the domain, fetch /.well-known/tea over HTTPS, then pick an endpoint and append its version.
The domain may be given as a bare name, a URL, or a TEI — those are the three forms a person actually has to hand, and requiring them to convert between them would be busywork.
type WellKnownEndpoint ¶
type WellKnownEndpoint struct {
URL string `json:"url"`
Versions []string `json:"versions"`
Priority *float64 `json:"priority,omitempty"`
}
WellKnownEndpoint is one entry of the discovery document's endpoints.