sites

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package sites owns site naming, metadata and manifests stored in the blob store (SPEC §7.2, §9).

Index

Constants

View Source
const (

	// TitleScanBytes is how much of an index.html is inspected for its title.
	TitleScanBytes = 64 << 10

	// IndexFile is the site-relative path whose <title> describes the site.
	IndexFile = "index.html"
)
View Source
const (
	SitesPrefix    = "sites/"
	MetaPrefix     = "_meta/sites/"
	ManifestPrefix = "_meta/manifests/"
	UploadsPrefix  = "uploads/"
)

Blob key prefixes (relative to the storage prefix).

Variables

View Source
var (
	// ErrNotFound: the site does not exist.
	ErrNotFound = errors.New("sites: not found")
	// ErrInvalidName: name fails the pattern or is reserved.
	ErrInvalidName = errors.New("sites: invalid site name")
)
View Source
var ErrCorrupt = errors.New("sites: corrupt metadata")

ErrCorrupt is returned (wrapped) when a stored meta document or manifest cannot be decoded or exceeds its size bound. List and Get then fall back to metadata synthesized from the object listing, GetManifest to an empty manifest and Refresh rebuilds both; GetMeta reports it so that authorization checks can fail closed.

Functions

func ExtractTitle

func ExtractTitle(doc []byte) (title, description string)

ExtractTitle returns the <title> text and <meta name="description"> content of an HTML document (best effort; only the first 64 KiB are considered).

The scan is tolerant of malformed markup: comments and the contents of script/style/svg/template elements are skipped, entities are decoded and whitespace is collapsed. Results are capped at a sensible length.

func ManifestKey

func ManifestKey(site string) string

ManifestKey returns the blob key of a site's manifest.

func MetaKey

func MetaKey(site string) string

MetaKey returns the blob key of a site's metadata document.

func SiteKey

func SiteKey(site, path string) string

SiteKey returns the blob key of a file inside a site.

func UploadKey

func UploadKey(site, id, name string) string

UploadKey returns the blob key of an uploaded file.

func ValidateName

func ValidateName(name string, reserved []string) error

ValidateName checks a site name against the DNS-label pattern and the reserved list.

Types

type Manifest

type Manifest struct {
	Site      string         `json:"site"`
	UpdatedAt time.Time      `json:"updated_at"`
	Files     []ManifestFile `json:"files"`
}

Manifest records the content hashes of the last API deploy/refresh.

type ManifestFile

type ManifestFile struct {
	Path   string `json:"path"`
	Size   int64  `json:"size"`
	SHA256 string `json:"sha256"`
	ETag   string `json:"etag"` // storage etag observed after upload
}

ManifestFile is one entry of a site manifest.

type Meta

type Meta struct {
	Name        string    `json:"name"`
	URL         string    `json:"url"`
	Title       string    `json:"title,omitempty"`
	Description string    `json:"description,omitempty"`
	CreatedAt   time.Time `json:"created_at"`
	CreatedBy   string    `json:"created_by,omitempty"`
	UpdatedAt   time.Time `json:"updated_at"`
	UpdatedBy   string    `json:"updated_by,omitempty"`
	DeployID    string    `json:"deploy_id,omitempty"`
	FileCount   int       `json:"file_count"`
	Bytes       int64     `json:"bytes"`
	Owners      []string  `json:"owners"`
}

Meta is the public description of a site (SiteMeta in the spec).

func (*Meta) IsOwner

func (m *Meta) IsOwner(id, email string) bool

IsOwner reports whether id/email is listed as an owner.

type Registry

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

Registry reads and writes site metadata in the blob store.

func NewRegistry

func NewRegistry(store blob.Store, cfg *config.Config) *Registry

NewRegistry returns a registry over store.

func (*Registry) Config

func (r *Registry) Config() *config.Config

Config returns the configuration.

func (*Registry) Delete

func (r *Registry) Delete(ctx context.Context, name string) error

Delete removes a site's files, uploads, meta and manifest. The meta document goes last so an interrupted delete can be retried.

func (*Registry) Exists

func (r *Registry) Exists(ctx context.Context, name string) (bool, error)

Exists reports whether any object exists under sites/<name>/ or a meta file exists.

func (*Registry) FileDigest

func (r *Registry) FileDigest(ctx context.Context, site, path string) (*ManifestFile, error)

FileDigest returns the manifest entry of the object currently stored for path in site: its size, SHA-256 and etag, where the digest is always that of the bytes the etag identifies. It uses a digest the storage service verified itself when the store reports one (blob.DigestReporter, e.g. S3 objects uploaded with x-amz-checksum-sha256) and otherwise reads and hashes the object. A missing object yields an error wrapping blob.ErrNotFound.

func (*Registry) Files

func (r *Registry) Files(ctx context.Context, name string) ([]blob.ObjectInfo, error)

Files lists the objects of a site with keys made site-relative (no "sites/<name>/" prefix). "Directory marker" objects (keys ending in "/") are omitted.

func (*Registry) Get

func (r *Registry) Get(ctx context.Context, name string) (*Meta, error)

Get returns a site's metadata or ErrNotFound. For sites synced directly to storage without a meta file, a Meta is synthesized from the object listing.

func (*Registry) GetManifest

func (r *Registry) GetManifest(ctx context.Context, name string) (*Manifest, error)

GetManifest returns the manifest, or an empty manifest when none exists. A corrupt manifest is treated as missing: it only caches digests, so the next deploy re-uploads every file once and writes a fresh one.

func (*Registry) GetMeta

func (r *Registry) GetMeta(ctx context.Context, name string) (*Meta, error)

GetMeta returns the stored meta document of a site, without synthesizing one from the object listing. It returns ErrNotFound when none exists and an error matching ErrCorrupt when it cannot be decoded.

func (*Registry) List

func (r *Registry) List(ctx context.Context) ([]Meta, error)

List returns all sites: meta files ∪ first-level prefixes under sites/, sorted by UpdatedAt descending (then name).

func (*Registry) PutManifest

func (r *Registry) PutManifest(ctx context.Context, m *Manifest) error

PutManifest writes a site's manifest.

func (*Registry) PutMeta

func (r *Registry) PutMeta(ctx context.Context, m *Meta) error

PutMeta writes a site's metadata.

func (*Registry) Refresh

func (r *Registry) Refresh(ctx context.Context, name, actor string) (*Meta, error)

Refresh rebuilds the manifest (sha256 of every file) and meta from storage after a direct sync; actor becomes UpdatedBy (and CreatedBy/owner if new).

CreatedAt, CreatedBy and Owners of an existing meta document are kept. When the site is new and sites.ownership is "owner", a non-anonymous actor becomes its first owner.

func (*Registry) Store

func (r *Registry) Store() blob.Store

Store returns the underlying blob store.

Directories

Path Synopsis
Package sitestest provides test helpers for code built on the sites registry and the deploy gateway: an in-memory blob.Store with optional presigned uploads served by an http.Handler.
Package sitestest provides test helpers for code built on the sites registry and the deploy gateway: an in-memory blob.Store with optional presigned uploads served by an http.Handler.

Jump to

Keyboard shortcuts

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