core

package
v0.2.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuditActionCreated = "created"
	AuditActionUpdated = "updated"
	AuditActionDeleted = "deleted"
)

Audit actions.

View Source
const (
	ContextTypeString    = evalcore.ContextTypeString
	ContextTypeInt       = evalcore.ContextTypeInt
	ContextTypeDouble    = evalcore.ContextTypeDouble
	ContextTypeBool      = evalcore.ContextTypeBool
	ContextTypeTimestamp = evalcore.ContextTypeTimestamp
	ContextTypeList      = evalcore.ContextTypeList
	ContextTypeMap       = evalcore.ContextTypeMap
)
View Source
const (
	ValueTypeBoolean = evalcore.ValueTypeBoolean
	ValueTypeString  = evalcore.ValueTypeString
	ValueTypeNumber  = evalcore.ValueTypeNumber
	ValueTypeJSON    = evalcore.ValueTypeJSON
)
View Source
const (
	ValidationIssueParseError        = "parse_error"
	ValidationIssueUnknownField      = "unknown_field"
	ValidationIssueNonBoolExpression = "non_bool_expression"
	ValidationIssueInvalidRollout    = "invalid_rollout"
	ValidationIssueMissingBucket     = "missing_bucket_field"
	ValidationIssueInvalidValueType  = "invalid_value_type"
	ValidationIssueInvalidValue      = "invalid_value"
)
View Source
const DefaultEnvironmentKey = "production"
View Source
const ResourceTypeFlag = "flag"

Audit resource types. Only flags are recorded for now, but the audit_logs table is generic so other resources can be added without a migration.

Variables

View Source
var (
	ErrAuthNotConfigured  = errors.New("auth is not configured")
	ErrInvalidCredentials = errors.New("invalid credentials")
	ErrUserNotAllowed     = errors.New("user is not allowed")
	ErrSessionNotFound    = errors.New("session not found")
	ErrAPIKeyNotFound     = errors.New("api key not found")
)
View Source
var (
	ErrFlagNotFound        = errors.New("flag not found")
	ErrRuleNotFound        = errors.New("rule not found")
	ErrEnvironmentNotFound = errors.New("environment not found")
	ErrEnvironmentKeyTaken = errors.New("environment key already in use")
	ErrEnvironmentInUse    = errors.New("environment is in use")
	ErrDefaultEnvironment  = errors.New("default environment cannot be deleted")
	ErrContextNotFound     = errors.New("context not found")
	ErrContextNameTaken    = errors.New("context name already in use")
	ErrContextHasReferers  = errors.New("context referenced by flags")
)

Functions

func WithActor

func WithActor(ctx context.Context, actor *Actor) context.Context

WithActor returns a copy of ctx carrying the given actor.

Types

type APIKey

type APIKey struct {
	ID            string
	Name          string
	Description   string
	Prefix        string
	EnvironmentID string
	CreatedAt     time.Time
	UpdatedAt     time.Time
	LastUsedAt    *time.Time
	RevokedAt     *time.Time
	CreatedBy     *string
	DeletedBy     *string
}

type Actor

type Actor struct {
	ID    string
	Label string
}

Actor identifies who performed a mutation. It is carried on the request context by the admin auth middleware and read by the store when writing audit metadata. When auth is disabled the actor is nil.

func ActorFromContext

func ActorFromContext(ctx context.Context) *Actor

ActorFromContext returns the actor carried on ctx, or nil if none is set.

type AuditEntry

type AuditEntry struct {
	ID            string
	EnvironmentID string
	ResourceType  string
	ResourceID    string
	Action        string
	Version       int
	Snapshot      *FlagConfig
	ActorID       *string
	ActorLabel    *string
	CreatedAt     time.Time
}

AuditEntry is a single version in a resource's change history. Each entry stores the full snapshot of the resource as it existed after the change (nil for a delete), so consecutive entries can be diffed to show exactly what changed.

type ContextField

type ContextField = evalcore.ContextField

type ContextFieldReference

type ContextFieldReference struct {
	Path      string
	RuleCount int
}

type ContextReference

type ContextReference struct {
	ContextID        string
	EnvironmentID    string
	EnvironmentKey   string
	FlagKey          string
	RuleCount        int
	ReferencedFields []ContextFieldReference
	Flag             FlagConfig
}

type ContextSchema

type ContextSchema = evalcore.ContextSchema

type ContextSchemaConflictError

type ContextSchemaConflictError struct {
	Issues []ValidationIssue
}

func (*ContextSchemaConflictError) Error

type ContextType

type ContextType = evalcore.ContextType

type Environment

type Environment struct {
	ID          string
	Key         string
	Name        string
	Description string
	CreatedAt   time.Time
	UpdatedAt   time.Time
	CreatedBy   *string
	DeletedBy   *string
}

type EvalContext

type EvalContext = evalcore.EvalContext

type FlagConfig

type FlagConfig = evalcore.FlagConfig

type FlagUsageBucket

type FlagUsageBucket struct {
	EnvironmentID string
	FlagKey       string
	BucketStart   time.Time
	ValueType     ValueType
	Value         any
	Reason        string
	MatchedRuleID *string
	APIKeyID      *string
	APIKeyName    string
	Source        string
	Count         int64
}

type FlagUsageEvent

type FlagUsageEvent struct {
	ID            string
	EnvironmentID string
	FlagKey       string
	ValueType     ValueType
	Value         any
	Reason        string
	MatchedRuleID *string
	APIKeyID      *string
	Source        string
	Latency       time.Duration
	ObservedAt    time.Time
	Context       map[string]any
}

type FlagUsageLatencyBucket

type FlagUsageLatencyBucket struct {
	EnvironmentID string
	FlagKey       string
	Source        string
	BucketStart   time.Time
	Count         int64
	AvgLatency    time.Duration
	P95Latency    time.Duration
}

type FlagUsageQuery

type FlagUsageQuery struct {
	EnvironmentID string
	FlagKey       string
	Since         time.Time
	Limit         int32
}

type FlagUsageRecorder

type FlagUsageRecorder interface {
	RecordFlagUsage(ctx context.Context, event FlagUsageEvent) error
}

type FlagUsageSource

type FlagUsageSource struct {
	APIKeyID string
	Source   string
}

type FlagValue

type FlagValue = evalcore.FlagValue

type Rollout

type Rollout = evalcore.Rollout

type Rule

type Rule = evalcore.Rule

type Store

type Store interface {
	ListEnvironments(ctx context.Context) ([]*Environment, error)
	GetEnvironment(ctx context.Context, id string) (*Environment, error)
	GetEnvironmentByKey(ctx context.Context, key string) (*Environment, error)
	CreateEnvironment(ctx context.Context, env *Environment) error
	UpdateEnvironment(ctx context.Context, env *Environment) error
	DeleteEnvironment(ctx context.Context, id string) error

	GetFlag(ctx context.Context, environmentID, key string) (*FlagConfig, error)
	ListFlags(ctx context.Context, environmentID string) ([]*FlagConfig, error)
	SaveFlag(ctx context.Context, environmentID string, flag *FlagConfig) error
	DeleteFlag(ctx context.Context, environmentID, key string) error
	ListFlagAuditLog(ctx context.Context, environmentID, flagKey string) ([]*AuditEntry, error)

	GetRule(ctx context.Context, environmentID, flagKey, ruleID string) (*Rule, error)
	CreateRule(ctx context.Context, environmentID, flagKey string, rule Rule) error
	UpdateRule(ctx context.Context, environmentID, flagKey string, rule Rule) error
	DeleteRule(ctx context.Context, environmentID, flagKey, ruleID string) error
	ReorderRules(ctx context.Context, environmentID, flagKey string, ruleIDs []string) error

	ListContexts(ctx context.Context) ([]*ContextSchema, error)
	GetContext(ctx context.Context, id string) (*ContextSchema, error)
	CreateContext(ctx context.Context, c *ContextSchema) error
	UpdateContext(ctx context.Context, c *ContextSchema) error
	DeleteContext(ctx context.Context, id string) error
}

type User

type User struct {
	ID          string
	OIDCSubject string
	Email       string
	Name        string
	Description string
	Admin       bool
	CreatedAt   time.Time
	UpdatedAt   time.Time
	CreatedBy   *string
	DeletedBy   *string
}

type ValidationError

type ValidationError struct {
	Message string            `json:"message"`
	Issues  []ValidationIssue `json:"issues"`
}

func (*ValidationError) Error

func (e *ValidationError) Error() string

type ValidationIssue

type ValidationIssue struct {
	Code    string `json:"code"`
	Field   string `json:"field"`
	Path    string `json:"path,omitempty"`
	Message string `json:"message"`
}

type ValueType

type ValueType = evalcore.ValueType

Jump to

Keyboard shortcuts

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