quotaconfig

package
v0.0.0-...-cf55a68 Latest Latest
Warning

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

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

Documentation

Overview

Package quotaconfig exports the interface required by the quota library to read *pb.Policy configs. Provides an in-memory implementation of the interface suitable for testing. See quotaconfig subpackages for other implementations.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("policy not found")

ErrNotFound must be returned by Interface.Get implementations when the named *pb.Policy is not found.

Functions

func ValidatePolicy

func ValidatePolicy(ctx *validation.Context, p *pb.Policy)

ValidatePolicy validates the given *pb.Policy.

Types

type Interface

type Interface interface {
	// Get returns the named *pb.Policy or ErrNotFound if it doesn't exist.
	//
	// Called by the quota library every time quota is manipulated,
	// so implementations should return relatively quickly.
	Get(context.Context, string) (*pb.Policy, error)

	// Refresh fetches all *pb.Policies.
	//
	// Implementations should validate (see ValidatePolicy) and cache configs so
	// future Get calls return relatively quickly.
	Refresh(context.Context) error
}

Interface encapsulates the functionality needed to implement a configuration layer usable by the quota library. Implementations should ensure returned *pb.Policies are valid (see ValidatePolicy).

func NewMemory

func NewMemory(ctx context.Context, policies []*pb.Policy) (Interface, error)

NewMemory returns a new Memory initialized with the given policies.

type Memory

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

Memory holds known *pb.Policy protos in memory. Implements Interface. Safe for concurrent use.

func (*Memory) Get

func (m *Memory) Get(ctx context.Context, name string) (*pb.Policy, error)

Get returns a copy of the named *pb.Policy if it exists, or else ErrNotFound.

func (*Memory) Refresh

func (m *Memory) Refresh(ctx context.Context) error

Refresh fetches all *pb.Policies.

Directories

Path Synopsis
Package configservice provides an implementation of quotaconfig.Interface which fetches *pb.Policy configs stored with the LUCI Config service.
Package configservice provides an implementation of quotaconfig.Interface which fetches *pb.Policy configs stored with the LUCI Config service.

Jump to

Keyboard shortcuts

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