customcfg

package
v3.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package customcfg holds hand-written (NOT generated) configuration that the generated config.Config struct can't carry — named profiles, each with a server URL and (keychain-stored) secret — plus one-time migration from the legacy TS CLI. It lives in its own package and a separate file (~/.config/growthbook/cli.yaml) so it survives regeneration; the generated config layer is never edited.

Profile resolution sits in front of the generated credential chain (flag > env > keychain > config): the active profile injects its server URL into the --server-url flag and its secret into GBCLI_BEARER_AUTH, but only when the user hasn't supplied those explicitly — so explicit flags/env always win and the rest of the chain still applies when no profile is active.

Update / compatibility advisory (hand-written, NOT generated). Lives in the custom layer so it survives regeneration.

Principle (see the migration plan §F): the nudge must be *correct* — never push a user toward a CLI that targets endpoints their backend lacks. The orderable compatibility signal is the build DATE: nudge to a newer CLI only if the connected backend's build date is >= that CLI's generated-against date. semver is compared first (is a newer CLI even out?), then date. If either date is empty (dev builds), we degrade to semver and lean permissive.

Guardrails: advisory-only (never auto-updates), at most once/day, stderr only (so JSON on stdout stays clean), auto-off in CI / non-TTY, and opt-out via --no-update-check or GBCLI_NO_UPDATE_CHECK.

Index

Constants

This section is empty.

Variables

View Source
var (
	Version  = "dev"
	Commit   = ""
	SpecDate = ""
)

Build metadata, injected via -ldflags at release (see .goreleaser.yaml). Empty in local/dev builds.

  • Version: the CLI's own semver, e.g. "1.0.0"
  • Commit: short git SHA of the CLI build (human-readable messages only)
  • SpecDate: the generated-against date — the commit date (YYYY-MM-DD) of the backend spec.yaml the CLI was generated from. The orderable compat signal.

Functions

func BearerFromProfile

func BearerFromProfile() bool

BearerFromProfile reports whether the active profile supplied the bearer credential during startup.

func DeleteProfileSecret

func DeleteProfileSecret(name string) error

func GetProfileSecret

func GetProfileSecret(name string) string

GetProfileSecret / SetProfileSecret / DeleteProfileSecret manage per-profile secrets in the OS keychain.

func MaybeCheckForUpdate

func MaybeCheckForUpdate(cmd *cobra.Command)

MaybeCheckForUpdate is the guarded entry point, called from OnStartup. It never blocks meaningfully (bounded network timeout, at most once/day) and never returns an error — an advisory must not break the user's command.

func OnStartup

func OnStartup(cmd *cobra.Command) error

OnStartup runs custom startup logic from the root PersistentPreRunE (added via persistentEdits): one-time legacy migration, then active-profile resolution.

func Path

func Path() string

Path returns the on-disk location of the custom config (cli.yaml), where profiles are stored. Exported for `whoami` to surface alongside config.yaml.

func SetProfileSecret

func SetProfileSecret(name, secret string) error

func Versioned404Hint

func Versioned404Hint(requestPath string) string

Versioned404Hint returns an actionable message for a 404 on a versioned endpoint — defense-in-depth pointing at the legacy group / a server upgrade. (Wiring it into the SDK error path is release infra; exposed for that use.)

Types

type File

type File struct {
	Current            string             `yaml:"current,omitempty"`
	Profiles           map[string]Profile `yaml:"profiles,omitempty"`
	MigratedFromLegacy bool               `yaml:"migrated_from_legacy,omitempty"`
}

File is the on-disk custom config, kept beside the generated config.yaml.

func Load

func Load() (*File, error)

Load reads the custom config; a missing file yields an empty File (not an error).

func (*File) Names

func (f *File) Names() []string

Names returns the profile names, sorted.

func (*File) Save

func (f *File) Save() error

Save writes the custom config (0600, dir 0700).

type Profile

type Profile struct {
	ServerURL string `yaml:"server_url,omitempty"`
}

Profile is one named environment. The secret is stored in the OS keychain (key profileSecretKey(name)), not on disk.

Jump to

Keyboard shortcuts

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