quota

package
v0.0.3-dev Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2020 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Args

type Args struct {
	// DeduplicationID is used for deduplicating quota allocation/free calls in the case of
	// failed RPCs and retries. This should be a UUID per call, where the same
	// UUID is used for retries of the same quota allocation or release call.
	DeduplicationID string

	// The amount of quota being allocated or released.
	QuotaAmount int64

	// If true, allows a response to return less quota than requested. When
	// false, the exact requested amount is returned or 0 if not enough quota
	// was available.
	BestEffort bool
}

Args controls the quota requested

type Manager

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

A Manager tracks multiple Apigee quotas

func NewManager

func NewManager(options Options) (*Manager, error)

NewManager constructs and starts a new Manager. Call Close when done.

func (*Manager) Apply

func (m *Manager) Apply(auth *auth.Context, p *product.APIProduct, args Args) (*Result, error)

Apply a quota request to the local quota bucket and schedule for sync

func (*Manager) Close

func (m *Manager) Close()

Close shuts down the manager.

func (*Manager) Start

func (m *Manager) Start()

Start starts the manager.

type Options

type Options struct {
	// Client is a configured HTTPClient
	Client *http.Client
	// BaseURL of the Apigee internal proxy
	BaseURL *url.URL
	// Key is provisioning key
	Key string
	// Secret is provisioning secret
	Secret string
}

Options allows us to specify options for how this auth manager will run

type Request

type Request struct {
	Identifier string `json:"identifier"`
	Weight     int64  `json:"weight"`
	Interval   int64  `json:"interval"`
	Allow      int64  `json:"allow"`
	TimeUnit   string `json:"timeUnit"`
}

A Request is sent to Apigee's quota server to allocate quota.

type Result

type Result struct {
	Allowed    int64 `json:"allowed"`
	Used       int64 `json:"used"`
	Exceeded   int64 `json:"exceeded"`
	ExpiryTime int64 `json:"expiryTime"`
	Timestamp  int64 `json:"timestamp"`
}

A Result is a response from Apigee's quota server that gives information about how much quota is available. Note that Used will never exceed Allowed, but Exceeded will be positive in that case.

type ResultCache

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

ResultCache is a structure to track Results by ID, bounded by size

func (*ResultCache) Add

func (d *ResultCache) Add(id string, result *Result)

Add a Result to the cache

func (*ResultCache) Get

func (d *ResultCache) Get(id string) *Result

Get a Result from the cache, nil if none

Jump to

Keyboard shortcuts

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