Documentation ¶
Index ¶
- Variables
- func FastUpdateNonceProtectedResource[T nonceProtectedResource](ctx context.Context, bk backend.Backend, key []byte, resource T) error
- type MarshalFunc
- type Resource
- type Service
- func (s *Service[T]) CreateResource(ctx context.Context, resource T) (T, error)
- func (s *Service[T]) DeleteAllResources(ctx context.Context) error
- func (s *Service[T]) DeleteResource(ctx context.Context, name string) error
- func (s *Service[T]) GetResource(ctx context.Context, name string) (resource T, err error)
- func (s *Service[T]) GetResources(ctx context.Context) ([]T, error)
- func (s *Service[T]) ListResources(ctx context.Context, pageSize int, pageToken string) ([]T, string, error)
- func (s *Service[T]) ListResourcesReturnNextResource(ctx context.Context, pageSize int, pageToken string) ([]T, *T, error)
- func (s *Service[T]) MakeBackendItem(resource T, name string) (backend.Item, error)
- func (s *Service[T]) MakeKey(name string) []byte
- func (s *Service[T]) RunWhileLocked(ctx context.Context, lockName string, ttl time.Duration, ...) error
- func (s *Service[T]) UpdateAndSwapResource(ctx context.Context, name string, modify func(T) error) (T, error)
- func (s *Service[T]) UpdateResource(ctx context.Context, resource T) (T, error)
- func (s *Service[T]) UpsertResource(ctx context.Context, resource T) (T, error)
- func (s *Service[T]) WithPrefix(parts ...string) *Service[T]
- type ServiceConfig
- type UnmarshalFunc
Constants ¶
This section is empty.
Variables ¶
var ErrNonceViolation = errors.New("nonce-violation")
ErrNonceViolation is the error returned by FastUpdateNonceProtectedResource when a nonce-protected update fails due to concurrent modification. This error should be caught and re-mapped into an appropriate user-facing message for the given resource type.
Functions ¶
func FastUpdateNonceProtectedResource ¶
func FastUpdateNonceProtectedResource[T nonceProtectedResource](ctx context.Context, bk backend.Backend, key []byte, resource T) error
FastUpdateNonceProtectedResource is a helper for updating a resource that is protected by a nonce. The target resource must store its nonce value in a top-level 'nonce' field in order for correct nonce semantics to be observed.
Types ¶
type MarshalFunc ¶
type MarshalFunc[T Resource] func(T, ...services.MarshalOption) ([]byte, error)
MarshalFunc is a type signature for a marshaling function.
type Resource ¶
type Resource interface {
GetName() string
}
Resource represents a Teleport resource that may be generically persisted into the backend.
type Service ¶
type Service[T Resource] struct { // contains filtered or unexported fields }
Service is a generic service for interacting with resources in the backend.
func NewService ¶
func NewService[T Resource](cfg *ServiceConfig[T]) (*Service[T], error)
NewService will return a new generic service with the given config. This will panic if the configuration is invalid.
func (*Service[T]) CreateResource ¶
CreateResource creates a new resource.
func (*Service[T]) DeleteAllResources ¶
DeleteAllResources removes all resources.
func (*Service[T]) DeleteResource ¶
DeleteResource removes the specified resource.
func (*Service[T]) GetResource ¶
GetResource returns the specified resource.
func (*Service[T]) GetResources ¶
GetResources returns a list of all resources.
func (*Service[T]) ListResources ¶
func (s *Service[T]) ListResources(ctx context.Context, pageSize int, pageToken string) ([]T, string, error)
ListResources returns a paginated list of resources.
func (*Service[T]) ListResourcesReturnNextResource ¶
func (s *Service[T]) ListResourcesReturnNextResource(ctx context.Context, pageSize int, pageToken string) ([]T, *T, error)
ListResourcesReturnNextResource returns a paginated list of resources. The next resource is returned, which allows consumers to construct the next pagination key as appropriate.
func (*Service[T]) MakeBackendItem ¶
MakeBackendItem will check and make the backend item.
func (*Service[T]) RunWhileLocked ¶
func (s *Service[T]) RunWhileLocked(ctx context.Context, lockName string, ttl time.Duration, fn func(context.Context, backend.Backend) error) error
RunWhileLocked will run the given function in a backend lock. This is a wrapper around the backend.RunWhileLocked function.
func (*Service[T]) UpdateAndSwapResource ¶
func (s *Service[T]) UpdateAndSwapResource(ctx context.Context, name string, modify func(T) error) (T, error)
UpdateAndSwapResource will get the resource from the backend, modify it, and swap the new value into the backend.
func (*Service[T]) UpdateResource ¶
UpdateResource updates an existing resource.
func (*Service[T]) UpsertResource ¶
UpsertResource upserts a resource.
func (*Service[T]) WithPrefix ¶
WithPrefix will return a service with the given parts appended to the backend prefix.
type ServiceConfig ¶
type ServiceConfig[T Resource] struct { Backend backend.Backend ResourceKind string PageLimit uint BackendPrefix string MarshalFunc MarshalFunc[T] UnmarshalFunc UnmarshalFunc[T] }
ServiceConfig is the configuration for the service configuration.
func (*ServiceConfig[T]) CheckAndSetDefaults ¶
func (c *ServiceConfig[T]) CheckAndSetDefaults() error
type UnmarshalFunc ¶
type UnmarshalFunc[T Resource] func([]byte, ...services.MarshalOption) (T, error)
UnmarshalFunc is a type signature for an unmarshalling function.