metaschema

package
v0.116.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	NameUser     = "user"
	NameGroup    = "group"
	NameOrg      = "organization"
	NameRole     = "role"
	NameProspect = "prospect"
)

Built-in metaschema names. These are the schemas the server validates entity metadata against, and the set the MetaSchema reconcile kind manages.

Variables

View Source
var (
	ErrInvalidID         = errors.New("metaschema id is invalid")
	ErrNotExist          = errors.New("metaschema doesn't exist")
	ErrConflict          = errors.New("metaschema already exist")
	ErrInvalidDetail     = errors.New("invalid metadata detail")
	ErrInvalidMetaSchema = errors.New("metadata schema validation failed")
	ErrInvalidSchema     = errors.New("metaschema schema must be a JSON object")
)
View Source
var Defaults = map[string]string{
	NameUser:     string(defaultUser),
	NameGroup:    string(defaultGroup),
	NameOrg:      string(defaultOrg),
	NameRole:     string(defaultRole),
	NameProspect: string(defaultProspect),
}

Defaults maps each built-in metaschema name to its shipped JSON schema. It is the one source for both the server seeding (MigrateDefaults) and the MetaSchema reconcile kind, so adding a metaschema for a new resource is a single edit here.

Functions

This section is empty.

Types

type Config added in v0.115.0

type Config struct {
	// RefreshInterval is how often each server reloads the metaschema cache from
	// the database, so a change made on one pod reaches the others. A value of 0
	// disables the background refresh; the cache is still primed once at startup.
	RefreshInterval time.Duration `yaml:"refresh_interval" mapstructure:"refresh_interval" default:"1m"`
}

Config holds runtime configuration for the metaschema service.

type MetaSchema

type MetaSchema struct {
	ID        string
	Name      string
	Schema    string
	CreatedAt time.Time
	UpdatedAt time.Time
}

MetaSchema represents metadata schema to be validated for users/ groups/ organisations / roles

type Repository

type Repository interface {
	Create(ctx context.Context, metaschema MetaSchema) (MetaSchema, error)
	Get(ctx context.Context, id string) (MetaSchema, error)
	Update(ctx context.Context, id string, metaschema MetaSchema) (MetaSchema, error)
	List(ctx context.Context) ([]MetaSchema, error)
	Delete(ctx context.Context, id string) (string, error)
	MigrateDefaults(ctx context.Context) error
}

type Service

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

func NewService

func NewService(repository Repository, logger *slog.Logger, refreshInterval time.Duration) *Service

func (*Service) Close added in v0.115.0

func (s *Service) Close() error

Close stops the background refresh job. It is safe to call when none started.

func (*Service) Create

func (s *Service) Create(ctx context.Context, toCreate MetaSchema) (MetaSchema, error)

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, id string) error

func (*Service) Get

func (s *Service) Get(ctx context.Context, idOrName string) (MetaSchema, error)

func (*Service) Init added in v0.115.0

func (s *Service) Init(ctx context.Context) error

Init primes the cache from the database and, when refreshInterval is greater than zero, starts a background job that reloads it on that interval so a change made on one pod reaches the others.

func (*Service) List

func (s *Service) List(ctx context.Context) ([]MetaSchema, error)

func (*Service) MigrateDefault

func (s *Service) MigrateDefault(ctx context.Context) error

func (*Service) Update

func (s *Service) Update(ctx context.Context, id string, toUpdate MetaSchema) (MetaSchema, error)

func (*Service) Validate

func (s *Service) Validate(mdata metadata.Metadata, name string) error

Validate checks the metadata against the json-schema. When the named metaschema is not in the cache it returns nil (no validation).

Jump to

Keyboard shortcuts

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