phasekit

package
v11.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package phasekit hydrates environment variables from Phase before config.MustLoad runs.

Phasekit shells out to the phase CLI instead of linking the Phase SDK, keeping chassis free of additional Go module dependencies. The caller supplies bootstrap configuration directly, usually from PHASE_SERVICE_TOKEN and PHASE_HOST, then phasekit exports secrets as JSON and applies them to the process environment.

Existing environment variables win by default. This lets local .env files, shell exports, and orchestrator-provided secrets override Phase unless the caller explicitly opts in to overwriting them.

If the phase CLI binary is missing, Hydrate falls back to the existing process environment and returns Result.Source SourceEnvFallback.

Index

Constants

View Source
const (
	SourcePhaseCLI    = "phase-cli"
	SourceEnvFallback = "env-fallback"
)

Source values returned in Result.Source.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// ServiceToken is the Phase service token. Required.
	// Typically read from os.Getenv("PHASE_SERVICE_TOKEN") by the caller.
	// Required only when the phase CLI is available.
	ServiceToken string

	// App is the application name in Phase. Required.
	App string

	// Env is the environment name in Phase, for example "Production". Required.
	Env string

	// Path is the exact path within the app/env. Optional.
	// Defaults to "/" (root path only). Ignored when AllPaths is true.
	Path string

	// AllPaths fetches secrets from all paths by passing --path "" to the
	// Phase CLI. Defaults to false.
	AllPaths bool

	// RequiredKeys makes Hydrate fail if any listed key is missing from the
	// Phase response. RequiredKeys are not enforced when the phase CLI is
	// missing and phasekit falls back to the existing process environment.
	RequiredKeys []string

	// OverwriteExisting allows Phase values to replace variables already present
	// in the process environment. Defaults to false.
	OverwriteExisting bool

	// AllowRedacted allows literal "[REDACTED]" values returned by the Phase CLI.
	// Defaults to false because redacted secrets should fail startup.
	AllowRedacted bool

	// BinaryPath is the path to the phase binary. Defaults to exec.LookPath("phase").
	BinaryPath string

	// Host is the Phase API host. Defaults to "https://console.phase.dev".
	Host string

	// Timeout is the maximum duration for the phase CLI subprocess. Defaults to 10s.
	Timeout time.Duration
}

Config holds bootstrap parameters for hydrating env from Phase.

type Result

type Result struct {
	// Set lists keys hydrated into the process environment.
	Set []string

	// Skipped lists keys preserved because OverwriteExisting is false.
	Skipped []string

	// Source identifies the hydration source.
	// It is either SourcePhaseCLI or SourceEnvFallback.
	Source string
}

Result reports the outcome of a successful hydration.

func Hydrate

func Hydrate(ctx context.Context, cfg Config) (Result, error)

Hydrate executes the phase CLI, parses its JSON output, and applies the secrets to the process environment.

func MustHydrate

func MustHydrate(ctx context.Context, cfg Config) Result

MustHydrate calls Hydrate and panics on any error. Matches the ergonomics of config.MustLoad and chassis.RequireMajor.

Directories

Path Synopsis
Package phasetest provides fake phase CLI binaries for testing phasekit integrations without network access.
Package phasetest provides fake phase CLI binaries for testing phasekit integrations without network access.

Jump to

Keyboard shortcuts

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