seed

package
v0.234.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package seed loads a YAML or JSON seed file into the mock's in-memory stores: expectations, claims, claim mappings, permissions and the MFA flag.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	Expectations  []Item              `json:"expectations,omitempty"`
	Claims        map[string]any      `json:"claims,omitempty"`
	ClaimMappings map[string]string   `json:"claim_mappings,omitempty"`
	Permissions   map[string][]string `json:"permissions,omitempty"`
	MFARequired   bool                `json:"mfa_required,omitempty"`
}

File is the on-disk shape of a seed file, shared with the export.

func Export

func Export(st Stores, detail bool) File

Export dumps the current state of st in seed file shape. Bodies are normalised (sorted keys, exact numbers) so the output is stable. When detail is true each expectation also carries its id and hit count.

func (File) JSON

func (f File) JSON() ([]byte, error)

JSON renders f as indented JSON ending in a newline.

func (File) YAML

func (f File) YAML() ([]byte, error)

YAML renders f as YAML with alphabetical keys and exact numbers.

type Item

type Item struct {
	ID string `json:"id,omitempty"`
	matches.Registration
	Hits *int64 `json:"hits,omitempty"`
}

Item is one expectation entry. ID and Hits appear in exports; they are accepted on load and ignored.

type Manager

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

Manager owns the seed file: it applies it at startup, re-applies it on reset and reloads it when its content changes.

func NewManager

func NewManager(path string, v *spec.Validator, st Stores, log zerolog.Logger) (*Manager, error)

NewManager reads and parses the seed file at path and applies it to st.

func (*Manager) Bind

func (m *Manager) Bind(wipe func(context.Context))

Bind sets the function that clears every store. It must be called before Reset, Poll or Watch.

func (*Manager) Export

func (m *Manager) Export(detail bool) File

Export snapshots the stores in seed file shape while holding the lock Reset and Poll hold, so it never sees a half-applied reload.

func (*Manager) Poll

func (m *Manager) Poll(ctx context.Context)

Poll checks the seed file once and reloads it if its content changed.

func (*Manager) Reset

func (m *Manager) Reset(ctx context.Context, keepSeed bool)

Reset clears every store and, if keepSeed, re-applies the current seed.

func (*Manager) Watch

func (m *Manager) Watch(ctx context.Context, interval time.Duration)

Watch polls the seed file every interval until ctx is done. Start it only after Bind.

type Seed

type Seed struct {
	Expectations  []matches.Expectation
	Claims        map[string]any
	ClaimMappings map[string]string
	Permissions   map[string][]string
	MFARequired   bool
}

Seed is a parsed, validated seed file.

func Parse

func Parse(data []byte, v *spec.Validator) (*Seed, error)

Parse reads YAML (or JSON, which is a subset) and validates every expectation against the Management API spec.

func (*Seed) Apply

func (s *Seed) Apply(st Stores)

Apply writes the seed into the stores. Expectations are Put in file order.

func (*Seed) Summary

func (s *Seed) Summary() string

Summary is a one-line description for logs.

type Stores

type Stores struct {
	Matches       *matches.Store
	Claims        *claims.Store
	ClaimMappings *claims.MappingStore
	Permissions   *permissions.Store
	MFA           *mfa.Store
}

Stores are the stores a seed is applied to.

Jump to

Keyboard shortcuts

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