envconfig

package
v0.19.0 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: 4 Imported by: 0

README

internal/envconfig

Overview

Resolves OPENSTORAGE_* environment settings. It does not read the legacy CODESTORAGE_* names as values [envconfig.go:CheckLegacy]. It reports legacy variables that are set without their replacement, and it strips or sets both spellings in child-process environments.

Interface

  • LookupEnv — injectable wrapper around os.LookupEnv; never logs [envconfig.go:LookupEnv]
  • Getenv — value-only form; returns "" when unset [envconfig.go:Getenv]
  • First — returns the value of the first present name in an alias chain [envconfig.go:First]
  • CheckLegacy — returns an error listing sorted CODESTORAGE_* to OPENSTORAGE_* pairs set without the replacement, without values [envconfig.go:CheckLegacy]
  • Strip — removes both spellings of each canonical name from an env slice [envconfig.go:Strip]
  • Set — replaces both spellings of a name with one canonical name=value entry [envconfig.go:Set]
  • Prefix literals OPENSTORAGE_ and CODESTORAGE_ [envconfig.go:prefix]

Invariants

  • legacyName panics unless the name starts with OPENSTORAGE_ [envconfig.go:legacyName]
  • First stops at the first present name, including an explicitly empty one [envconfig.go:First]
  • CheckLegacy reports only legacy names whose replacement is unset, deduplicated and sorted, and returns nil when there are none [envconfig.go:CheckLegacy]
  • Set removes both spellings before it appends the canonical value [envconfig.go:Set]

Side Effects

  • Reads the process environment through os.LookupEnv and os.Environ [envconfig.go:CheckLegacy]
  • CheckLegacy must not run in hook subprocesses, because git relays hook stderr to the pushing client [envconfig.go:CheckLegacy]
  • Strip mutates the caller's slice in place; Set appends to it [envconfig.go:Strip]

Verification

  • Run: go test ./internal/envconfig/... -tags=openstorage_viewcheck -count=1 -race -timeout=30m

Documentation

Overview

Package envconfig resolves OPENSTORAGE_* settings. Presence, not a nonempty value, selects a name. The old CODESTORAGE_* names are not read: CheckLegacy refuses a process that still sets one without its replacement.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckLegacy added in v0.17.0

func CheckLegacy() error

CheckLegacy fails when a CODESTORAGE_* variable is set and its OPENSTORAGE_* replacement is unset. The error names every such pair, sorted, and never includes a value. A legacy name next to its set replacement is ignored, so a fleet that still runs pre-0.15 binaries can keep both names. Do not call this in hook subprocesses: git relays hook stderr to the pushing client.

func First

func First(names ...string) string

First returns the value of the first PRESENT name in an alias chain. An explicitly empty earlier name ends the scan instead of exposing a later alias.

func Getenv

func Getenv(name string) string

Getenv is the value-only form of LookupEnv, suitable for injected config readers.

func LookupEnv

func LookupEnv(name string) (string, bool)

LookupEnv is os.LookupEnv, kept as the injectable reader for settings. Lookups never log: hooks and lazy runtime settings read it on every call.

func Set

func Set(env []string, name, value string) []string

Set replaces both spellings with one trusted canonical value. Children read only OPENSTORAGE_* names: every hook script runs this binary (EnsureCacheRepo rewrites managed hooks before each request), and 0.15.x and 0.16.x hook binaries also read the canonical name first.

func Strip

func Strip(env []string, names ...string) []string

Strip removes both spellings of each canonical name from a child environment, so no inherited value under either prefix reaches the child. It reuses env's backing array; callers must own that slice.

Types

This section is empty.

Jump to

Keyboard shortcuts

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