apptype

package
v0.8.8 Latest Latest
Warning

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

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

Documentation

Overview

Package apptype models a governed app type (ADR 052): a constraint and defaults layer over the app spec that an admin publishes and apps pin.

Index

Constants

View Source
const (
	EnvEnabled        = "LEVELRAIL_APPTYPE_ENABLED"
	EnvMaxParams      = "LEVELRAIL_APPTYPE_MAX_PARAMS"
	EnvMaxSchemaBytes = "LEVELRAIL_APPTYPE_MAX_SCHEMA_BYTES"
	EnvMaxPatternLen  = "LEVELRAIL_APPTYPE_MAX_PATTERN_LEN"
	EnvMaxVersions    = "LEVELRAIL_APPTYPE_MAX_VERSIONS"
)

Env names for the feature flag and its limits.

View Source
const (
	CodeWorkloadMismatch   = "apptype_workload_mismatch"
	CodeParamInvalid       = "apptype_param_invalid"
	CodeBuildNotAllowed    = "apptype_build_not_allowed"
	CodeAddonNotAllowed    = "apptype_addon_not_allowed"
	CodeFixedValueChanged  = "apptype_fixed_value_changed"
	CodeFixedValueMissing  = "apptype_fixed_value_missing"
	CodeReplicasOutOfRange = "apptype_replicas_out_of_range"
	CodeReadinessRequired  = "apptype_readiness_required"
)

Violation codes. They share the policy.Violation shape so every surface that renders deploy policy violations renders these too.

Variables

This section is empty.

Functions

func Check

func Check(t AppType, spec Spec) []policy.Violation

Check evaluates one app spec against one published type version. It returns every violation, never stops at the first.

func Enabled

func Enabled() bool

Enabled reports whether the feature flag is on; it is read per call so a restart is the only switch an operator needs.

Types

type Addons

type Addons struct {
	Databases *DatabaseRule `json:"databases,omitempty"`
	Volumes   *Toggle       `json:"volumes,omitempty"`
	Domains   *DomainRule   `json:"domains,omitempty"`
	Cron      *Toggle       `json:"cron,omitempty"`
}

Addons limits optional extras; a nil rule means unrestricted.

type AppType

type AppType struct {
	Name              string             `json:"name"`
	Version           int                `json:"version,omitempty"`
	Title             string             `json:"title,omitempty"`
	Description       string             `json:"description,omitempty"`
	Workload          string             `json:"workload"`
	Enforcement       policy.Mode        `json:"enforcement,omitempty"`
	Parameters        json.RawMessage    `json:"parameters,omitempty"`
	Binds             map[string]string  `json:"binds,omitempty"`
	EnvironmentConfig map[string]EnvRule `json:"environmentConfig,omitempty"`
	Build             BuildRule          `json:"build,omitempty"`
	Addons            Addons             `json:"addons,omitempty"`
	Fixed             map[string]string  `json:"fixed,omitempty"`
	Defaults          map[string]string  `json:"defaults,omitempty"`
	Messages          map[string]string  `json:"messages,omitempty"`
}

AppType is the published document.

func ParseDocument

func ParseDocument(raw []byte, lim Limits) (AppType, error)

ParseDocument decodes and validates a type document. Unknown fields are refused so a typo in a rule cannot silently weaken a type.

func (AppType) Validate

func (t AppType) Validate(lim Limits) error

Validate checks the document's own consistency.

type BuildRule

type BuildRule struct {
	Allowed []string `json:"allowed,omitempty"`
}

BuildRule limits build methods; empty means any.

type DatabaseRule

type DatabaseRule struct {
	AllowedEngines []string `json:"allowed_engines,omitempty"`
	Max            int      `json:"max,omitempty"`
}

DatabaseRule limits database engines and count.

type DomainRule

type DomainRule struct {
	Allowed  bool     `json:"allowed"`
	Suffixes []string `json:"suffixes,omitempty"`
}

DomainRule limits custom domains.

type EnvRule

type EnvRule struct {
	ReplicasMin       *int `json:"replicasMin,omitempty"`
	ReplicasMax       *int `json:"replicasMax,omitempty"`
	ReadinessRequired bool `json:"readinessRequired,omitempty"`
}

EnvRule tightens a type for one environment kind.

type Limits

type Limits struct {
	MaxParams      int
	MaxSchemaBytes int
	MaxPatternLen  int
	MaxVersions    int
}

Limits caps what a type document may carry.

func LimitsFromEnv

func LimitsFromEnv() Limits

LimitsFromEnv reads the caps, falling back to the ADR defaults.

type Schema

type Schema struct {
	Type        string
	Enum        []any
	Minimum     *float64
	Maximum     *float64
	MinLength   *int
	MaxLength   *int
	Pattern     string
	Format      string
	Default     any
	Description string
	Required    []string
	Properties  map[string]*Schema
	// contains filtered or unexported fields
}

Schema is the constrained JSON Schema subset a type uses for parameters. Composition, references and remote ids are left out so a form and a one-line error per field stay predictable.

func ParseSchema

func ParseSchema(raw json.RawMessage, lim Limits) (*Schema, error)

ParseSchema checks raw against the subset and the env-driven limits.

func (*Schema) ParamPaths

func (s *Schema) ParamPaths() []string

ParamPaths lists the dotted path of every scalar parameter, sorted.

func (*Schema) Validate

func (s *Schema) Validate(path string, v any) []string

Validate returns one readable message per problem with v at path.

type Spec

type Spec struct {
	Workload  string            `json:"workload,omitempty"`
	EnvKind   string            `json:"env_kind,omitempty"`
	Params    map[string]any    `json:"params,omitempty"`
	Build     string            `json:"build,omitempty"`
	Replicas  *int              `json:"replicas,omitempty"`
	Readiness bool              `json:"readiness,omitempty"`
	Databases []string          `json:"databases,omitempty"`
	Volumes   int               `json:"volumes,omitempty"`
	Domains   []string          `json:"domains,omitempty"`
	Cron      string            `json:"cron,omitempty"`
	Values    map[string]string `json:"values,omitempty"`
}

Spec is the slice of an app the checks look at. Values holds flat dotted spec paths (for example labels.team) for fixed-value rules.

type Toggle

type Toggle struct {
	Allowed bool `json:"allowed"`
}

Toggle allows or forbids an add-on.

Jump to

Keyboard shortcuts

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