config

package
v0.2.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

AllClaims lists every claim a custom provider has to map.

Functions

func ApplyPageDefaults added in v0.2.0

func ApplyPageDefaults(v *viper.Viper)

ApplyPageDefaults expands the optional top-level `pageDefaults` block into every entry under `pages`, so common settings (bucket, proxy, git, preview) can be declared once instead of repeated per page.

Each page is deep-merged over the defaults: a value the page sets wins, and anything it omits is inherited — recursively, per leaf field. Lists (such as proxy.searchPath) are replaced wholesale rather than concatenated. The merge runs on the raw config maps before unmarshalling, so a field that is present with a zero value (e.g. `preview.enabled: false`) still overrides a non-zero default — something a struct-level merge could not distinguish from "unset".

It is a no-op when `pageDefaults` is absent, leaving behavior unchanged.

func SetDefaults added in v0.2.2

func SetDefaults(v *viper.Viper)

SetDefaults registers the default value of every setting that has one, so a configuration file only needs to name what it changes.

Types

type BucketConfig

type BucketConfig struct {
	URL           EnvValue `yaml:"url"`
	Name          EnvValue `yaml:"name"`
	ApplicationID EnvValue `yaml:"applicationId"`
	Secret        EnvValue `yaml:"secret"`
	Region        EnvValue `yaml:"region"`
}

BucketConfig locates the S3-compatible bucket a page is uploaded to.

type Claim

type Claim string

Claim names a piece of information StaticPages reads from an OIDC token.

const (
	// RepositoryClaim is the repository that published the upload.
	RepositoryClaim Claim = "repository"
	// CommitClaim is the commit the upload was built from.
	CommitClaim Claim = "commit"
	// BranchClaim is the branch the commit is on.
	BranchClaim Claim = "branch"
	// EnvironmentClaim is the deployment environment, if any.
	EnvironmentClaim Claim = "environment"
)

type ClaimMap

type ClaimMap map[Claim]string

ClaimMap maps each Claim to the name of the token claim that carries it.

type ClaimMapRaw

type ClaimMapRaw map[string]string

ClaimMapRaw maps claim names, as written in the configuration, to token claims.

func (ClaimMapRaw) AsTyped

func (cm ClaimMapRaw) AsTyped() ClaimMap

AsTyped converts the configured mapping to a ClaimMap.

type DomainMapper

type DomainMapper map[DomainScope]*Page

DomainMapper is a wrapper around a map of DomainMatcher to Page pointers that provides methods for longest-prefix matching.

func NewDomainMapperFromPages

func NewDomainMapperFromPages(pages []*Page) DomainMapper

NewDomainMapperFromPages indexes the pages by their domain.

func (DomainMapper) GetMatchingDomain

func (dm DomainMapper) GetMatchingDomain(domain string) DomainScope

GetMatchingDomain returns the DomainMatcher that was used for the longest match This can be useful for informational purposes or debugging

func (DomainMapper) Lookup

func (dm DomainMapper) Lookup(domain string) *Page

Lookup finds the longest matching DomainMatcher for a given domain and returns the corresponding *Page. Returns nil if no match is found.

For example, with a map containing "specht.av0.de" and "cedi.av0.de" as keys, a lookup for "dev.specht.av0.de" would return the page for "specht.av0.de".

type DomainScope

type DomainScope string

DomainScope is a string that represents a Domain Name. The speciality of DomainScope is the ability to perform a longest-prefix-match of a given domain against the DomainScope Domain. For Example: domain := DomainScope("example.com") domain.Is("example.com") == true domain.Is("foo.example.com") == true domain.Is("foo.bar.com") == false domain.Subdomain("foo.bar.example.com") = "foo.bar", error(nil) domain.Subdomain("foo.bar.com") = "", error(foo.bar.com is not associated with example.com)

func FromString

func FromString(domain string) DomainScope

FromString creates a new DomainScope from a string

func (DomainScope) HasParent

func (d DomainScope) HasParent(parent DomainScope) bool

HasParent checks if this domain is a subdomain of the provided parent

func (DomainScope) Is

func (d DomainScope) Is(domain string) bool

Is checks if the given domain matches or is a subdomain of the DomainScope. Returns true if the domain is either exactly the same as the DomainScope or is a subdomain of it (ends with .DomainScope).

func (DomainScope) Level

func (d DomainScope) Level() int

Level returns the domain level (number of dot-separated parts) For example: "foo.example.com" -> 3, "example.com" -> 2, "com" -> 1

func (DomainScope) Normalize

func (d DomainScope) Normalize() DomainScope

Normalize ensures the domain is in a consistent format (currently just returns the domain as-is, but could be extended to handle normalization like stripping trailing dots, lowercasing, etc.)

func (DomainScope) Parent

func (d DomainScope) Parent() DomainScope

Parent returns the parent domain of the current domain, or empty string if it's a top-level domain For example: "foo.example.com" -> "example.com", "example.com" -> "com", "com" -> ""

func (DomainScope) String

func (d DomainScope) String() string

String returns the string representation of the DomainScope

func (DomainScope) Subdomain

func (d DomainScope) Subdomain(domain string) (string, humane.Error)

Subdomain extracts the subdomain part from a given domain. For example, if DomainScope is "example.com" and domain is "foo.bar.example.com", it returns "foo.bar". Returns an error if the given domain is not associated with the DomainScope.

type EnvValue

type EnvValue string

EnvValue represents a value that can be either a literal string or an environment variable reference using ENV('VAR_NAME')

func (EnvValue) String

func (e EnvValue) String() string

String returns the string representation of the EnvValue.

func (*EnvValue) Validate

func (e *EnvValue) Validate() humane.Error

type Format

type Format string

Format selects how the CLI renders its output.

const (
	// ShortFormat prints compact output.
	ShortFormat Format = "short"
	// LongFormat prints verbose output.
	LongFormat Format = "long"
)

type GitConfig

type GitConfig struct {
	Oidc       GitProvider `yaml:"oidc"`
	Provider   string      `yaml:"provider"`
	Repository string      `yaml:"repository"`
	MainBranch string      `yaml:"mainBranch"`
}

GitConfig names the repository allowed to publish a page and the provider whose OIDC tokens prove it.

func (*GitConfig) GetOidcClaimMapping

func (g *GitConfig) GetOidcClaimMapping() (ClaimMap, humane.Error)

GetOidcClaimMapping returns how the configured provider's token claims map to the claims StaticPages reads.

func (*GitConfig) GetOidcIssuer

func (g *GitConfig) GetOidcIssuer() (string, humane.Error)

GetOidcIssuer returns the OIDC issuer of the configured provider.

type GitProvider

type GitProvider struct {
	ClaimMappings ClaimMapRaw `yaml:"claimMappings"`
	Issuer        string      `yaml:"issuer"`
}

GitProvider configures a custom OIDC issuer and how its token claims map to the claims StaticPages reads.

type Output

type Output struct {
	Format Format
}

Output configures the CLI's output.

type Page

type Page struct {
	Bucket  BucketConfig  `yaml:"bucket"`
	Git     GitConfig     `yaml:"git"`
	Domain  DomainScope   `yaml:"domain"`
	Proxy   PageProxy     `yaml:"proxy"`
	History int           `yaml:"history"`
	Preview PreviewConfig `yaml:"preview"`
}

Page is one site StaticPages serves: the domain it answers on, the bucket its uploads live in, the backend it proxies to, and the repository allowed to publish it.

type PageProxy

type PageProxy struct {
	URL        EnvValue `yaml:"url"`
	Path       EnvValue `yaml:"path"`
	NotFound   string   `yaml:"notFound"`
	SearchPath []string `yaml:"searchPath"`
}

PageProxy configures where the proxy fetches a page's objects from and how it resolves request paths to them.

type PreviewConfig

type PreviewConfig struct {
	Enabled      bool `yaml:"enabled"`
	CommitSha    bool `yaml:"sha"`
	Environments bool `yaml:"environment"`
	Branch       bool `yaml:"branch"`
}

PreviewConfig selects which preview subdomains a page serves besides its main branch: one per commit, per environment, or per branch.

type Proxy

type Proxy struct {
	MaxIdleConns        int
	MaxIdleConnsPerHost int
	Timeout             time.Duration
	Compression         bool

	// ProbeTimeout bounds each per-path HEAD probe issued while resolving a
	// request to a backend object. A probe that exceeds this deadline is
	// treated as inconclusive (the object may still exist) rather than as a
	// definitive "not found".
	ProbeTimeout time.Duration
}

Proxy configures the reverse proxy's connections to the storage backends.

type Server

type Server struct {
	Host      string
	ProxyPort int
	ApiPort   int
}

Server configures the addresses the proxy and the upload API listen on.

type StaticPagesConfig

type StaticPagesConfig struct {
	Output Output
	Pages  []*Page
	Server Server
	Proxy  Proxy
}

StaticPagesConfig is the whole configuration file: the listeners, the proxy's connection settings, and the pages it serves.

func (*StaticPagesConfig) ApiBindAddr

func (s *StaticPagesConfig) ApiBindAddr() string

ApiBindAddr returns the address the upload API listens on.

func (*StaticPagesConfig) ProxyBindAddr

func (s *StaticPagesConfig) ProxyBindAddr() string

ProxyBindAddr returns the address the reverse proxy listens on.

type SubDomain

type SubDomain struct {
	Pattern string `yaml:"pattern"`
	History int    `yaml:"history"`
}

SubDomain configures a subdomain pattern and how much history it keeps.

Jump to

Keyboard shortcuts

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