storage

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const ConfKey = "storage"

Variables

This section is empty.

Functions

func RegisterDriver

func RegisterDriver(name string, cons Constructor)

RegisterDriver registers a storage driver.

func Reload added in v0.15.0

func Reload(ctx context.Context, rs ReloadableStore) error

func TestSubscription

func TestSubscription(s Subscribable) func(*testing.T, time.Duration, ...Event)

TestSubscription is a helper to test subscriptions.

Types

type Conf

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

Conf is required configuration for storage. +desc=This section is required. The field driver must be set to indicate which driver to use.

func GetConf added in v0.15.0

func GetConf() (*Conf, error)

func (*Conf) Key

func (c *Conf) Key() string

func (*Conf) UnmarshalYAML added in v0.15.0

func (c *Conf) UnmarshalYAML(unmarshal func(any) error) error

type Constructor

type Constructor func(context.Context, *config.Wrapper) (Store, error)

Constructor is a constructor function for a storage driver.

type Event

type Event struct {
	SchemaFile string
	Kind       EventKind
	PolicyID   namer.ModuleID
}

Event is an event detected by the storage layer.

func NewPolicyEvent added in v0.11.0

func NewPolicyEvent(kind EventKind, policyID namer.ModuleID) Event

NewPolicyEvent creates a new storage event for a policy.

func NewSchemaEvent added in v0.11.0

func NewSchemaEvent(kind EventKind, schemaFile string) Event

NewSchemaEvent creates a new storage event for a schema.

func (Event) String

func (evt Event) String() string

type EventKind

type EventKind int

EventKind identifies the kind of storage event such as addition or deletion.

const (
	EventAddOrUpdatePolicy EventKind = iota
	EventDeletePolicy
	EventAddOrUpdateSchema
	EventDeleteSchema
	EventNop
)

type Instrumented added in v0.15.0

type Instrumented interface {
	RepoStats(context.Context) RepoStats
}

Instrumented stores expose repository stats.

type InvalidPolicyError

type InvalidPolicyError struct {
	Err     error
	Message string
}

InvalidPolicyError is a custom error to signal that a policy is invalid.

func NewInvalidPolicyError

func NewInvalidPolicyError(err error, msg string, args ...any) InvalidPolicyError

func (InvalidPolicyError) Error

func (ipe InvalidPolicyError) Error() string

func (InvalidPolicyError) Unwrap

func (ipe InvalidPolicyError) Unwrap() error

type InvalidSchemaError added in v0.12.0

type InvalidSchemaError struct {
	Err     error
	Message string
}

InvalidSchemaError is a custom error to signal that a schema is invalid.

func NewInvalidSchemaError added in v0.12.0

func NewInvalidSchemaError(err error, msg string, args ...any) InvalidSchemaError

func (InvalidSchemaError) Error added in v0.12.0

func (ise InvalidSchemaError) Error() string

func (InvalidSchemaError) Unwrap added in v0.12.0

func (ise InvalidSchemaError) Unwrap() error

type MutableStore

type MutableStore interface {
	Store
	AddOrUpdate(context.Context, ...policy.Wrapper) error
	AddOrUpdateSchema(context.Context, ...*schemav1.Schema) error
	DeleteSchema(context.Context, ...string) error
	Delete(context.Context, ...namer.ModuleID) error
}

MutableStore is a store that allows mutations.

type ReloadableStore added in v0.15.0

type ReloadableStore interface {
	Store
	Reload(context.Context) error
}

ReloadableStore is a store that allows reloading (blob, disk, git).

type RepoStats added in v0.15.0

type RepoStats struct {
	PolicyCount       map[policy.Kind]int
	AvgRuleCount      map[policy.Kind]float64
	AvgConditionCount map[policy.Kind]float64
	SchemaCount       int
}

type Store

type Store interface {
	Subscribable
	// Driver is the name of the storage backend implementation.
	Driver() string
	// GetCompilationUnits gets the compilation units for the given module IDs.
	GetCompilationUnits(context.Context, ...namer.ModuleID) (map[namer.ModuleID]*policy.CompilationUnit, error)
	// GetDependents returns the dependents of the given modules.
	GetDependents(context.Context, ...namer.ModuleID) (map[namer.ModuleID][]namer.ModuleID, error)
	// ListPolicyIDs returns the policy IDs in the store
	ListPolicyIDs(context.Context) ([]string, error)
	// ListSchemaIDs returns the schema ids in the store
	ListSchemaIDs(context.Context) ([]string, error)
	// LoadSchema loads the given schema from the store.
	LoadSchema(context.Context, string) (io.ReadCloser, error)
	// LoadPolicy loads the given policy from the store
	LoadPolicy(context.Context, ...string) ([]*policy.Wrapper, error)
}

Store is the common interface implemented by storage backends.

func New

func New(ctx context.Context) (Store, error)

New returns a storage driver implementation based on the configured driver.

func NewFromConf added in v0.15.0

func NewFromConf(ctx context.Context, confWrapper *config.Wrapper) (Store, error)

NewFromConf returns a storage driver implementation based on the provided configuration.

type Subscribable

type Subscribable interface {
	// Subscribe adds a subscriber to listen for storage notifications.
	Subscribe(Subscriber)
	// Unsubscribe removes a subscriber.
	Unsubscribe(Subscriber)
}

Subscribable is an interface for managing subscriptions to storage events.

type Subscriber

type Subscriber interface {
	SubscriberID() string
	OnStorageEvent(...Event)
}

Subscriber is the interface implemented by storage subscribers.

type SubscriptionManager

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

func NewSubscriptionManager

func NewSubscriptionManager(ctx context.Context) *SubscriptionManager

func (*SubscriptionManager) NotifySubscribers

func (sm *SubscriptionManager) NotifySubscribers(events ...Event)

Notify sends the events to all subscribers.

func (*SubscriptionManager) Subscribe

func (sm *SubscriptionManager) Subscribe(s Subscriber)

func (*SubscriptionManager) Unsubscribe

func (sm *SubscriptionManager) Unsubscribe(s Subscriber)

Directories

Path Synopsis
db

Jump to

Keyboard shortcuts

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