envs

package
v0.30.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 5 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrParse = errors.New("failed to parse environment variables")

ErrParse is joined with the backend's error when Parse fails, so a caller can tell a configuration problem from anything else with errors.Is.

View Source
var ErrParseWithPrefix = errors.New("failed to parse environment variables for the given prefix")

ErrParseWithPrefix is joined with the backend's error when ParseWithPrefix fails, so a caller can tell a configuration problem from anything else with errors.Is.

Functions

func AnnouncementFor added in v0.27.0

func AnnouncementFor(edition Edition) string

AnnouncementFor returns the SSH connection banner for the given edition.

func Parse added in v0.13.3

func Parse[T any](backend Backend) (*T, error)

Parse fills a T from the envconfig tags on its fields, reading each key from backend. It returns ErrParse, joined with the cause, when a required key is missing or a value does not decode.

func ParseWithPrefix added in v0.13.0

func ParseWithPrefix[T any](backend Backend, prefix string) (*T, error)

ParseWithPrefix fills a T from the envconfig tags on its fields, reading each key from backend under prefix before falling back to the unprefixed key. It returns ErrParseWithPrefix, joined with the cause, when a required key is missing or a value does not decode.

Types

type Backend

type Backend interface {
	Get(key string) string
	Process(prefix string, spec any) error
}

Backend is where a configuration is parsed from: the process environment (OS) or, in a test, a map (Map).

func Map added in v0.27.0

func Map(values map[string]string) Backend

Map returns a backend that reads values instead of the process environment. Its Process resolves a prefixed key over the unprefixed one exactly as the backend OS returns does.

func OS added in v0.27.0

func OS() Backend

OS returns the backend that reads the process environment. Only an entrypoint should call it, to parse its configuration once and pass the values down.

type Edition added in v0.27.0

type Edition string

Edition is the ShellHub edition an instance runs as. It decides which features the server exposes, so it is read at startup and never per request.

const (
	// Community is the open-source edition, and the edition an instance falls back to when
	// SHELLHUB_EDITION is unset.
	Community Edition = "community"
	// Enterprise is the self-hosted paid edition, gated by a licence file.
	Enterprise Edition = "enterprise"
	// Cloud is the hosted edition, which adds billing and the multi-tenant surface on top of
	// Enterprise.
	Cloud Edition = "cloud"
)

func ParseEdition added in v0.27.0

func ParseEdition(raw string) (Edition, error)

ParseEdition normalizes raw (trim and lowercase) into an Edition. The empty string is Community; anything else outside the three editions is an error.

func (Edition) IsCloud added in v0.27.0

func (e Edition) IsCloud() bool

IsCloud reports whether e is the hosted edition. Billing and namespace limits are the features that turn on here and nowhere else.

func (Edition) IsCommunity added in v0.27.0

func (e Edition) IsCommunity() bool

IsCommunity reports whether e is the community edition. The zero value is community too, so an edition nobody set behaves as an unset SHELLHUB_EDITION does.

func (Edition) IsEnterprise added in v0.27.0

func (e Edition) IsEnterprise() bool

IsEnterprise reports whether e is the enterprise edition, which is not the same question as "may it use a paid feature"; see IsEnterpriseOrCloud.

func (Edition) IsEnterpriseOrCloud added in v0.27.0

func (e Edition) IsEnterpriseOrCloud() bool

IsEnterpriseOrCloud reports whether the paid feature set is available. This is the check a feature gate wants, so that a feature added for cloud stays available to enterprise.

func (*Edition) UnmarshalText added in v0.27.0

func (e *Edition) UnmarshalText(text []byte) error

UnmarshalText parses text with ParseEdition, so a config struct that declares an Edition field rejects a bad SHELLHUB_EDITION when it is parsed.

type OpenAPIValidation added in v0.27.0

type OpenAPIValidation string

OpenAPIValidation is how the server treats a response that does not match its schema.

const (
	// OpenAPIValidationOff checks nothing.
	OpenAPIValidationOff OpenAPIValidation = "off"
	// OpenAPIValidationReport logs a mismatch and answers as the handler did.
	OpenAPIValidationReport OpenAPIValidation = "report"
	// OpenAPIValidationStrict answers a mismatch with a 500 that lists it and refuses to start
	// without a schema.
	OpenAPIValidationStrict OpenAPIValidation = "strict"
)

func OpenAPIValidationMode added in v0.27.0

func OpenAPIValidationMode(raw string, development bool) OpenAPIValidation

OpenAPIValidationMode turns the raw SHELLHUB_OPENAPI_VALIDATION into a mode. on, true, 1 and report log a mismatch, strict fails it, and off, false and 0 disable the check. Anything else reports in development and is off elsewhere.

Jump to

Keyboard shortcuts

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