edge

package
v0.0.0-...-611bec0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 21 Imported by: 14

Documentation

Index

Constants

View Source
const (
	PreviewTokenLen = 16

	PreviewTailLen = PreviewTokenLen + previewMACLen
)
View Source
const (
	NextRouteTableFile = "next-route-table.json"
	OcelRouteTableFile = "ocel-route-table.json"
)
View Source
const (
	ImmutableCacheControl  = "public, max-age=31536000, immutable"
	RevalidateCacheControl = "public, max-age=0, must-revalidate"
)
View Source
const (
	OcelRouteTableVar = "OCEL_ROUTE_TABLE"
	ReleaseTokenVar   = "OCEL_RELEASE_TOKEN"
	EdgeCacheVar      = "OCEL_EDGE_CACHE"

	EdgeCacheControlHeaderVar = "OCEL_EDGE_CACHE_CONTROL_HEADER"
)
View Source
const (
	OriginSecretVar         = "OCEL_ORIGIN_SECRET"
	OriginSecretPreviousVar = "OCEL_ORIGIN_SECRET_PREVIOUS"
	OriginSignedVar         = "OCEL_ORIGIN_SIGNED"
	OriginDispatchVar       = "OCEL_ORIGIN_DISPATCH"
	CacheTagPurgeVar        = "OCEL_CACHE_TAG_PURGE"
	OriginSecretHeader      = "x-ocel-origin-secret"

	OriginContainerHeader = "x-ocel-container"
)
View Source
const AppBundleFile = "edge/bundle.json"
View Source
const EdgeGroupKind = "edge"
View Source
const HeaderClientAddress = "x-ocel-client-address"
View Source
const HeaderClientAuthorization = "x-ocel-client-authorization"
View Source
const HeaderEmptyBody = "x-ocel-empty-body"
View Source
const ImageOptimizerURLVar = "OCEL_IMAGE_OPTIMIZER_URL"
View Source
const LivenessProbeLabel = "ocel-edge-probe"
View Source
const LivenessProbePath = "/.well-known/ocel-edge"
View Source
const OcelRouteTableVersion = 1
View Source
const OriginCertificateRenewal = 182 * 24 * time.Hour
View Source
const OriginFrontedVar = "OCEL_ORIGIN_FRONTED"
View Source
const OriginGroupName = "origin"
View Source
const OriginReachVar = "OCEL_ORIGIN"
View Source
const PreviewEntryOwner = "ocel-preview-entry"
View Source
const PreviewKeyVar = "OCEL_PREVIEW_KEY"
View Source
const PreviewLabelMaxLen = 63
View Source
const ProxyPlaceholder = "100::"
View Source
const PurgeURLVar = "OCEL_PURGE_URL"
View Source
const StaticAssetDir = "static"
View Source
const StaticRulesVar = "OCEL_STATIC_RULES"

Variables

View Source
var ErrStoreAbsent = errors.New("the releases store is not provisioned")

Functions

func AttributeHostnames

func AttributeHostnames(project []string, apps [][]string) [][]string

func DerivePurgeSecret

func DerivePurgeSecret(seed, storageCoordinate string) string

func EdgeGroupName

func EdgeGroupName(kind Kind) string

func ListPreviewHostnames

func ListPreviewHostnames(hosts []PreviewHost) []string

func Loopback

func Loopback(hostname string) bool

func NeedNames

func NeedNames(needs []Need) []string

func NewCachingOriginEnv

func NewCachingOriginEnv(facts Facts, release string) map[string]string

func NewPreviewToken

func NewPreviewToken() (string, error)

func OriginSecretFingerprint

func OriginSecretFingerprint(secret string) string

func Pointable

func Pointable(target DNSTarget, bound []string, hostname string) bool

func PreviewWildcard

func PreviewWildcard(baseDomain string) string

func ProbeHostname

func ProbeHostname(hostname string) string

func RefuseUnusablePreviewBase

func RefuseUnusablePreviewBase(base string) error

func ValidNeed

func ValidNeed(need Need) bool

func ValidPlanAction

func ValidPlanAction(action PlanAction) bool

func ZoneOwns

func ZoneOwns(hostname, zone string) bool

Types

type Adoption

type Adoption struct {
	ReleasesStore bool
}

type BootstrapOutput

type BootstrapOutput struct {
	Trust         TrustBoundary
	ReleasesStore *ReleasesStore
}

type BootstrapPart

type BootstrapPart struct {
	Name    string
	Current bool
}

type CacheRule

type CacheRule struct {
	Revalidate  int      `json:"revalidate"`
	Expire      *int     `json:"expire,omitempty"`
	AllowQuery  []string `json:"allowQuery,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	BypassToken *string  `json:"bypassToken,omitempty"`
}

type CacheTagLimits

type CacheTagLimits struct {
	TagBytes    int
	Tags        int
	HeaderBytes int
}

func (CacheTagLimits) IsZero

func (l CacheTagLimits) IsZero() bool

type ClientCertificateHooks

type ClientCertificateHooks struct {
	RefuseUnready func(ctx context.Context, tier environment.Tier, hostname string) error
	Ensure        func(ctx context.Context, tier environment.Tier, hostname string) ([]string, error)
	Present       func(ctx context.Context, tier environment.Tier, hostname string) error
}

type CodeEntitlement

type CodeEntitlement struct {
	Plan    string
	Granted Entitlement
	Reason  string
}

type CredentialDocument

type CredentialDocument struct {
	Heading  string
	Document string
}

type CredentialIdentity

type CredentialIdentity struct {
	Account string
}

type CredentialPurpose

type CredentialPurpose string
const (
	PurposeBootstrap CredentialPurpose = "bootstrap"
	PurposeDeploy    CredentialPurpose = "deploy"
)

type DNSRecords

type DNSRecords interface {
	Ensure(ctx context.Context, records []Record, say func(string)) ([]Record, error)

	Delete(ctx context.Context, records []Record) error

	TTL() time.Duration

	VerifyCredentials(ctx context.Context) error
}

type DNSTarget

type DNSTarget struct {
	Kind           Kind
	ServesUnbound  bool
	ProxiesRecords bool
	Address        string
	AddressByHost  map[string]string
}

func TargetFor

func TargetFor(e Edge, state StackState) DNSTarget

func TargetOf

func TargetOf(kind Kind, facts Facts, state StackState) DNSTarget

func (DNSTarget) AddressFor

func (t DNSTarget) AddressFor(hostname string) string

type DomainBinding

type DomainBinding struct {
	Hostname    string
	Certificate string
	App         string
	Origin      *Origin
	Say         func(string)
}

type Edge

type Edge interface {
	Kind() Kind

	Facts() Facts

	Hooks() Hooks

	Bootstrap(ctx context.Context, tier environment.Tier) (BootstrapOutput, error)

	Teardown(ctx context.Context, tier environment.Tier) error

	Reconcile(ctx context.Context, spec StackSpec, prior StackState) (EdgeStack, error)

	Open(state StackState) (EdgeStack, error)

	ReconcilePreviewWildcard(ctx context.Context, spec PreviewWildcardSpec) (string, error)

	DestroyPreviewWildcard(ctx context.Context, baseDomain string) error

	DomainOwner(ctx context.Context, hostname string) (string, error)

	ProjectOwner(ctx context.Context, slug string, tier environment.Tier) (string, error)

	PlanProjectRemoval(scope ProjectScope) ([]PlanGroup, error)

	PlanPreviewWildcardRemoval(wildcard string) (removed, kept PlanGroup, err error)

	PlanSharedPreviewRemoval() PlanGroup
}

type EdgeCacheMode

type EdgeCacheMode string
const (
	EdgeCacheNone   EdgeCacheMode = ""
	EdgeCacheMarked EdgeCacheMode = "marked"
	EdgeCacheAll    EdgeCacheMode = "all"
)

func NewEdgeCacheMode

func NewEdgeCacheMode(facts Facts) EdgeCacheMode

type EdgeStack

type EdgeStack interface {
	State() StackState

	BindDomain(ctx context.Context, binding DomainBinding) error

	UnbindDomain(ctx context.Context, hostname string) error

	Destroy(ctx context.Context) error
}

type Entitlement

type Entitlement string
const (
	EntitlementUnknown  Entitlement = "unknown"
	EntitlementGranted  Entitlement = "granted"
	EntitlementWithheld Entitlement = "withheld"
)

type Facts

type Facts struct {
	Supported             []Need
	RunsCode              bool
	ServesUnbound         bool
	ProxiesRecords        bool
	ProxiedRecordNote     string
	ShieldsOrigin         bool
	TunnelsToOrigin       bool
	OriginFacingRanges    []string
	InvalidatesByCacheTag bool
	CachesResponses       bool
	CacheControlHeader    string
	CacheTagLimits        CacheTagLimits
	PurgeBudget           PurgeBudget
	Gates                 bool
	GatesAtOrigin         bool
	ChecksSignedPasswords bool
	CredentialScope       string
}

type Fallback

type Fallback struct {
	Function string `json:"function"`
}

type GatePublication

type GatePublication struct {
	State StackState
	Gate  *gate.Gate
	Say   func(string)
}

type HeaderRule

type HeaderRule struct {
	Src     string            `json:"src"`
	Headers map[string]string `json:"headers"`
}

type Hooks

type Hooks struct {
	PlanBootstrap                 func(ctx context.Context, tier environment.Tier) ([]PlanChange, error)
	PlanRemoveBootstrap           func(ctx context.Context, tier environment.Tier) ([]PlanChange, error)
	PlanAdoption                  func(ctx context.Context, tier environment.Tier) (Adoption, error)
	DescribeBootstrap             func(ctx context.Context, tier environment.Tier) ([]BootstrapPart, error)
	CheckBootstrapInstalled       func(ctx context.Context, tier environment.Tier) (bool, error)
	ListBoundHostnames            func(ctx context.Context, tier environment.Tier) ([]string, error)
	VerifyCredentials             func(ctx context.Context) (CredentialIdentity, error)
	CheckCodeEntitlement          func(ctx context.Context) (CodeEntitlement, error)
	DescribeCredentialPermissions func(purpose CredentialPurpose) (CredentialDocument, error)
	ClientCertificates            *ClientCertificateHooks
	OriginCertificates            *OriginCertificateHooks
	PurgeHostnames                func(ctx context.Context, hostnames []string) error
	Tunnels                       *TunnelHooks
	PublishGate                   func(ctx context.Context, publication GatePublication) error
}

type Kind

type Kind string
const None Kind = ""

func EdgeGroupKindOf

func EdgeGroupKindOf(name string) (Kind, bool)

type Need

type Need string
const (
	NeedEdgeMiddleware Need = "edge-middleware"
	NeedEdgeRuntime    Need = "edge-runtime"
	NeedPPRResume      Need = "ppr-resume"
	NeedEdgeCache      Need = "edge-cache"
	NeedStreaming      Need = "streaming"
	NeedRevalidation   Need = "revalidation"
)

func AllNeeds

func AllNeeds() []Need

func CodeNeeds

func CodeNeeds() []Need

type OcelRouteTable

type OcelRouteTable struct {
	Version       int            `json:"version"`
	BasePath      string         `json:"basePath"`
	TrailingSlash TrailingSlash  `json:"trailingSlash"`
	Headers       []HeaderRule   `json:"headers"`
	Redirects     []RedirectRule `json:"redirects"`
	Routes        []Route        `json:"routes"`
	Fallback      Fallback       `json:"fallback"`
}

func ReadOcelRouteTable

func ReadOcelRouteTable(raw []byte) (OcelRouteTable, error)

func (OcelRouteTable) Functions

func (r OcelRouteTable) Functions() []string

func (OcelRouteTable) HasCachedRoute

func (r OcelRouteTable) HasCachedRoute() bool

type Origin

type Origin struct {
	Address   string
	Certified bool
	Tunneled  bool
}

type OriginCertificate

type OriginCertificate struct {
	ID          string
	Certificate string
	Key         string
	ExpiresAt   time.Time
}

func (OriginCertificate) IsDue

func (c OriginCertificate) IsDue(now time.Time) bool

type OriginCertificateHooks

type OriginCertificateHooks struct {
	Issue  func(ctx context.Context, hostname string) (OriginCertificate, error)
	Revoke func(ctx context.Context, id string) error
}

type OriginImages

type OriginImages struct {
	OptimizerURL    string `json:"optimizerUrl,omitempty"`
	MaxRequestBytes int64  `json:"maxRequestBytes,omitempty"`
}

type OriginReach

type OriginReach struct {
	Reach    Reach         `json:"reach"`
	Store    *OriginStore  `json:"store,omitempty"`
	Throttle Throttle      `json:"throttle"`
	Images   *OriginImages `json:"images,omitempty"`
}

func (OriginReach) RefuseIncomplete

func (o OriginReach) RefuseIncomplete() error

type OriginStore

type OriginStore struct {
	URL             string `json:"url"`
	Region          string `json:"region"`
	HoldsEntries    bool   `json:"holdsEntries"`
	AccessKeyID     string `json:"accessKeyId"`
	SecretAccessKey string `json:"secretAccessKey"`
}

type Outstanding

type Outstanding struct {
	Kind string
	Name string
}

type OutstandingError

type OutstandingError struct {
	Because string
	Waited  time.Duration
	Items   []Outstanding
}

func (*OutstandingError) Error

func (e *OutstandingError) Error() string

type PlanAction

type PlanAction string
const (
	PlanCreate            PlanAction = "create"
	PlanUpdate            PlanAction = "update"
	PlanDelete            PlanAction = "delete"
	PlanDisableThenDelete PlanAction = "disable-then-delete"
	PlanKeep              PlanAction = "keep"
)

type PlanChange

type PlanChange struct {
	Kind   string
	Name   string
	Action PlanAction
	Reason string
	Slow   bool
}

type PlanGroup

type PlanGroup struct {
	Kind    string
	Name    string
	Part    string
	Action  PlanAction
	Reason  string
	Slow    bool
	Changes []PlanChange
}

type PreviewHost

type PreviewHost struct {
	Hostname string `json:"hostname"`
	App      string `json:"app,omitempty"`
}

func (PreviewHost) ReadLabel

func (h PreviewHost) ReadLabel() string

func (PreviewHost) ReadPrefix

func (h PreviewHost) ReadPrefix() string

func (PreviewHost) ReadTail

func (h PreviewHost) ReadTail() string

type PreviewKey

type PreviewKey string

func NewPreviewKey

func NewPreviewKey() (PreviewKey, error)

func (PreviewKey) Sign

func (k PreviewKey) Sign(prefix, token string) string

type PreviewSite

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

func NewProjectPreviewSite

func NewProjectPreviewSite(baseDomain string, key PreviewKey) PreviewSite

func NewSharedPreviewSite

func NewSharedPreviewSite(slug, baseDomain string, key PreviewKey) PreviewSite

func (PreviewSite) IsServing

func (s PreviewSite) IsServing() bool

func (PreviewSite) ListHosts

func (s PreviewSite) ListHosts(name, token string, apps []string) []PreviewHost

func (PreviewSite) RefuseOverlongLabels

func (s PreviewSite) RefuseOverlongLabels(hosts []PreviewHost) error

type PreviewWildcardSpec

type PreviewWildcardSpec struct {
	Version     string
	BaseDomain  string
	Certificate string
	Say         func(string)
	Warn        func(string)
	Program     *Program
	Origin      *Origin
}

type Private

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

func Own

func Own(value any) Private

func (Private) Into

func (p Private) Into(target any) error

func (Private) IsZero

func (p Private) IsZero() bool

func (Private) MarshalJSON

func (p Private) MarshalJSON() ([]byte, error)

func (*Private) UnmarshalJSON

func (p *Private) UnmarshalJSON(raw []byte) error

type Program

type Program struct {
	Origin            OriginReach
	ReleasesStore     ReleasesStore
	PreviewBaseDomain string
	PreviewKey        PreviewKey
}

type ProjectScope

type ProjectScope struct {
	Slug      string
	Tier      environment.Tier
	Hostnames []string
	Address   string
}

type PurgeBudget

type PurgeBudget struct {
	TagsPerPurge int
}

func (PurgeBudget) IsZero

func (b PurgeBudget) IsZero() bool

type Reach

type Reach struct {
	Kind                ReachKind `json:"kind"`
	Service             string    `json:"service,omitempty"`
	Region              string    `json:"region,omitempty"`
	AccessKeyID         string    `json:"accessKeyId,omitempty"`
	SecretAccessKey     string    `json:"secretAccessKey,omitempty"`
	Secret              string    `json:"secret,omitempty"`
	PreviousSecret      string    `json:"previousSecret,omitempty"`
	PreviousFingerprint string    `json:"previousFingerprint,omitempty"`
}

type ReachKind

type ReachKind string
const (
	ReachSigV4        ReachKind = "sigv4"
	ReachOriginSecret ReachKind = "origin-secret"
)

type Record

type Record struct {
	Name    string     `json:"name"`
	Type    RecordType `json:"type"`
	Value   string     `json:"value"`
	Proxied bool       `json:"proxied,omitempty"`
}

func RecordsFor

func RecordsFor(target DNSTarget, hostnames []string) ([]Record, error)

func Unwritten

func Unwritten(wanted, written []Record) []Record

func (Record) ApexNote

func (r Record) ApexNote(zone string) string

func (Record) Instruction

func (r Record) Instruction() string

func (Record) String

func (r Record) String() string

type RecordType

type RecordType string
const (
	RecordTypeA     RecordType = "A"
	RecordTypeAAAA  RecordType = "AAAA"
	RecordTypeCNAME RecordType = "CNAME"
)

type RedirectRule

type RedirectRule struct {
	Src      string `json:"src"`
	Location string `json:"location"`
	Status   int    `json:"status"`
}

type ReleasesStore

type ReleasesStore struct {
	Name                string
	Endpoint            string
	BootstrapCredential string
}

type Route

type Route struct {
	Src      string     `json:"src"`
	Function string     `json:"function"`
	Cache    *CacheRule `json:"cache,omitempty"`
}

type RouteTableFormat

type RouteTableFormat string
const (
	RouteTableNext RouteTableFormat = "next"
	RouteTableOcel RouteTableFormat = "ocel"
)

type StackSpec

type StackSpec struct {
	Version    string
	Tier       environment.Tier
	Slug       string
	Domains    []string
	DomainApps map[string]string

	ServedElsewhere []string
	GlobalPreview   string
	PruneOnly       bool
	Gate            *gate.Gate
	Say             func(string)
	Warn            func(string)
	Program         *Program
}

type StackState

type StackState struct {
	Slug          string            `json:"slug,omitempty"`
	Tier          environment.Tier  `json:"tier,omitempty"`
	Endpoint      string            `json:"endpoint,omitempty"`
	Secret        string            `json:"secret,omitempty"`
	Address       string            `json:"address,omitempty"`
	Addresses     map[string]string `json:"addresses,omitempty"`
	Bound         []string          `json:"bound,omitempty"`
	Records       []Record          `json:"records,omitempty"`
	GlobalPreview string            `json:"globalPreview,omitempty"`
	PreviewBase   string            `json:"previewBase,omitempty"`
	PurgeURL      string            `json:"purgeURL,omitempty"`
	Private       Private           `json:"private,omitzero"`
}

func (*StackState) Bind

func (s *StackState) Bind(hostname string)

func (StackState) Empty

func (s StackState) Empty() bool

func (StackState) Equal

func (s StackState) Equal(other StackState) bool

func (*StackState) PublishAddress

func (s *StackState) PublishAddress(hostname, address string)

func (*StackState) RecordWrites

func (s *StackState) RecordWrites(records []Record)

func (*StackState) Release

func (s *StackState) Release(hostname string)

func (StackState) ServedOnGlobalPreview

func (s StackState) ServedOnGlobalPreview(baseDomain string) bool

type Static

type Static struct {
	ImmutablePrefixes      []string `json:"immutablePrefixes"`
	MustRevalidatePrefixes []string `json:"mustRevalidatePrefixes,omitempty"`
}

func (*Static) CacheControl

func (s *Static) CacheControl(path string) string

func (*Static) IsImmutable

func (s *Static) IsImmutable(path string) bool

func (*Static) Variable

func (s *Static) Variable() string

type Throttle

type Throttle struct {
	Status       int    `json:"status"`
	Header       string `json:"header,omitempty"`
	BodyContains string `json:"bodyContains,omitempty"`
}

type TrailingSlash

type TrailingSlash string
const (
	TrailingSlashNever  TrailingSlash = "never"
	TrailingSlashAlways TrailingSlash = "always"
	TrailingSlashIgnore TrailingSlash = "ignore"
)

type TrustBoundary

type TrustBoundary string
const (
	TrustExternal TrustBoundary = "external"
	TrustInternal TrustBoundary = "internal"
)

type Tunnel

type Tunnel struct {
	ID      string
	Address string
}

type TunnelConnector

type TunnelConnector struct {
	Image                string
	Command              []string
	TokenFileEnv         string
	Ready                []string
	VisitorAddressHeader string
	VisitorSchemeHeader  string
}

type TunnelHooks

type TunnelHooks struct {
	Connector TunnelConnector
	Ensure    func(ctx context.Context, name string) (Tunnel, error)
	Configure func(ctx context.Context, id, service string) error
	ReadToken func(ctx context.Context, id string) (string, error)
	Delete    func(ctx context.Context, id string) error
}

type Zone

type Zone struct {
	ID   string
	Name string
}

func SelectZone

func SelectZone(zones []Zone, hostname, named string) (Zone, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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