api

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: Apache-2.0 Imports: 2 Imported by: 5

Documentation

Index

Constants

View Source
const (

	// LimitExtension is the key to enable this extension when calling 3scale backend - set to 1 to enable
	LimitExtension = "limit_headers"

	// HierarchyExtension is the key to enabling hierarchy feature. Set its bool value to 1 to enable.
	// https://github.com/3scale/apisonator/issues/75
	HierarchyExtension = "hierarchy"

	// FlatUsageExtension is the key to enabling the "flat usage" feature for reporting purposes - set to 1 to enable
	// Enabling this feature implies that the backend will not calculate the relationships between hierarchies and
	// pushes this compute responsibility back to the client.
	// Therefore when enabled, it is the clients responsibility to ensure that parent --> child metrics
	// are calculated correctly. This feature is supported in versions >= 2.8
	// Use the GetVersion() function to ensure suitability or risk incurring unreported state.
	FlatUsageExtension = "flat_usage"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthType

type AuthType string

AuthType maps to a known client authentication pattern Currently known and supported are 0=ServiceToken 1=ProviderKey

const (

	// ServiceToken as a specific key for the service
	ServiceToken AuthType = "service_token"
	// ProviderKey for all services under an account
	ProviderKey AuthType = "provider_key"
)

type ClientAuth

type ClientAuth struct {
	Type  AuthType
	Value string
}

ClientAuth holds the key type (ProviderKey, ServiceToken) and their respective value for authenticating the client against a given service.

type Extensions

type Extensions map[string]string

Extensions are features or behaviours that are not part of the standard API for a variety of reasons See https://github.com/3scale/apisonator/blob/v2.96.2/docs/extensions.md for context

type Hierarchy

type Hierarchy map[string][]string

Hierarchy maps a parent metric to its child metrics

func (Hierarchy) DeepCopy

func (h Hierarchy) DeepCopy() Hierarchy

DeepCopy returns a clone of the original Metrics. It provides a deep copy of both the key and the value of the original Hierarchy.

type Metrics

type Metrics map[string]int

Metrics let you track the usage of your API in 3scale

func (Metrics) Add

func (m Metrics) Add(name string, value int) (int, error)

Add takes a provided key and value and adds them to the Metric 'm' If the metric already existed in 'm', then the value will be added (if positive) or subtracted (if negative) from the existing value. If a subtraction leads to a negative value Add returns an error and the change will be discarded. Returns the updated value (or current value in error cases) as well as the error.

func (Metrics) AddHierarchyToMetrics added in v0.0.4

func (m Metrics) AddHierarchyToMetrics(hierarchy Hierarchy) Metrics

AddHierarchyToMetrics takes the provided hierarchy structure, and uses it to determine how the metrics, m, are affected, incrementing parent metrics based on the value of the parents child/children metrics. Returns new Metrics, leaving metrics m in it's original state.

func (Metrics) DeepCopy

func (m Metrics) DeepCopy() Metrics

DeepCopy returns a clone of the original Metrics

func (Metrics) Delete

func (m Metrics) Delete(name string)

Delete a metric m['name'] if present

func (Metrics) Set

func (m Metrics) Set(name string, value int) error

Set takes a provided key and value and sets that value of the key in 'm', overwriting any value that exists previously.

func (Metrics) SubtractHierarchyFromMetrics added in v0.0.4

func (m Metrics) SubtractHierarchyFromMetrics(hierarchy Hierarchy) Metrics

SubtractHierarchyFromMetrics takes the provided hierarchy structure, and uses it to determine how the metrics, m, are affected, decrementing parent metrics based on the value of the parents child/children metrics. Returns new Metrics, leaving metrics m in it's original state.

type Params

type Params struct {

	// AppID is used in the Application Identifier and Key pairs authentication method.
	// It is mutually exclusive with the API Key authentication method outlined below
	// therefore if both are provided, the value defined in 'UserKey' will be prioritised.
	AppID string `json:"app_id"`

	// AppKey is an optional, secret key which can be used in conjunction with 'AppID'
	AppKey string `json:"app_key"`

	// Referrer is an optional value which is required only if referrer filtering is enabled.
	// If special value '*' (wildcard) is passed, the referrer check is bypassed.
	Referrer string `json:"referrer"`

	// UserID is an optional value for identifying an end user.
	// Required only when the application is rate limiting end users.
	UserID string `json:"user_id"`

	// UserKey is the identifier and shared secret of the application if the authentication pattern is API Key.
	// Mutually exclusive with, and prioritised over 'AppID'.
	UserKey string `json:"user_key"`
}

Params that are embedded in each Transaction to 3scale API This structure simplifies the formatting of the transaction from the callers perspective It is used to authenticate the application

type Period

type Period int

Period wraps the known rate limiting periods as defined in 3scale

const (
	Minute Period = iota
	Hour
	Day
	Week
	Month
	Year
	Eternity
)

Predefined, known LimitPeriods which can be used in 3scale rate limiting functionality These values represent time durations.

func (Period) String added in v0.5.0

func (p Period) String() string

String returns a string representation of the Period

type PeriodWindow

type PeriodWindow struct {
	Period Period
	Start  int64
	End    int64
}

PeriodWindow holds information about the start and end time of the specified period Start and End are unix timestamp

func (PeriodWindow) IsEqual added in v0.5.0

func (pw PeriodWindow) IsEqual(window PeriodWindow) bool

IsEqual compares two PeriodWindows. They are equal if the period is the same and timestamps for start and end do not differ

type RateLimits

type RateLimits struct {
	LimitRemaining int
	LimitReset     int
}

RateLimits holds the values returned when using rate limiting extension

type Service

type Service string

Service represents a 3scale service marked by its identifier (service_id)

type Transaction

type Transaction struct {
	Metrics Metrics
	Params  Params
	// Timestamp is a unix timestamp.
	// Timestamp will only be taken into account when calling the Report API
	Timestamp int64
}

Transaction holds the params and optional additions that will be sent to 3scale as query parameters or headers.

type UsageReport

type UsageReport struct {
	PeriodWindow PeriodWindow
	MaxValue     int
	CurrentValue int
}

UsageReport for rate limiting information gathered from using extensions

func (UsageReport) IsForDay added in v0.5.0

func (ur UsageReport) IsForDay() bool

func (UsageReport) IsForEternity added in v0.5.0

func (ur UsageReport) IsForEternity() bool

func (UsageReport) IsForHour added in v0.5.0

func (ur UsageReport) IsForHour() bool

func (UsageReport) IsForMinute added in v0.5.0

func (ur UsageReport) IsForMinute() bool

func (UsageReport) IsForMonth added in v0.5.0

func (ur UsageReport) IsForMonth() bool

func (UsageReport) IsForWeek added in v0.5.0

func (ur UsageReport) IsForWeek() bool

func (UsageReport) IsForYear added in v0.5.0

func (ur UsageReport) IsForYear() bool

func (UsageReport) IsSame added in v0.5.0

func (ur UsageReport) IsSame(usageReport UsageReport) bool

IsSame does a comparison of two usage reports. They are considered the same only if their PeriodWindows are equal and the max value for the limit has not changed. Current limit values are ignored.

type UsageReports

type UsageReports map[string][]UsageReport

UsageReports defines a map of metric names to a list of 'UsageReport'

func (UsageReports) OrderByAscendingGranularity added in v0.5.0

func (urs UsageReports) OrderByAscendingGranularity()

OrderByAscendingGranularity sorts each slice in the usage reports in order of ascending granularity

func (UsageReports) OrderByDescendingGranularity added in v0.5.0

func (urs UsageReports) OrderByDescendingGranularity()

OrderByDescendingGranularity sorts each slice in the usage reports in order of descending granularity

Jump to

Keyboard shortcuts

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