service

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 51 Imported by: 0

Documentation

Overview

Package service is the composition root: it wires the configuration, the dependencies (PostgreSQL, Valkey) and the scenarios into the tree the Backplane SDK runs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(
	store *postgres.Store, spec accounts.Spec, cfg HTTP, docsHost, revision string,
) (http.Handler, error)

Handler builds the public API over an opened store: the production tree calls it at start, tests call it directly.

Types

type Account

type Account struct {
	ID   string `json:"id"   schemapb:"description=The account's UUID (also its API address)"`
	Slug string `json:"slug" schemapb:"description=The account's slug (also its API address)"`
	Name string `json:"name" schemapb:"description=Display name of the account"`
	// Ed25519Seed imports the vendor's signing key when the account row is
	// created; an existing row with another key fails startup.
	Ed25519Seed config.Secret `json:"ed25519_seed,omitempty" schemapb:"description=Hex ed25519 signing seed to import"`
}

Account identifies the configured account; both its id and its slug address it on the wire. ID is a string so the configuration schema validates it as one; New parses it.

type Automation

type Automation struct {
	PortalBase string `json:"portalBase,omitempty" schemapb:"description=Public portal base URL"` //nolint:tagliatelle,lll // config is camelCase
	Locale     string `json:"locale,omitempty"     schemapb:"description=Default message language (en or ru)"`
}

Automation configures links and language, not mail transport.

type Catalog added in v0.0.18

type Catalog struct {
	Products []CatalogProduct `json:"products,omitempty" schemapb:"description=Declared products"`
}

Catalog is the declared catalog. It is read at startup only: token values are secrets and never come from Consul.

type CatalogPolicy added in v0.0.18

type CatalogPolicy struct {
	ID         string         `json:"id"         schemapb:"description=The policy's UUID"`
	Attributes map[string]any `json:"attributes" schemapb:"description=Keygen policy attributes"`
}

CatalogPolicy is a declared policy: its id and its Keygen attributes, named as the API names them (maxMachines, expirationStrategy, ...).

type CatalogProduct added in v0.0.18

type CatalogProduct struct {
	ID                   string          `json:"id"                              schemapb:"description=UUID"`
	Name                 string          `json:"name"                            schemapb:"description=Name"`
	Code                 string          `json:"code,omitempty"                  schemapb:"description=Code"`
	DistributionStrategy string          `json:"distribution_strategy,omitempty" schemapb:"description=Distribution"`
	URL                  string          `json:"url,omitempty"                   schemapb:"description=URL"`
	Platforms            []string        `json:"platforms,omitempty"             schemapb:"description=Platforms"`
	Metadata             map[string]any  `json:"metadata,omitempty"              schemapb:"description=Metadata"`
	Policies             []CatalogPolicy `json:"policies,omitempty"              schemapb:"description=Policies"`
	Tokens               []CatalogToken  `json:"tokens,omitempty"                schemapb:"description=Tokens"`
}

CatalogProduct is a declared product with its policies and tokens.

type CatalogToken added in v0.0.18

type CatalogToken struct {
	Name        string        `json:"name"                  schemapb:"description=Token name, unique per product"`
	Value       config.Secret `json:"value"                 schemapb:"description=Secret prod-<64 hex>v3"`
	Permissions []string      `json:"permissions,omitempty" schemapb:"description=Product permissions (empty: all)"`
}

CatalogToken is a named product token of fixed value.

type Config

type Config struct {
	config.Backplane `json:"backplane"`

	Store postgres.Config `json:"store"`
	// Cache is optional: without it tokens are read from the store and
	// the password-attempt windows are kept per process.
	Cache *valkey.Config `json:"cache,omitempty"`

	// Account is the single account of the installation: the row is
	// created at startup from these fields when missing.
	Account Account `json:"account"`

	// Catalog declares products, their policies and named product tokens,
	// reconciled at every start; empty declares nothing.
	Catalog Catalog `json:"catalog,omitempty"`

	// HTTP is the public API's runtime section.
	HTTP HTTP `json:"http"`

	Automation Automation `json:"automation,omitempty"`

	// Brand is the vendor identity customers see: the portal's header,
	// accent color and footer links, and the brand_* data of every message.
	Brand domain.Brand `json:"brand,omitempty"`

	// DocsHost overrides the docs origin of error links (the reference
	// derives it from its configured host); empty derives it from the
	// request host.
	DocsHost string `json:"docsHost,omitempty" schemapb:"description=Docs links origin"` //nolint:tagliatelle,lll // camelCase
}

Config is the whole configuration: file (BACKPLANE_CONFIG_FILE) < env LIC_* (BACKPLANE_* for the SDK block) < Consul KV for Live fields.

type HTTP

type HTTP struct {
	// Portal serves the standalone customer SPA on the public HTTP listener.
	Portal portal.Config `json:"portal,omitempty"`
	// TrustedProxies lists the proxy CIDRs (or single IPs) whose
	// X-Forwarded-For is honored when resolving the client address;
	// empty means every request is keyed by its remote address.
	TrustedProxies []string `json:"trustedProxies,omitempty" schemapb:"description=Proxies"` //nolint:tagliatelle,lll // camelCase
	// WebhookAllowPrivate lists the otherwise-private CIDRs webhook
	// endpoint URLs may resolve to (the self-hosted escape hatch for
	// internal receivers; the reference's
	// KEYGEN_ALLOWED_PRIVATE_ADDRESSES).
	WebhookAllowPrivate []string `json:"webhookAllowPrivate,omitempty" schemapb:"description=Private webhook CIDRs"` //nolint:tagliatelle,lll // camelCase
}

HTTP holds the public API's runtime settings.

type Service

type Service struct {
	Console *console.Server
	Store   deps.Dependency[*postgres.Store]
	Cache   deps.Optional[valkey.AsideClient]
	// HTTP is the public JSON:API (the full middleware pipeline: request
	// id, negotiation, authentication, response signing); it answers 503
	// until the tree has started.
	HTTP http.Handler
}

Service is the built tree plus what main declares on the platform.

func New

func New(root backplane.Root[Config]) (*Service, error)

New builds the tree under root: the store and cache dependencies, and a start step that creates the account row from configuration and builds the HTTP handler over the started store.

Jump to

Keyboard shortcuts

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