env

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package env provides a vault implementation that reads secrets from environment variables.

Usage:

v := env.New()
secret, err := v.Get(ctx, "API_KEY")  // reads os.Getenv("API_KEY")

This provider is read-only by default. Writing to environment variables is possible but only affects the current process.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Prefix is an optional prefix to add to all variable names.
	// For example, if Prefix is "MYAPP_", Get("API_KEY") will read "MYAPP_API_KEY".
	Prefix string

	// AllowWrite enables writing to environment variables.
	// Note: This only affects the current process.
	AllowWrite bool
}

Config holds configuration for the environment variable provider.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider implements vault.Vault for environment variables.

func New

func New() *Provider

New creates a new environment variable provider.

func NewWithConfig

func NewWithConfig(config Config) *Provider

NewWithConfig creates a new environment variable provider with configuration.

func (*Provider) Capabilities

func (p *Provider) Capabilities() vault.Capabilities

Capabilities returns the provider capabilities.

func (*Provider) Close

func (p *Provider) Close() error

Close is a no-op for environment variables.

func (*Provider) Delete

func (p *Provider) Delete(ctx context.Context, path string) error

Delete unsets an environment variable.

func (*Provider) Exists

func (p *Provider) Exists(ctx context.Context, path string) (bool, error)

Exists checks if an environment variable is set.

func (*Provider) Get

func (p *Provider) Get(ctx context.Context, path string) (*vault.Secret, error)

Get retrieves an environment variable value.

func (*Provider) List

func (p *Provider) List(ctx context.Context, prefix string) ([]string, error)

List returns all environment variable names matching the prefix.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the provider name.

func (*Provider) Set

func (p *Provider) Set(ctx context.Context, path string, secret *vault.Secret) error

Set sets an environment variable.

Jump to

Keyboard shortcuts

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