Documentation
¶
Overview ¶
Package multisite resolves an authorized exact authority to a stable site ID. Products own ingress trust, authentication, site bindings and domain isolation.
SPDX-License-Identifier: MPL-2.0
Index ¶
- Constants
- Variables
- func Version() string
- type ActivationPlan
- func (p ActivationPlan) AfterRevision() string
- func (p ActivationPlan) BeforeRevision() string
- func (p ActivationPlan) Descriptors() []achrix.Descriptor
- func (p ActivationPlan) Replacement(current Config, input ManagementConfig) (ManagementConfig, error)
- func (p ActivationPlan) Selection() SiteSelection
- func (p ActivationPlan) Site() SiteID
- type ActivationRequest
- type Config
- type InventoryPage
- type ManagementConfig
- type Module
- type Service
- func (s *Service) Inventory(parent context.Context, actor achrix.Principal, cursor string, limit int) (InventoryPage, error)
- func (s *Service) PlanActivation(parent context.Context, actor achrix.Principal, request ActivationRequest) (ActivationPlan, error)
- func (s *Service) Resolve(parent context.Context, actor achrix.Principal, authority string) (SiteID, error)
- func (s *Service) Site(parent context.Context, actor achrix.Principal, id SiteID) (SiteInfo, error)
- type Site
- type SiteID
- type SiteInfo
- type SiteSelection
Examples ¶
Constants ¶
const ( InventoryRead = "achrix.multisite.inventory.read" PlanActivation = "achrix.multisite.activation.plan" // InventoryTarget gates collection discovery in addition to exact-site reads. InventoryTarget = "" )
const Resolve = "achrix.multisite.resolve"
Variables ¶
var ( ErrConfiguration = errors.New("invalid multisite configuration") ErrInput = errors.New("invalid multisite input") ErrNotFound = errors.New("multisite site not found") )
var ErrConflict = errors.New("multisite configuration conflict")
Functions ¶
Types ¶
type ActivationPlan ¶
type ActivationPlan struct {
// contains filtered or unexported fields
}
ActivationPlan is an immutable target-only proposal. It contains no authority, service/store handle, other-site inventory or private product configuration.
func (ActivationPlan) AfterRevision ¶
func (p ActivationPlan) AfterRevision() string
func (ActivationPlan) BeforeRevision ¶
func (p ActivationPlan) BeforeRevision() string
func (ActivationPlan) Descriptors ¶
func (p ActivationPlan) Descriptors() []achrix.Descriptor
func (ActivationPlan) Replacement ¶
func (p ActivationPlan) Replacement(current Config, input ManagementConfig) (ManagementConfig, error)
Replacement is a pure trusted-caller helper over the caller's OWN supplied configuration. It never retrieves another site's private server configuration. It validates the expected target/catalogue revision and returns a defensive updated copy. It acquires no resource and grants no permission. Before actual persistence/activation the product reauthorizes and serializes/CASes its state.
func (ActivationPlan) Selection ¶
func (p ActivationPlan) Selection() SiteSelection
func (ActivationPlan) Site ¶
func (p ActivationPlan) Site() SiteID
type ActivationRequest ¶
type Config ¶
type Config struct{ Sites []Site }
Config is trusted, finite product composition input. New copies its inventory; replacing configuration requires a new validated Module/Application composition. No arbitrary site-count limit is imposed; products own inventory/resource budgets.
type InventoryPage ¶
type ManagementConfig ¶
type ManagementConfig struct {
Available []achrix.Descriptor
Sites []SiteSelection
}
ManagementConfig is trusted composition input. Available contains public, side-effect-free descriptors for product-wired factories, never service handles. Sites may omit a declared site to select no Modules for that site.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module owns immutable bindings and one-shot lifecycle state. It acquires no storage/network resources and starts no workers. Do not share a Module between Applications; products explicitly wire its Service to its owning Application.
func New ¶
New validates the complete inventory before any runtime effect. Every site requires at least one authority; duplicate IDs or authorities (even repeated aliases for one site) are rejected. Validation and copying are linear in input.
func NewManaged ¶
func NewManaged(config Config, input ManagementConfig) (*Module, error)
NewManaged adds optional inventory and selection planning to the existing resolver. It validates and copies all input before effects, constructs no selected Module and acquires no resource. Existing New remains resolver-only.
func (*Module) Descriptor ¶
func (m *Module) Descriptor() achrix.Descriptor
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service traverses Core authorization and the owning Module lifecycle. app must be the Application composing module; typed collaborators are explicitly product-wired, as with other Foundation Services, never discovered from metadata.
func NewService ¶
func NewService(app *achrix.Application, module *Module) (*Service, error)
func (*Service) Inventory ¶
func (s *Service) Inventory(parent context.Context, actor achrix.Principal, cursor string, limit int) (InventoryPage, error)
Inventory requires both collection-discovery permission and exact-site reads. Denied sites produce no entry, total or cursor identity. The cursor contains only the last returned authorized SiteID. Evaluation failure aborts the page. Work cooperatively stops within one second; result size is 1..100 sites.
func (*Service) PlanActivation ¶
func (s *Service) PlanActivation(parent context.Context, actor achrix.Principal, request ActivationRequest) (ActivationPlan, error)
PlanActivation authorizes a target-specific proposal, not activation itself. The returned plan exposes only the target's public selection. Persist/activate only after fresh authorization and a product-owned compare-and-swap, followed by supported domain drain/reconstruction/readiness/activation.
func (*Service) Resolve ¶
func (s *Service) Resolve(parent context.Context, actor achrix.Principal, authority string) (SiteID, error)
Resolve validates syntax without revealing binding existence, then authorizes the exact authority before lookup. A derived maximum one-second context retains any earlier caller deadline/cancellation. Policies are trusted synchronous code and must honor cancellation; this API cannot forcibly interrupt callbacks. Unknown and disabled bindings share ErrNotFound. The result is only a site ID: TLS/Host/proxy trust, resource access and site-to-Application/store bindings are separate product responsibilities. No normalization, suffix/default-port fallback or discovery occurs. Lookup is constant time in configured inventory size.
Example ¶
package main
import (
"context"
"fmt"
"time"
"github.com/AChWorks/achrix"
"github.com/AChWorks/achrix/multisite"
)
func main() {
resolver, err := multisite.New(multisite.Config{Sites: []multisite.Site{
{ID: "site-a", Authorities: []string{"a.example", "a.example:443"}},
{ID: "site-b", Authorities: []string{"b.example"}},
}})
if err != nil {
panic(err)
}
// This example's product policy grants only authority resolution. Actual
// authentication, trusted ingress and site resource authorization are separate.
policy := achrix.PolicyFunc(func(_ context.Context, actor achrix.Principal, capability, authority string) error {
if actor == "product-router" && capability == multisite.Resolve && authority == "a.example" {
return nil
}
return achrix.ErrDenied
})
app, err := achrix.New(achrix.Config{StartupTimeout: time.Second, ShutdownTimeout: time.Second}, policy, resolver)
if err != nil {
panic(err)
}
service, err := multisite.NewService(app, resolver)
if err != nil {
panic(err)
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
if err = app.Start(ctx); err != nil {
panic(err)
}
id, err := service.Resolve(ctx, "product-router", "a.example")
if err != nil {
panic(err)
}
fmt.Println(id)
cleanup, cleanupCancel := context.WithTimeout(context.Background(), time.Second)
defer cleanupCancel()
if err = app.Shutdown(cleanup); err != nil {
panic(err)
}
}
Output: site-a
type Site ¶
Site declares exact canonical authorities. Disabled sites retain their bindings but resolve like unknown authorities; the default is active.
type SiteID ¶
type SiteID string
SiteID is a stable product-selected ASCII identity, not a permission grant. Valid identities match [A-Za-z0-9][A-Za-z0-9_-]{0,63}.
type SiteInfo ¶
SiteInfo exposes only authorized public site/selection metadata. Disabled retains its resolver meaning; it is not a universal product lifecycle state. Revision binds this site's selection, Disabled value and available catalogue.
type SiteSelection ¶
type SiteSelection struct {
ID SiteID
Modules []string
// Generation is a product-persisted monotonic selection precondition.
// Replacement increments it; disabling/re-enabling must retain it.
Generation uint64
}
SiteSelection selects compiled Modules for one site's next Application. Omission or removal retains the owning Module's durable data.