product

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package product is the catalog layer over OpenJD templates: it parses product definition files, holds the embedded built-ins, validates inline templates, and overlays read-only built-ins on the store via Catalog.

Index

Constants

View Source
const (
	MaxNameLen        = 128
	MaxTitleLen       = 200
	MaxDescriptionLen = 500
	MaxReadmeLen      = 8000
	MaxCategoryLen    = 64
	MaxVersionLen     = 32
)

Metadata length limits, counted in runes rather than bytes so that text in a multi-byte script gets the same room as ASCII (500 bytes of CJK is about 166 characters).

MaxDescriptionLen is a design limit: the description is rendered into an unclamped picker card and a native Blender EnumProperty tooltip. MaxReadmeLen is an abuse guard; the readme appears only on the detail page. The other limits leave ample room for any real product and keep every metadata field bounded.

Variables

View Source
var ErrReadOnly = errors.New("product: read-only")

ErrReadOnly is returned when a mutation targets a read-only product (built-in or installed preset).

Functions

func Builtins

func Builtins() []store.Product

Builtins returns the embedded built-in products, sorted by name. The returned slice is a copy; callers may not mutate the shared definitions.

func ParseDefinition

func ParseDefinition(data []byte, opts ValidateOptions) (store.Product, error)

ParseDefinition parses a YAML product definition file (metadata + inline template) into a store.Product. Source is left empty for the caller to set. The inline template is re-serialized to YAML and validated under opts; a malformed template is an error, and so is a breach of opts.Deadline (wrapping [expr.ErrDeadlineExceeded]; see ValidateTemplate for why the two must be told apart).

opts is required rather than defaulted because callers differ in what they can supply, and a default would let the preset routes validate on openjd.DefaultExprLimits() while the create/update route honors the operator's configuration:

  • loadBuiltins, from package init, has no configuration to offer and passes only EnforceLimits.
  • internal/presetlib, reached from GET /api/v1/presets/{name} and POST /api/v1/presets/{name}/install, passes the operator's limits and a per-request deadline.

func ValidateMetadata added in v0.3.0

func ValidateMetadata(p store.Product) error

ValidateMetadata enforces the length limits on a product's metadata fields.

Both entry points into product data call it, ParseDefinition and the REST create/update handler, so the two enforce the same limits.

It checks length only. The slug pattern is checked by validateName on the definition path alone, because applying it to the REST route would reject products already stored under a name that does not match it.

func ValidateTemplate

func ValidateTemplate(rawTemplate string, format store.TemplateFormat, opts ValidateOptions) error

ValidateTemplate parses rawTemplate as OpenJD in the given format and runs the standard validation under opts. It returns nil when the template is valid, an error carrying the OpenJD ValidationErrors when it is not, or an error wrapping [expr.ErrDeadlineExceeded] when opts.Deadline passed mid-validation.

Callers must tell the last two apart. ValidationErrors mean the template is wrong and a retry gets the same answer; a deadline means this server stopped on a template that may validate on an idle machine. internal/api answers 400 for the first and 503 for the second. Match the deadline with errors.Is(err, expr.ErrDeadlineExceeded), not by reading the message.

Types

type Catalog

type Catalog struct {
	// contains filtered or unexported fields
}

Catalog overlays the embedded built-ins on a ProductStore and enforces the read-only / name-shadowing rules. It is the only component aware of built-ins.

func NewCatalog

func NewCatalog(st store.ProductStore) *Catalog

NewCatalog returns a Catalog backed by st.

func (*Catalog) Create

func (c *Catalog) Create(ctx context.Context, p store.Product) (store.Product, error)

Create stores a new custom/installed product. It rejects names that shadow a built-in. An empty Source defaults to SourceCustom; an empty ID is assigned.

func (*Catalog) Delete

func (c *Catalog) Delete(ctx context.Context, name string) error

Delete removes a stored product. Built-ins are read-only.

func (*Catalog) GetByName

func (c *Catalog) GetByName(ctx context.Context, name string) (store.Product, error)

GetByName returns a built-in (preferred) or stored product, or ErrNotFound.

func (*Catalog) Install

func (c *Catalog) Install(ctx context.Context, def store.Product, ref, fingerprint string) (store.Product, bool, error)

Install stores a preset fetched from the library as an installed product. It create-or-overwrites by name: a new name is created; an existing installed product of the same name is overwritten (the update path); a name shadowing a built-in or colliding with a custom product returns store.ErrConflict. The returned bool is true when a new product was created, false on overwrite.

func (*Catalog) List

func (c *Catalog) List(ctx context.Context) ([]store.Product, error)

List returns built-ins merged with stored products, ordered by name.

func (*Catalog) Update

func (c *Catalog) Update(ctx context.Context, p store.Product) (store.Product, error)

Update replaces a stored product. Built-ins and installed presets are read-only (edit an installed preset by duplicating it to a custom product).

type ValidateOptions added in v0.3.0

type ValidateOptions struct {
	// EnforceLimits gates OpenJD's quantitative limit checks; see
	// [openjd.ValidateOptions].
	EnforceLimits bool

	// ExprLimits is the operator's configured bound on what this template's
	// EXPR expression walk may spend. The zero value means the defaults.
	//
	// Every route that reaches this package from an HTTP request must set it,
	// or validation runs on the defaults even when the operator tightened the
	// four limits. The product create/update route and the preset install
	// route sit behind the same permission (policy.ProductsManage), both end
	// in a catalog write, and must enforce the same limits whoever supplied
	// the content.
	ExprLimits openjd.ExprLimits

	// Deadline, when non-zero, is an absolute wall-clock instant after which
	// validation stops and [ValidateTemplate] returns an error wrapping
	// [expr.ErrDeadlineExceeded].
	//
	// It is set per request and never stored: it is computed from a
	// configured duration at the start of one HTTP request. See the Deadline
	// field of [openjd.ExprLimits] for what a deadline stored on a long-lived
	// value does.
	Deadline time.Time
}

ValidateOptions bounds one ValidateTemplate or ParseDefinition call.

Product templates are validated by callers with different trust and configuration. POST /api/v1/products and PUT /api/v1/products/{name} accept an arbitrary client-supplied body, anonymously when auth is off (the default), and need both the operator's configured EXPR limits and a wall-clock deadline. The preset routes (GET /api/v1/presets/{name}, POST /api/v1/presets/{name}/install) validate a sha256-pinned body from an operator-configured index. That content is not client-chosen, but each validation is still one repeatable request, so they take both too. The built-in loader runs from package init, where no configuration exists, and takes neither.

The zero value means limit enforcement off, default EXPR limits, no deadline.

Jump to

Keyboard shortcuts

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