config

package
v1.29.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SearchPaths = []string{
	"{CWD}/.go-idp/inlets.yaml",
	"{CWD}/.inlets.yaml",
	"{HOME}/.go-idp/inlets/config.yaml",
	"{HOME}/.config/inlets.yaml",
	"{HOME}/.config/inlets.yml",
	"/etc/go-idp/inlets/config.yaml",
	"/etc/inlets/config.yaml",
}

SearchPaths defines default config file locations (priority order).

Functions

func BuildBandwidthLimits

func BuildBandwidthLimits(cfg *FileConfig) *limiter.ClientBandwidthLimits

func CreateGetToken

func CreateGetToken(ref *Ref, serverVersion string) types.GetToken

CreateGetToken returns a GetToken function backed by ref.

func Dir

func Dir(configPath string) string

Dir returns the directory containing the config file.

func FindFile

func FindFile() string

FindFile returns the first existing config path from SearchPaths.

func IsDurationField

func IsDurationField(path string) bool

IsDurationField returns true if the leaf at `path` is expected to be a duration string. Used by the admin UI to format input correctly.

func LoadRaw

func LoadRaw(path string) ([]byte, error)

LoadRaw returns the raw YAML bytes.

func ReadPIDFile

func ReadPIDFile(path string) (int, error)

ReadPIDFile returns the pid stored in path.

func RemovePIDFile

func RemovePIDFile(path string)

RemovePIDFile deletes the pid file if present.

func ResolvePublicHTTPNoAuthTiming

func ResolvePublicHTTPNoAuthTiming(cfg *FileConfig) (time.Duration, time.Duration)

func SaveAtomic

func SaveAtomic(path string, cfg *FileConfig) error

SaveAtomic writes cfg to path using a temp file and rename.

func SaveRawAtomic

func SaveRawAtomic(path string, raw []byte) error

SaveRawAtomic writes raw YAML to path.

func SignalReload

func SignalReload(pidFile string) error

SignalReload sends SIGHUP to the process in pidFile.

func Validate

func Validate(cfg *FileConfig) error

Validate returns a single error (errors.Join) or nil. Kept for callers that only need a yes/no answer.

func WritePIDFile

func WritePIDFile(path string) error

WritePIDFile writes the current process id to path.

Types

type AdminConfig

type AdminConfig struct {
	Enabled  bool          `yaml:"enabled"`
	Listen   string        `yaml:"listen"`
	Database AdminDatabase `yaml:"database"`
	Runtime  AdminRuntime  `yaml:"runtime"`
	UI       AdminUI       `yaml:"ui"`
}

AdminConfig controls the optional admin console HTTP server.

type AdminDatabase

type AdminDatabase struct {
	Path string `yaml:"path"`
}

type AdminRuntime

type AdminRuntime struct {
	PidFile          string `yaml:"pidFile"`
	SnapshotInterval string `yaml:"snapshotInterval"`
}

type AdminUI

type AdminUI struct {
	BasePath string `yaml:"basePath"`
}

type ApplyOptions

type ApplyOptions struct {
	GetToken                     types.GetToken
	Notification                 *client.NotificationConfig
	BandwidthLimits              *limiter.ClientBandwidthLimits
	PublicHTTPNoAuthSessionTTL   time.Duration
	PublicHTTPNoAuthWarnLeadTime time.Duration
}

ApplyOptions carries runtime fields derived from FileConfig.

func BuildApplyOptions

func BuildApplyOptions(cfg *FileConfig, serverVersion string, getToken types.GetToken) ApplyOptions

BuildApplyOptions constructs ApplyOptions from a config document.

type BandwidthLimitsConfig

type BandwidthLimitsConfig struct {
	Global  *limiter.BandwidthLimit            `yaml:"global"`
	Clients map[string]*limiter.BandwidthLimit `yaml:"clients"`
}

type ClientConfig

type ClientConfig struct {
	ClientID       string                  `yaml:"clientId"`
	ClientSecret   string                  `yaml:"clientSecret"`
	Config         *client.Config          `yaml:"config"`
	BandwidthLimit *limiter.BandwidthLimit `yaml:"bandwidthLimit"`
	Tunnels        []client.TunnelSpec     `yaml:"tunnels,omitempty"`
}

type FileConfig

type FileConfig struct {
	Domain           string                     `yaml:"domain"`
	Port             int                        `yaml:"port"`
	TCPPort          int                        `yaml:"tcpPort"`
	Secure           *bool                      `yaml:"secure"`
	Token            string                     `yaml:"token"`
	Clients          []ClientConfig             `yaml:"clients"`
	Notification     *client.NotificationConfig `yaml:"notification"`
	BandwidthLimits  *BandwidthLimitsConfig     `yaml:"bandwidthLimits"`
	PublicHTTPNoAuth *PublicHTTPNoAuthConfig    `yaml:"publicHTTPNoAuth,omitempty"`
	Admin            *AdminConfig               `yaml:"admin,omitempty"`
}

FileConfig is the on-disk inlets server YAML document.

func Load

func Load(path string) (*FileConfig, error)

Load reads and parses a YAML config file.

type Manager

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

Manager coordinates config file reload.

func NewManager

func NewManager(path string, ref *Ref, apply ReloadFunc) *Manager

func (*Manager) EffectiveConfig

func (m *Manager) EffectiveConfig() *FileConfig

EffectiveConfig returns the current config with all active overrides applied. Callers that need to observe user-driven temporary changes (the admin UI's "override" tab, for instance) should call this instead of ref.Get() directly.

func (*Manager) Override

func (m *Manager) Override() *Override

Override returns the override singleton for this manager. Overrides are layered on top of the on-disk config at read time and are process-local; they are not persisted and vanish on restart.

func (*Manager) Path

func (m *Manager) Path() string

func (*Manager) Ref

func (m *Manager) Ref() *Ref

func (*Manager) Reload

func (m *Manager) Reload() error

Reload reads the config file, validates, updates ref, and applies.

type Override

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

Override is an in-memory set of patches layered over a *FileConfig. Patches are stored as JSON-pointer-like paths (e.g. "clients[0].clientSecret") and applied on top of an immutable base at read time.

Design notes (see AGENTS.md 2024-12-19 concurrency lesson):

  • Apply() does NOT mutate its argument. It deep-copies via JSON round-trip and writes the patches into the copy.
  • Reads take a brief RLock, copy, return.
  • Writes take a Lock.
  • Patch paths that resolve to a missing field fail-fast at Set time.

func NewOverride

func NewOverride() *Override

NewOverride creates an empty Override.

func (*Override) Apply

func (o *Override) Apply(base *FileConfig) *FileConfig

Apply returns a deep copy of `base` with all patches applied. The argument is never mutated.

func (*Override) ClearAll

func (o *Override) ClearAll()

ClearAll removes every patch.

func (*Override) Delete

func (o *Override) Delete(path string)

Delete removes a patch.

func (*Override) Get

func (o *Override) Get(path string) (json.RawMessage, bool)

Get returns the raw JSON value of a patch.

func (*Override) List

func (o *Override) List() []OverrideEntry

List returns a copy of the current patches.

func (*Override) Set

func (o *Override) Set(path string, value any) error

Set registers a patch. The path must resolve to a settable leaf in FileConfig; otherwise an error is returned. Values are stored as their JSON representation so re-marshaling is stable.

func (*Override) Size

func (o *Override) Size() int

Size returns the number of active patches.

type OverrideEntry

type OverrideEntry struct {
	Path  string          `json:"path"`
	Value json.RawMessage `json:"value"`
}

OverrideEntry is the JSON-friendly view of a single patch.

type PublicHTTPNoAuthConfig

type PublicHTTPNoAuthConfig struct {
	Timeout  string `yaml:"timeout,omitempty"`
	WarnLead string `yaml:"warnLead,omitempty"`
}

type Ref

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

Ref holds the live server config document for hot reload.

func NewRef

func NewRef(initial *FileConfig) *Ref

func (*Ref) Get

func (r *Ref) Get() *FileConfig

func (*Ref) Set

func (r *Ref) Set(cfg *FileConfig)

type ReloadFunc

type ReloadFunc func(cfg *FileConfig) error

ReloadFunc applies a freshly loaded config to the running server.

type ResolvedAdmin

type ResolvedAdmin struct {
	Enabled          bool
	Host             string
	Port             int
	DatabasePath     string
	PidFile          string
	SnapshotInterval time.Duration
	UIBasePath       string
}

ResolvedAdmin holds parsed admin settings with defaults applied.

func ResolveAdmin

func ResolveAdmin(cfg *FileConfig, configPath string) (*ResolvedAdmin, error)

ResolveAdmin applies defaults for admin settings.

type ValidationError

type ValidationError struct {
	Path    string `json:"path"`
	Message string `json:"message"`
}

ValidationError describes a single configuration problem with a machine-addressable path (dotted/indexed, e.g. "clients[2].clientSecret").

func ValidateWithDetails

func ValidateWithDetails(cfg *FileConfig) []ValidationError

validateWithDetails runs the same checks as Validate but returns a structured list of errors keyed by JSON-pointer-like paths. The function is pure (does not load files) and is safe to call from request handlers.

func (ValidationError) Error

func (e ValidationError) Error() string

Jump to

Keyboard shortcuts

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