github.com/TykTechnologies/tyk/internal/model
Package model provides an internal data model for use across the gateway.
Package
Files: 6. Third party imports: 1. Imports from organisation: 0. Tests: 0. Benchmarks: 0.
Constants
// Other.
const (
Pass = apidef.Pass
Warn = apidef.Warn
Fail = apidef.Fail
System = apidef.System
Datastore = apidef.Datastore
)
Vars
var (
// ErrBucketFull is returned when the amount requested to add exceeds the remaining space in the bucket.
ErrBucketFull = errors.New("add exceeds free bucket capacity")
)
Types
Bucket
Bucket interface for interacting with leaky buckets: https://en.wikipedia.org/wiki/Leaky_bucket
| Field name | Field type | Comment |
|---|---|---|
| type |
|
No comment on field. |
type Bucket interface {
// Capacity of the bucket.
Capacity() uint
// Remaining space in the bucket.
Remaining() uint
// Reset returns when the bucket will be drained.
Reset() time.Time
// Add to the bucket. Returns bucket state after adding.
Add(uint) (BucketState, error)
}
BucketState
BucketState is a snapshot of a bucket's properties.
| Field name | Field type | Comment |
|---|---|---|
| Capacity |
|
No comment on field. |
| Remaining |
|
No comment on field. |
| Reset |
|
No comment on field. |
type BucketState struct {
Capacity uint
Remaining uint
Reset time.Time
}
BucketStorage
BucketStorage interface for generating buckets keyed by a string.
| Field name | Field type | Comment |
|---|---|---|
| type |
|
No comment on field. |
type BucketStorage interface {
// Create a bucket with a name, capacity, and rate.
// rate is how long it takes for full capacity to drain.
Create(name string, capacity uint, rate time.Duration) (Bucket, error)
}
ConfigProvider
ConfigProvider provides a typical config getter signature.
| Field name | Field type | Comment |
|---|---|---|
| type |
|
No comment on field. |
type ConfigProvider interface {
GetConfig() config.Config
}
EventMetaDefault
EventMetaDefault is a standard embedded struct to be used with custom event metadata types, gives an interface for easily extending event metadata objects
| Field name | Field type | Comment |
|---|---|---|
| Message |
|
No comment on field. |
| OriginatingRequest |
|
No comment on field. |
type EventMetaDefault struct {
Message string
OriginatingRequest string
}
Gateway
Gateway is a collection of well defined gateway interfaces. It should only be implemented in full by gateway.Gateway, and is used for a built-time type assertion. Do not use the symbol elsewhere, use the smaller interfaces.
| Field name | Field type | Comment |
|---|---|---|
| type |
|
No comment on field. |
type Gateway interface {
ConfigProvider
PolicyProvider
ReplaceTykVariables
}
LoggerProvider
LoggerProvider returns a new *logrus.Entry for the request.
It's implemented by gateway and middleware. Middleware typically
adds the mw field with the middleware name.
| Field name | Field type | Comment |
|---|---|---|
| type |
|
No comment on field. |
type LoggerProvider interface {
Logger() *logrus.Entry
}
MergedAPI
MergedAPI combines the embeds the classic and adds the OAS API definition as a field.
| Field name | Field type | Comment |
|---|---|---|
|
No comment on field. | |
| OAS |
|
No comment on field. |
type MergedAPI struct {
*apidef.APIDefinition `json:"api_definition,inline"`
OAS *oas.OAS `json:"oas"`
}
MergedAPIList
MergedAPIList is the response body for FromDashboardService.
| Field name | Field type | Comment |
|---|---|---|
| Message |
|
No comment on field. |
| Nonce |
|
No comment on field. |
type MergedAPIList struct {
Message []MergedAPI
Nonce string
}
Middleware
Middleware is a subset of the gateway.Middleware interface, that can be implemented outside of gateway scope.
| Field name | Field type | Comment |
|---|---|---|
| type |
|
No comment on field. |
type Middleware interface {
Init()
Name() string
Logger() *logrus.Entry
ProcessRequest(w http.ResponseWriter, r *http.Request, conf interface{}) (error, int) // Handles request
EnabledForSpec() bool
Unload()
}
MockUpstreamAuthProvider
MockUpstreamAuthProvider is a mock implementation of UpstreamAuthProvider.
type MockUpstreamAuthProvider struct{}
PolicyProvider
PolicyProvider is a storage interface encapsulating policy retrieval.
| Field name | Field type | Comment |
|---|---|---|
| type |
|
No comment on field. |
type PolicyProvider interface {
PolicyCount() int
PolicyIDs() []string
PolicyByID(string) (user.Policy, bool)
}
UpstreamAuthProvider
UpstreamAuthProvider is an interface that can fill in upstream authentication details to the request.
| Field name | Field type | Comment |
|---|---|---|
| type |
|
No comment on field. |
type UpstreamAuthProvider interface {
Fill(r *http.Request)
}
GroupLoginRequest, GroupKeySpaceRequest, DefRequest, InboundData, KeysValuesPair
This type doesn't have documentation.
| Field name | Field type | Comment |
|---|---|---|
| type |
|
No comment on field. |
| type |
|
No comment on field. |
| type |
|
No comment on field. |
| type |
|
No comment on field. |
| type |
|
No comment on field. |
type (
GroupLoginRequest = apidef.GroupLoginRequest
GroupKeySpaceRequest = apidef.GroupKeySpaceRequest
DefRequest = apidef.DefRequest
InboundData = apidef.InboundData
KeysValuesPair = apidef.KeysValuesPair
)
HealthCheckItem, HealthCheckResponse, HealthCheckStatus, HostDetails, NodeData, GWStats
This type doesn't have documentation.
| Field name | Field type | Comment |
|---|---|---|
| type |
|
No comment on field. |
| type |
|
No comment on field. |
| type |
|
No comment on field. |
| type |
|
No comment on field. |
| type |
|
No comment on field. |
| type |
|
No comment on field. |
type (
HealthCheckItem = apidef.HealthCheckItem
HealthCheckResponse = apidef.HealthCheckResponse
HealthCheckStatus = apidef.HealthCheckStatus
HostDetails = apidef.HostDetails
NodeData = apidef.NodeData
GWStats = apidef.GWStats
)
ReplaceTykVariables, StripListenPath, StripListenPathFunc
This type doesn't have documentation.
| Field name | Field type | Comment |
|---|---|---|
| type |
|
No comment on field. |
| type |
|
No comment on field. |
| type |
|
No comment on field. |
type (
// ReplaceTykVariables is a request-based template replacement hook.
// Implemented by gateway.Gateway.
ReplaceTykVariables interface {
ReplaceTykVariables(r *http.Request, in string, escape bool) string
}
// StripListenPath is the interface implemented by APISpec.StripListenPath.
StripListenPath interface {
StripListenPath(string) string
}
// StripListenPathFunc is the function signature for StripListenPath.
StripListenPathFunc func(string) string
)
Functions
func NewEventMetaDefault
NewEventMetaDefault creates an instance of model.EventMetaDefault.
func NewEventMetaDefault(r *http.Request, message string) EventMetaDefault {
return EventMetaDefault{
Message: message,
OriginatingRequest: event.EncodeRequestToEvent(r),
}
}
Cognitive complexity: 1, Cyclomatic complexity: 1
func NewMergedAPIList
func NewMergedAPIList(apis ...MergedAPI) *MergedAPIList {
return &MergedAPIList{
Message: apis,
}
}
Cognitive complexity: 1, Cyclomatic complexity: 1
func (*MergedAPI) LogFields
Logger returns API detail fields for logging.
func (m *MergedAPI) LogFields() logrus.Fields {
return logrus.Fields{
"api_id": m.APIID,
"org_id": m.OrgID,
"name": m.Name,
"path": m.Proxy.ListenPath,
}
}
Cognitive complexity: 1, Cyclomatic complexity: 1
func (*MergedAPIList) Filter
Filter, if enabled=true, will filter the internal api definitions by their tags.
func (f *MergedAPIList) Filter(enabled bool, tags ...string) []MergedAPI {
if !enabled {
return f.Message
}
if len(tags) == 0 {
return nil
}
tagMap := map[string]bool{}
for _, tag := range tags {
tagMap[tag] = true
}
result := make([]MergedAPI, 0, len(f.Message))
for _, v := range f.Message {
if v.TagsDisabled {
continue
}
for _, tag := range v.Tags {
if ok := tagMap[tag]; ok {
result = append(result, MergedAPI{v.APIDefinition, v.OAS})
break
}
}
}
return result
}
Cognitive complexity: 19, Cyclomatic complexity: 8
func (*MergedAPIList) SetClassic
Set sets the available classic API definitions to the MergedAPIList.
func (f *MergedAPIList) SetClassic(defs []*apidef.APIDefinition) {
for _, def := range defs {
f.Message = append(f.Message, MergedAPI{APIDefinition: def})
}
}
Cognitive complexity: 4, Cyclomatic complexity: 2
func (*MockUpstreamAuthProvider) Fill
Fill is a mock implementation to be used in tests.
func (m *MockUpstreamAuthProvider) Fill(_ *http.Request) {
// empty mock implementation.
}
Cognitive complexity: 0, Cyclomatic complexity: 1