Documentation ¶
Index ¶
- Constants
- func RedisFinishUpdate(conn redis.Conn, started time.Time, catalogVersion string, ...)
- func RedisStartUpdate(conn redis.Conn, tm time.Time) (*time.Time, error)
- func RedisUpdate(conn redis.Conn, ail *APIIndexedLimits)
- func RedisUpdateLimits(conn redis.Conn, ail *APIIndexedLimits)
- func UpdateSharedMatcher(ail *APIIndexedLimits, pm *pathmatcher.SharedPathMatcher)
- type APICatalogVersion
- type APIIndexedLimits
- type APIKeyIndexedLimits
- type APIKeys
- type APILimits
- type CatalogURLs
- type CatalogUpdater
- type DefaultAPIKeys
- type EndpointIndexedDef
- type EndpointIndexedLimits
- type RedisCatalogStatus
Constants ¶
const ( RedisKeyLimitsVersion string = "dynlimits_limits_version" RedisKeyCatalogVersion string = "dynlimits_catalog_version" RedisKeyUpdating string = "dynlimits_updating" RedisKeyUpdatingLimitsVersion string = "dynlimits_updating_limits_version" RedisKeyUpdatingCatalogVersion string = "dynlimits_updating_catalog_version" RedisKeyUpdateStarted string = "dynlimits_update_started" RedisKeyUpdateFinished string = "dynlimits_update_finished" UpdateTimeoutSeconds int64 = 5 * 60 // 5 min to update the catalog )
Variables ¶
This section is empty.
Functions ¶
func RedisFinishUpdate ¶
func RedisStartUpdate ¶
RedisStartUpdate sets a redis key with the time starting to update
the redis catalog if it is not set (no other process is updatating the catalog) returning the given timestamp. In case it cannot set the timestamp it returns a nil time, and nil error.
func RedisUpdate ¶
func RedisUpdate(conn redis.Conn, ail *APIIndexedLimits)
RedisUpdate loads a catalog of per endpoint and api key into Redis
func RedisUpdateLimits ¶
func RedisUpdateLimits(conn redis.Conn, ail *APIIndexedLimits)
func UpdateSharedMatcher ¶
func UpdateSharedMatcher(ail *APIIndexedLimits, pm *pathmatcher.SharedPathMatcher)
UpdateSharedMatcher updates the valid paths where rate limits can be applied to
Types ¶
type APICatalogVersion ¶
type APICatalogVersion struct { SemVer string `json:"semver"` HashVer string `json:"hash"` Released time.Time `json:"released"` }
APICatalogVersion contains the version information for an API Catalog
- SemVer: a semantic version v3.22.15 (not useful for machine consumption)
- HashVer: a hash generated from the catalog data, the semver, and the release date
- Released: the time at what this catalog was created or updated
type APIIndexedLimits ¶
type APIIndexedLimits struct { Version APICatalogVersion `json:"version"` Methods []string `json:"methods"` Paths []string `json:"paths"` Endpoints []EndpointIndexedDef `json:"endpoints"` APILimits []APIKeyIndexedLimits `json:"apilimits"` }
APIIndexedLimits contains all the information required to perform per endpoint and api key rate limits
func (*APIIndexedLimits) Validate ¶
func (ail *APIIndexedLimits) Validate() []error
Validate checks that all indices point to valid positions in each of the lists.
type APIKeyIndexedLimits ¶
type APIKeyIndexedLimits struct { APIKey string `json:"key"` Limits []EndpointIndexedLimits `json:"limits"` }
APIKeyIndexedLimits has the limits to be applied to a given API Key. See `EndpointsIndexedLimits` to see how to reference tha endpoints.
type CatalogURLs ¶
CatalogURLs contains all the endpoints to get information from the control server
- GetLatestVersion: an url to get the latest hash for the most recent version of the catalog. (We could get the catalog with an ETag)
- GetDiff: an url to get the difference between two versions with from and to params. If to is not provided, it is assumed to be the most recent one. The diff is always "forward" meaning that from is always before in time than to
- GetIndexedCatalog: to retrieve the full catalog (to be used if there is no existing version in the redis ? or we want a full rebuild)
type CatalogUpdater ¶
type CatalogUpdater struct { RequestOnDemandUpdate chan bool RequestShutdown chan bool // contains filtered or unexported fields }
CatalogUpdater holds the information required to keep the catalago updated from the command and control server
urls: the command and control URL server
catalogAPIKey: the api to use when requesting updates
serverCheckSeconds: how often we need to poll the server for new updates
redisCheckSeconds: we check in redis if some other proxy has already updated to a new version the data in Redis
redisPool: a pool of connections for redis
RequestOnDemandUpdate: a channel to be used by the client code to force an update
RequestShutdown: a channel to notify that we want the poller to stop
func LaunchUpdatesPoller ¶
func LaunchUpdatesPoller(redisPool *redis.Pool, updateBaseURL string, catalogApiKey string, matcher *pathmatcher.SharedPathMatcher, redisCheckSeconds int64, serverCheckSeconds int64) (*CatalogUpdater, error)
LaunchUpdatesPoller returns a CatalogUpdater
type DefaultAPIKeys ¶
type DefaultAPIKeys struct { }
func NewDefaultAPIKeys ¶
func NewDefaultAPIKeys() *DefaultAPIKeys
func (*DefaultAPIKeys) BlockUntil ¶
func (dak *DefaultAPIKeys) BlockUntil(apiKey string, until time.Time)
type EndpointIndexedDef ¶
EndpointIndexedDef contains the index to the path definition, and an index to the http verb to define an endpoint
type EndpointIndexedLimits ¶
EndpointIndexedLimits contains an index to the list of endpoints definitions and the limit to apply to this endpoint.
type RedisCatalogStatus ¶
type RedisCatalogStatus struct { LimitsVersion string CatalogVersion string UpdateStarted time.Time UpdateFinished time.Time }
func RedisGetCatalogStatus ¶
func RedisGetCatalogStatus(conn redis.Conn) (*RedisCatalogStatus, error)
RedisGetVersions returns the catalogVersion, and limitsVersions