envs

package
v0.27.0-rc.12 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 6 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

func AnnouncementFor(edition Edition) string

AnnouncementFor returns the SSH connection banner for the given edition.

func IsCloud

func IsCloud() bool

IsCloud reports whether this instance runs the hosted edition. Billing and namespace limits are the features that turn on here and nowhere else.

func IsCommunity added in v0.12.5

func IsCommunity() bool

IsCommunity reports whether this instance runs the community edition. It panics on an unrecognized SHELLHUB_EDITION, as CurrentEdition does.

func IsDevelopment added in v0.14.0

func IsDevelopment() bool

IsDevelopment reports whether SHELLHUB_ENV is "development". It gates developer conveniences only; never use it to relax a security decision, as the variable is attacker-controlled in any deployment that passes the environment through.

func IsEnterprise

func IsEnterprise() bool

IsEnterprise reports whether this instance runs the enterprise edition, which is not the same question as "may it use a paid feature" — see IsEnterpriseOrCloud.

func IsEnterpriseOrCloud

func 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 OpenAPISchemaURL

func OpenAPISchemaURL() string

OpenAPISchemaURL is where the response validator loads the schema from. SHELLHUB_OPENAPI_SCHEMA overrides the address the openapi service serves it at, so a deployment without that service can point the validator at a file it already carries.

func Parse added in v0.13.3

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

Parse parses the environment variables.

This function uses the envconfig package as its default backend, so it requires the struct to be annotated with the envconfig tags. Check the envconfig documentation for more information.

The T generic parameter must be a struct with the fields annotated with the envconfig tags, that will be returned with the values parsed from the environment variables.

func ParseWithPrefix added in v0.13.0

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

ParseWithPrefix parses the environment variables for the a given prefix.

This function uses the envconfig package as its default backend, so it requires the struct to be annotated with the envconfig tags. Check the envconfig documentation for more information.

The T generic parameter must be a struct with the fields annotated with the envconfig tags, that will be returned with the values parsed from the environment variables.

Types

type Backend

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

Backend is an interface for any sort of underlying key/value store.

var DefaultBackend Backend

DefaultBackend define the backend to be used to get environment variables.

type Edition

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 CurrentEdition

func CurrentEdition() Edition

CurrentEdition returns the resolved edition, panicking on an unrecognized value so a misconfigured instance fails rather than silently running as community. Entrypoints should call ResolveEdition at startup to surface the error cleanly; this panic is a last-resort invariant for the predicates below.

func ResolveEdition

func ResolveEdition() (Edition, error)

ResolveEdition reads SHELLHUB_EDITION, normalizes it (trim + lowercase) and defaults to Community when empty. It returns an error for any unrecognized value so entrypoints can validate the edition once at startup and fail fast with a clean message instead of relying on CurrentEdition's lazy panic.

type OpenAPIValidation

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

func OpenAPIValidationMode() OpenAPIValidation

OpenAPIValidationMode reads SHELLHUB_OPENAPI_VALIDATION. on, true, 1 and report log a mismatch, strict fails it, and off, false and 0 disable the check. Unset, it reports in development and is off elsewhere.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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