confdb

package
v0.0.0-...-4c8c240 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Only the operator's keys can be used to sign the messages.
	OperatorKey authentication = 1 << iota
	// Messages can be signed on behalf of the operator by the store.
	Store
)

Variables

View Source
var (
	ValidConfdbName = validSubkey
	ValidViewName   = validSubkey
)

Functions

This section is empty.

Types

type BadRequestError

type BadRequestError struct {
	Account    string
	ConfdbName 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 Confdb

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

Confdb holds a series of related views.

func New

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

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

func (*Confdb) GetViewsAffectedByPath

func (db *Confdb) GetViewsAffectedByPath(path string) []*View

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

func (*Confdb) View

func (db *Confdb) View(view string) *View

View returns a view from the confdb.

type Control

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

Control holds the delegations done by the device to operators.

func (Control) Clone

func (cc Control) Clone() Control

Clone returns a deep copy of Control.

func (*Control) Delegate

func (cc *Control) Delegate(operatorID string, views, authMeth []string) error

Delegate delegates the given views with the provided authentication methods to the operator.

func (*Control) Groups

func (cc *Control) Groups() []interface{}

Groups returns the groups in a format that can be used to assemble the next revision of the confdb-control assertion.

func (*Control) IsDelegated

func (cc *Control) IsDelegated(operatorID, view string, authMeth []string) (bool, error)

IsDelegated checks if the view is delegated to the operator with the given authentication methods.

func (*Control) Undelegate

func (cc *Control) Undelegate(operatorID string, views, authMeth []string) error

Undelegate withdraws access to the views that have been delegated with the provided authentication methods.

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 confdb 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) Overwrite

func (s *JSONDataBag) Overwrite(data []byte) error

Overwrite replaces the entire databag with the provided data.

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) Ephemeral

func (v JSONSchema) Ephemeral() bool

func (JSONSchema) PruneEphemeral

func (v JSONSchema) PruneEphemeral(b []byte) ([]byte, error)

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 Schema

type Schema interface {
	// Validate checks that the data conforms to the schema.
	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

	// Ephemeral returns true if the data corresponding to this type should not be
	// saved by snapd.
	Ephemeral() bool

	// PruneEphemeral parses the data and removes paths marked as ephemeral in the
	// schema. The data should've been validated previously to ensure that the data
	// matches the schema. Returns nil if the entire data was pruned.
	PruneEphemeral(data []byte) ([]byte, error)
}

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 confdb schema and can be used to validate the storage.

func ParseSchema

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

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

func (*StorageSchema) Ephemeral

func (s *StorageSchema) Ephemeral() bool

func (*StorageSchema) PruneEphemeral

func (s *StorageSchema) PruneEphemeral(data []byte) ([]byte, error)

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 confdb.

func (*View) Confdb

func (v *View) Confdb() *Confdb

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) 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