Documentation
¶
Index ¶
- Constants
- func FailClosedPolicy() bool
- func FailOpenPolicy() bool
- type Application
- type Backend
- func (b *Backend) AuthRep(request threescale.Request) (*threescale.AuthorizeResult, error)
- func (b *Backend) Authorize(request threescale.Request) (*threescale.AuthorizeResult, error)
- func (b *Backend) Flush()
- func (b *Backend) GetPeer() string
- func (b *Backend) OauthAuthRep(request threescale.Request) (*threescale.AuthorizeResult, error)
- func (b *Backend) OauthAuthorize(request threescale.Request) (*threescale.AuthorizeResult, error)
- func (b *Backend) Report(request threescale.Request) (*threescale.ReportResult, error)
- func (b *Backend) SetCacheHitCallback(f func())
- type Cacheable
- type FailurePolicy
- type LimitCounter
- type LocalCache
- type UnlimitedCounter
Constants ¶
const RejectionReasonHeaderExtension = "rejection_reason_header"
RejectionReasonHeader - This is used by authorization endpoints to provide a header that provides an error code describing the different reasons an authorization can be denied.
Variables ¶
This section is empty.
Functions ¶
func FailClosedPolicy ¶
func FailClosedPolicy() bool
FailClosedPolicy denies authorization requests when the upstream 3scale is unavailable
func FailOpenPolicy ¶
func FailOpenPolicy() bool
FailOpenPolicy authorizes requests when the upstream 3scale is unavailable
Types ¶
type Application ¶
type Application struct { RemoteState LimitCounter LocalState LimitCounter UnlimitedCounter UnlimitedCounter sync.RWMutex // contains filtered or unexported fields }
Application defined under a 3scale service It is the responsibility of creator of an application to ensure that the counters for both remote and local state is sorted by ascending granularity. The internals of the cache relies on these semantics.
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend defines the connection to a single backend and maintains a cache for multiple services and applications per backend. It implements the 3scale Client interface
func NewBackend ¶
func NewBackend(url string, client *http.Client, logger core.Logger, policy FailurePolicy) (*Backend, error)
NewBackend returns a cached backend which uses an in-memory cache
func (*Backend) AuthRep ¶
func (b *Backend) AuthRep(request threescale.Request) (*threescale.AuthorizeResult, error)
AuthRep authorizes a request based on the current cached values and reports the new state to the cache in cases where the request has been authorized If the request misses the cache, a remote call to 3scale is made Request Transactions must not be nil and must not be empty If multiple transactions are provided, all but the first are discarded
func (*Backend) Authorize ¶
func (b *Backend) Authorize(request threescale.Request) (*threescale.AuthorizeResult, error)
Authorize authorizes a request based on the current cached values If the request misses the cache, a remote call to 3scale is made Request Transactions must not be nil and must not be empty If multiple transactions are provided, all but the first is discarded
func (*Backend) Flush ¶
func (b *Backend) Flush()
Flush the cached entries and report existing state to backend
func (*Backend) OauthAuthRep ¶ added in v0.0.2
func (b *Backend) OauthAuthRep(request threescale.Request) (*threescale.AuthorizeResult, error)
func (*Backend) OauthAuthorize ¶ added in v0.0.2
func (b *Backend) OauthAuthorize(request threescale.Request) (*threescale.AuthorizeResult, error)
func (*Backend) Report ¶
func (b *Backend) Report(request threescale.Request) (*threescale.ReportResult, error)
Report the provided request transactions to the cache Report always returns with 'Accepted' as bool 'true' and the error will only ever be nil in cases where the provided transaction are empty or nil The background task will abort in cases where we have a cache miss and we also fail to get the hierarchy from 3scale Typically, we can handle cache miss and report to cache once we are aware of a hierarchy for the service Request Transactions must not be nil and must not be empty Supports multiple transactions
func (*Backend) SetCacheHitCallback ¶
func (b *Backend) SetCacheHitCallback(f func())
SetCacheHitCallback
type Cacheable ¶
type Cacheable interface { // Get the application from the cache, return bool value declaring if the cache was hit or not Get(key string) (*Application, bool) // Set the application for the provided key, overwriting any existing entry for the key Set(key string, application *Application) // Keys returns a list of keys for all cached items Keys() []string }
Cacheable defines the required behaviour of a Backend cache The cache key should be in the format of '<serviceID>_<applicationID>'
type FailurePolicy ¶
type FailurePolicy func() bool
FailurePolicy is a function will be called when we have a cache miss and an error reaching the upstream 3scale
type LimitCounter ¶
type LimitCounter api.UsageReports
LimitCounter keeps a count of limits for a given period
type LocalCache ¶
type LocalCache struct {
// contains filtered or unexported fields
}
LocalCache is an implementation of Cacheable providing an in-memory cache
func NewLocalCache ¶
func NewLocalCache() *LocalCache
NewLocalCache returns a LocalCache with its data store initialised
func (LocalCache) Get ¶
func (l LocalCache) Get(cacheKey string) (*Application, bool)
Get entries for LocalCache
func (LocalCache) Keys ¶
func (l LocalCache) Keys() []string
Keys returns a list of keys for all cached items
func (LocalCache) Set ¶
func (l LocalCache) Set(cacheKey string, app *Application)
Set entries for LocalCache
type UnlimitedCounter ¶
UnlimitedCounter keeps a count of metrics without limits