store

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package store is a generated GoMock package.

Index

Constants

View Source
const (
	UCPScopePrefix    = "scope"
	UCPResourcePrefix = "resource"
)

Variables

This section is empty.

Functions

func DecodeMap

func DecodeMap(in any, out any) error

DecodeMap decodes map[string]interface{} structure to the type of out.

func GetResource

func GetResource[T any](ctx context.Context, client StorageClient, id string) (*T, error)

GetResource gets the resource data from StorageClient for id.

Types

type DeleteOptions

type DeleteOptions interface {
	ApplyDeleteOption(StoreConfig) StoreConfig
	// contains filtered or unexported methods
}

DeleteOptions applies an option to Delete().

type ETag

type ETag = string

type ErrConcurrency

type ErrConcurrency struct {
}

func (*ErrConcurrency) Error

func (e *ErrConcurrency) Error() string

Error returns the error message for ErrConcurrency error.

func (*ErrConcurrency) Is

func (e *ErrConcurrency) Is(target error) bool

Is checks if the target error is an instance of ErrConcurrency.

type ErrInvalid

type ErrInvalid struct {
	Message string
}

func (*ErrInvalid) Error

func (e *ErrInvalid) Error() string

Error returns a string representation of the error.

func (*ErrInvalid) Is

func (e *ErrInvalid) Is(target error) bool

Is checks if the target error is of type ErrInvalid and if the message of the target error is equal to the message of the ErrInvalid instance or is an empty string.

type ErrNotFound

type ErrNotFound struct {
	// ID of the resource that was not found
	ID string
}

func (*ErrNotFound) Error

func (e *ErrNotFound) Error() string

Error returns a string describing the resource not found error for the given ID.

func (*ErrNotFound) Is

func (e *ErrNotFound) Is(target error) bool

Is checks if the target error is an instance of ErrNotFound and returns a boolean.

type GetOptions

type GetOptions interface {
	// contains filtered or unexported methods
}

GetOptions applies an option to Get().

type Metadata

type Metadata struct {
	ID          string
	ETag        ETag
	APIVersion  string
	ContentType string
}

type MockStorageClient

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

MockStorageClient is a mock of StorageClient interface.

func NewMockStorageClient

func NewMockStorageClient(ctrl *gomock.Controller) *MockStorageClient

NewMockStorageClient creates a new mock instance.

func (*MockStorageClient) Delete

func (m *MockStorageClient) Delete(arg0 context.Context, arg1 string, arg2 ...DeleteOptions) error

Delete mocks base method.

func (*MockStorageClient) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockStorageClient) Get

func (m *MockStorageClient) Get(arg0 context.Context, arg1 string, arg2 ...GetOptions) (*Object, error)

Get mocks base method.

func (*MockStorageClient) Query

func (m *MockStorageClient) Query(arg0 context.Context, arg1 Query, arg2 ...QueryOptions) (*ObjectQueryResult, error)

Query mocks base method.

func (*MockStorageClient) Save

func (m *MockStorageClient) Save(arg0 context.Context, arg1 *Object, arg2 ...SaveOptions) error

Save mocks base method.

type MockStorageClientMockRecorder

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

MockStorageClientMockRecorder is the mock recorder for MockStorageClient.

func (*MockStorageClientMockRecorder) Delete

func (mr *MockStorageClientMockRecorder) Delete(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockStorageClientMockRecorder) Get

func (mr *MockStorageClientMockRecorder) Get(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call

Get indicates an expected call of Get.

func (*MockStorageClientMockRecorder) Query

func (mr *MockStorageClientMockRecorder) Query(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call

Query indicates an expected call of Query.

func (*MockStorageClientMockRecorder) Save

func (mr *MockStorageClientMockRecorder) Save(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call

Save indicates an expected call of Save.

type MutatingOptions

type MutatingOptions interface {
	SaveOptions
	DeleteOptions
}

MutatingOptions applies an option to Delete() or Save().

func WithETag

func WithETag(etag ETag) MutatingOptions

WithETag sets the ETag field in the StoreConfig struct.

type Object

type Object struct {
	Metadata

	// Data is the payload of the object. It will be marshaled to and from JSON for storage.
	Data any
}

func (*Object) As

func (o *Object) As(out any) error

As decodes the Data field of the Object instance into the out parameter.

func (Object) MatchesFilters

func (o Object) MatchesFilters(filters []QueryFilter) (bool, error)

MatchesFilters checks if the object's data matches the given filters and returns a boolean and an error.

type ObjectQueryResult

type ObjectQueryResult struct {
	// PaginationToken represents the token for pagination, such as continuation token.
	PaginationToken string
	// Items represents the list of documents.
	Items []Object
}

ObjectQueryResult represents the result of Query().

type Query

type Query struct {
	// Scope sets the root scope of the query. This will be the fully-qualified root scope. This can be a
	// UCP scope ('/planes/...') or an ARM scope as long as the data-store is self-consistent.
	//
	// Example:
	//	/planes/radius/local/resourceGroups/cool-group/
	RootScope string

	// ScopeRecursive determines whether the root scope is applied recursively.
	//
	// Example: If 'true' the following value of Scope would match all of the provided root scopes.
	//	/planes/radius/local/ ->
	//		/planes/radius/local/
	//		/planes/radius/local/resourceGroups/cool-group
	//		/planes/radius/local/resourceGroups/cool-group2
	ScopeRecursive bool

	// ResourceType is the optional resource type used to filter the query. ResourceType must be a fully-qualified
	// type if it is provided.
	//
	// Example:
	//	Applications.Core/applications
	ResourceType string

	// RoutingScopePrefix is the optional routing scope used to filter the query. RoutingScopePrefix should be the prefix
	// of the desired resources (types and names). RoutingScopePrefix should have a resource name as its last segment
	// not a type.
	//
	// Example:
	//	/Applications.Core/applications/my-app/
	RoutingScopePrefix string

	// IsScopeQuery is used to determine whether to query scopes (true) or resources (false).
	// Example: To query all "plane"
	// 	set RootScope to /planes and both ScopeRecursive and IsScopeQuery to True.
	// If ScopeQuery is False, we would be querying for resources that match RootScope and other optional
	// query field values.
	// Example: To query all resources in a radius local plane scope
	// 	set RootScope to /planes/radius/local and ScopeRecursive = True and IsScopeQuery to False.
	IsScopeQuery bool

	// Filters is an query filter to filter the specific property value.
	Filters []QueryFilter
}

Query specifies the structure of a query. RootScope is required and other fields are optional.

type QueryFilter

type QueryFilter struct {
	Field string
	Value string
}

QueryFilter is the filter which filters property in resource entity.

type QueryOptions

type QueryOptions interface {
	ApplyQueryOption(StoreConfig) StoreConfig
	// contains filtered or unexported methods
}

QueryOptions applies an option to Query().

func WithMaxQueryItemCount

func WithMaxQueryItemCount(maxcnt int) QueryOptions

WithMaxQueryItemCount creates a QueryOptions instance that sets the maximum number of items in query result.

func WithPaginationToken

func WithPaginationToken(token string) QueryOptions

WithPaginationToken sets pagination token for Query().

type SaveOptions

type SaveOptions interface {
	ApplySaveOption(StoreConfig) StoreConfig
	// contains filtered or unexported methods
}

SaveOptions applies an option to Save().

type StorageClient

type StorageClient interface {
	Query(ctx context.Context, query Query, options ...QueryOptions) (*ObjectQueryResult, error)
	Get(ctx context.Context, id string, options ...GetOptions) (*Object, error)
	Delete(ctx context.Context, id string, options ...DeleteOptions) error
	Save(ctx context.Context, obj *Object, options ...SaveOptions) error
}

type StoreConfig

type StoreConfig struct {
	// PaginationToken represents pagination token such as continuation token.
	PaginationToken string

	// MaxQueryItemCount represents max items in query result.
	MaxQueryItemCount int

	// ETag represents the entity tag for optimistic consistency control.
	ETag ETag
}

Store Config represents the configurations of storageclient APIs.

func NewDeleteConfig

func NewDeleteConfig(opts ...DeleteOptions) StoreConfig

NewDeleteConfig applies the given DeleteOptions to a StoreConfig and returns the resulting StoreConfig for Delete().

func NewQueryConfig

func NewQueryConfig(opts ...QueryOptions) StoreConfig

NewQueryConfig applies a set of QueryOptions to a StoreConfig and returns the modified StoreConfig for Query().

func NewSaveConfig

func NewSaveConfig(opts ...SaveOptions) StoreConfig

NewSaveConfig applies a set of SaveOptions to a StoreConfig and returns the modified StoreConfig for Save().

Directories

Path Synopsis
Package apiserverstore stores resources using the Kubernetes API Server - using CRDs as a key-value store.
Package apiserverstore stores resources using the Kubernetes API Server - using CRDs as a key-value store.
api/ucp.dev/v1alpha1
Package v1alpha1 contains API Schema definitions for the ucp v1alpha1 API group +kubebuilder:object:generate=true +groupName=ucp.dev
Package v1alpha1 contains API Schema definitions for the ucp v1alpha1 API group +kubebuilder:object:generate=true +groupName=ucp.dev
Package etcdstore stores resources using etcd.
Package etcdstore stores resources using etcd.
storeutil contains utility functions for implementing storage backends.
storeutil contains utility functions for implementing storage backends.

Jump to

Keyboard shortcuts

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