registry

package
v0.0.0-...-f0aaebc Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: GPL-3.0 Imports: 13 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ValidRegistryName = validSubkey
	ValidViewName     = validSubkey
)

Functions

This section is empty.

Types

type BadRequestError

type BadRequestError struct {
	Account      string
	RegistryName string
	View         string
	Operation    string
	Request      string
	Cause        string
}

func (*BadRequestError) Error

func (e *BadRequestError) Error() string

func (*BadRequestError) Is

func (e *BadRequestError) Is(err error) bool

type DataBag

type DataBag interface {
	Get(path string) (interface{}, error)
	Set(path string, value interface{}) error
	Unset(path string) error
	Data() ([]byte, error)
}

DataBag controls access to the registry data storage.

type JSONDataBag

type JSONDataBag map[string]json.RawMessage

JSONDataBag is a simple DataBag implementation that keeps JSON in-memory.

func NewJSONDataBag

func NewJSONDataBag() JSONDataBag

NewJSONDataBag returns a DataBag implementation that stores data in JSON. The top-level of the JSON structure is always a map.

func (JSONDataBag) Copy

func (s JSONDataBag) Copy() JSONDataBag

Copy returns a copy of the databag.

func (JSONDataBag) Data

func (s JSONDataBag) Data() ([]byte, error)

Data returns all of the bag's data encoded in JSON.

func (JSONDataBag) Get

func (s JSONDataBag) Get(path string) (interface{}, error)

Get takes a path and a pointer to a variable into which the value referenced by the path is written. The path can be dotted. For each dot a JSON object is expected to exist (e.g., "a.b" is mapped to {"a": {"b": <value>}}).

func (JSONDataBag) Set

func (s JSONDataBag) Set(path string, value interface{}) error

Set takes a path to which the value will be written. The path can be dotted, in which case, a nested JSON object is created for each sub-key found after a dot. If the value is nil, the entry is deleted.

func (JSONDataBag) Unset

func (s JSONDataBag) Unset(path string) error

type JSONSchema

type JSONSchema struct{}

JSONSchema is the Schema implementation corresponding to JSONDataBag and it's able to validate its data.

func NewJSONSchema

func NewJSONSchema() JSONSchema

NewJSONSchema returns a Schema able to validate a JSONDataBag's data.

func (JSONSchema) SchemaAt

func (v JSONSchema) SchemaAt(path []string) ([]Schema, error)

SchemaAt always returns the JSONSchema.

func (JSONSchema) Type

func (v JSONSchema) Type() SchemaType

func (JSONSchema) Validate

func (s JSONSchema) Validate(jsonData []byte) error

Validate validates that the specified data can be encoded into JSON.

type NotFoundError

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

func NewNotFoundError

func NewNotFoundError(msg string, v ...any) *NotFoundError

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

func (*NotFoundError) Is

func (e *NotFoundError) Is(err error) bool

type PathError

type PathError string

func (PathError) Error

func (e PathError) Error() string

func (PathError) Is

func (e PathError) Is(err error) bool

type Registry

type Registry struct {
	Account string
	Name    string
	Schema  Schema
	// contains filtered or unexported fields
}

Registry holds a series of related views.

func New

func New(account string, registryName string, views map[string]interface{}, schema Schema) (*Registry, error)

New returns a new registry with the specified views and their rules.

func (*Registry) GetViewsAffectedByPath

func (r *Registry) GetViewsAffectedByPath(path string) []*View

GetViewsAffectedByPath returns all the views in the registry that have visibility into a storage path.

func (*Registry) View

func (d *Registry) View(view string) *View

View returns an view from the registry.

type Schema

type Schema interface {
	Validate(data []byte) error

	// SchemaAt returns the schemas (e.g., string, int, etc) that may be at the
	// provided path. If the path cannot be followed, an error is returned.
	SchemaAt(path []string) ([]Schema, error)

	// Type returns the SchemaType corresponding to the Schema.
	Type() SchemaType
}

Schema takes in data from the DataBag and validates that it's valid and could be committed.

type SchemaType

type SchemaType uint
const (
	Int SchemaType = iota
	Number
	String
	Bool
	Map
	Array
	Any
	Alt
)

func (SchemaType) String

func (v SchemaType) String() string

type StorageSchema

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

StorageSchema represents a registry schema and can be used to validate the storage.

func ParseSchema

func ParseSchema(raw []byte) (*StorageSchema, error)

ParseSchema parses a JSON registry schema and returns a Schema that can be used to validate storage.

func (*StorageSchema) SchemaAt

func (s *StorageSchema) SchemaAt(path []string) ([]Schema, error)

SchemaAt returns the types that may be stored at the specified path.

func (*StorageSchema) Type

func (s *StorageSchema) Type() SchemaType

func (*StorageSchema) Validate

func (s *StorageSchema) Validate(raw []byte) error

Validate validates the provided JSON object.

type ValidationError

type ValidationError struct {
	Path []interface{}
	Err  error
}

TODO: keep a list of expected types (to support alternatives), an actual type/value and then optional unmet constraints for the expected types. Then this could be used to have more concise errors when there are many possible types https://github.com/snapcore/snapd/pull/13502#discussion_r1463658230

func (*ValidationError) Error

func (v *ValidationError) Error() string

type View

type View struct {
	Name string
	// contains filtered or unexported fields
}

View carries access rules for a particular view in a registry.

func (*View) Get

func (v *View) Get(databag DataBag, request string) (interface{}, error)

Get returns the view value identified by the request. If either the named view or the corresponding value can't be found, a NotFoundError is returned.

func (*View) Registry

func (v *View) Registry() *Registry

func (*View) Set

func (v *View) Set(databag DataBag, request string, value interface{}) error

Set sets the named view to a specified non-nil value.

func (*View) Unset

func (v *View) Unset(databag DataBag, request string) error

Jump to

Keyboard shortcuts

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