-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TT-10881] Make BaseMiddleware a pointer #5914
Conversation
Apply Sweep Rules to your PR?
|
API Changes --- prev.txt 2023-12-29 13:30:37.413646418 +0000
+++ current.txt 2023-12-29 13:30:34.661653445 +0000
@@ -6560,7 +6560,7 @@
func CoProcessLog(CMessage, CLogLevel *C.char)
CoProcessLog is a bridge for using Tyk log from CP.
-func CreateCoProcessMiddleware(hookName string, hookType coprocess.HookType, mwDriver apidef.MiddlewareDriver, baseMid BaseMiddleware) func(http.Handler) http.Handler
+func CreateCoProcessMiddleware(hookName string, hookType coprocess.HookType, mwDriver apidef.MiddlewareDriver, baseMid *BaseMiddleware) func(http.Handler) http.Handler
CreateCoProcessMiddleware initializes a new CP middleware, takes hook type
(pre, post, etc.), hook name ("my_hook") and driver ("python").
@@ -6798,7 +6798,7 @@
where it is stored in the request (currently only "header" is supported)
type AccessRightsCheck struct {
- BaseMiddleware
+ *BaseMiddleware
}
AccessRightsCheck is a middleware that will check if the key bing used
to access the API has permission to access the specific version. If no
@@ -6812,7 +6812,7 @@
system, return an error to have the chain fail
type AuthKey struct {
- BaseMiddleware
+ *BaseMiddleware
}
KeyExists will check if the key being used to access the API is in the
request data, and then if the key is in the storage engine
@@ -6824,7 +6824,8 @@
type BaseExtractor struct {
Config *apidef.MiddlewareIdExtractor
IDExtractorConfig apidef.IDExtractorConfig
- BaseMiddleware
+ *BaseMiddleware
+
Spec *APISpec
}
BaseExtractor is the base structure for an ID extractor, it implements the
@@ -6847,7 +6848,7 @@
func (e *BaseExtractor) ExtractHeader(r *http.Request) (headerValue string, err error)
ExtractHeader is used when a HeaderSource is specified.
-func (e *BaseExtractor) GenerateSessionID(input string, mw BaseMiddleware) (sessionID string)
+func (e *BaseExtractor) GenerateSessionID(input string, mw *BaseMiddleware) (sessionID string)
GenerateSessionID is a helper for generating session IDs, it takes an input
(usually the extractor output) and a middleware pointer.
@@ -6861,40 +6862,40 @@
BaseMiddleware wraps up the ApiSpec and Proxy objects to be included in a
middleware handler, this can probably be handled better.
-func (t BaseMiddleware) ApplyPolicies(session *user.SessionState) error
+func (t *BaseMiddleware) ApplyPolicies(session *user.SessionState) error
ApplyPolicies will check if any policies are loaded. If any are, it will
overwrite the session state to use the policy values.
func (t *BaseMiddleware) Base() *BaseMiddleware
-func (t BaseMiddleware) CheckSessionAndIdentityForValidKey(originalKey string, r *http.Request) (user.SessionState, bool)
+func (t *BaseMiddleware) CheckSessionAndIdentityForValidKey(originalKey string, r *http.Request) (user.SessionState, bool)
CheckSessionAndIdentityForValidKey will check first the Session store for a
valid key, if not found, it will try the Auth Handler, if not found it will
fail
-func (t BaseMiddleware) Config() (interface{}, error)
+func (t *BaseMiddleware) Config() (interface{}, error)
-func (t BaseMiddleware) EnabledForSpec() bool
+func (t *BaseMiddleware) EnabledForSpec() bool
-func (t BaseMiddleware) FireEvent(name apidef.TykEvent, meta interface{})
+func (t *BaseMiddleware) FireEvent(name apidef.TykEvent, meta interface{})
FireEvent is added to the BaseMiddleware object so it is available across
the entire stack
-func (t BaseMiddleware) Init()
+func (t *BaseMiddleware) Init()
func (t *BaseMiddleware) Logger() (logger *logrus.Entry)
-func (t BaseMiddleware) OrgSession(orgID string) (user.SessionState, bool)
+func (t *BaseMiddleware) OrgSession(orgID string) (user.SessionState, bool)
-func (t BaseMiddleware) OrgSessionExpiry(orgid string) int64
+func (t *BaseMiddleware) OrgSessionExpiry(orgid string) int64
func (t *BaseMiddleware) SetName(name string)
-func (t BaseMiddleware) SetOrgExpiry(orgid string, expiry int64)
+func (t *BaseMiddleware) SetOrgExpiry(orgid string, expiry int64)
func (t *BaseMiddleware) SetRequestLogger(r *http.Request)
-func (t BaseMiddleware) UpdateRequestSession(r *http.Request) bool
+func (t *BaseMiddleware) UpdateRequestSession(r *http.Request) bool
type BaseTykResponseHandler struct {
Spec *APISpec `json:"-"`
@@ -6912,7 +6913,7 @@
func (b *BaseTykResponseHandler) Name() string
type BasicAuthKeyIsValid struct {
- BaseMiddleware
+ *BaseMiddleware
// Has unexported fields.
}
@@ -6991,7 +6992,7 @@
BundleSaver is an interface used by bundle saver structures.
type CertificateCheckMW struct {
- BaseMiddleware
+ *BaseMiddleware
}
CertificateCheckMW is used if domain was not detected or multiple APIs bind
on the same domain. In this case authentification check happens not on TLS
@@ -7027,7 +7028,8 @@
}
type CoProcessMiddleware struct {
- BaseMiddleware
+ *BaseMiddleware
+
HookType coprocess.HookType
HookName string
MiddlewareDriver apidef.MiddlewareDriver
@@ -7189,7 +7191,8 @@
func (d *DummyProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type DynamicMiddleware struct {
- BaseMiddleware
+ *BaseMiddleware
+
MiddlewareClassName string
Pre bool
UseSession bool
@@ -7212,7 +7215,7 @@
}
type ErrorHandler struct {
- BaseMiddleware
+ *BaseMiddleware
}
ErrorHandler is invoked whenever there is an issue with a proxied request,
most middleware will invoke the ErrorHandler if something is wrong with the
@@ -7315,7 +7318,7 @@
}
type ExternalOAuthMiddleware struct {
- BaseMiddleware
+ *BaseMiddleware
}
func (k *ExternalOAuthMiddleware) EnabledForSpec() bool
@@ -7518,7 +7521,8 @@
}
type GoPluginMiddleware struct {
- BaseMiddleware
+ *BaseMiddleware
+
Path string // path to .so file
SymbolName string // function symbol to look up
@@ -7543,7 +7547,7 @@
GranularAccessFailReasonValidationError
)
type GranularAccessMiddleware struct {
- BaseMiddleware
+ *BaseMiddleware
}
GranularAccessMiddleware will check if a URL is specifically enabled for the
key
@@ -7555,7 +7559,7 @@
system, return an error to have the chain fail
type GraphQLComplexityMiddleware struct {
- BaseMiddleware
+ *BaseMiddleware
}
func (m *GraphQLComplexityMiddleware) EnabledForSpec() bool
@@ -7583,7 +7587,7 @@
func DetermineGraphQLEngineTransportType(apiSpec *APISpec) GraphQLEngineTransportType
type GraphQLGranularAccessMiddleware struct {
- BaseMiddleware
+ *BaseMiddleware
}
func (m *GraphQLGranularAccessMiddleware) EnabledForSpec() bool
@@ -7595,7 +7599,7 @@
system, return an error to have the chain fail
type GraphQLMiddleware struct {
- BaseMiddleware
+ *BaseMiddleware
}
func (m *GraphQLMiddleware) EnabledForSpec() bool
@@ -7694,7 +7698,8 @@
func (h *HTTPDashboardHandler) StopBeating()
type HTTPSignatureValidationMiddleware struct {
- BaseMiddleware
+ *BaseMiddleware
+
// Has unexported fields.
}
HTTPSignatureValidationMiddleware will check if the request has a signature,
@@ -7880,7 +7885,7 @@
func (h *HostUptimeChecker) Stop()
type IPBlackListMiddleware struct {
- BaseMiddleware
+ *BaseMiddleware
}
IPBlackListMiddleware lets you define a list of IPs to block from upstream
@@ -7893,7 +7898,7 @@
system, return an error to have the chain fail
type IPWhiteListMiddleware struct {
- BaseMiddleware
+ *BaseMiddleware
}
IPWhiteListMiddleware lets you define a list of IPs to allow upstream
@@ -7907,7 +7912,7 @@
type IdExtractor interface {
ExtractAndCheck(*http.Request) (string, ReturnOverrides)
- GenerateSessionID(string, BaseMiddleware) string
+ GenerateSessionID(string, *BaseMiddleware) string
}
IdExtractor is the base interface for an ID extractor.
@@ -7974,7 +7979,7 @@
}
type JWTMiddleware struct {
- BaseMiddleware
+ *BaseMiddleware
}
func (k *JWTMiddleware) EnabledForSpec() bool
@@ -7984,7 +7989,7 @@
func (k *JWTMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Request, _ interface{}) (error, int)
type KeyExpired struct {
- BaseMiddleware
+ *BaseMiddleware
}
KeyExpired middleware will check if the requesting key is expired or not.
It makes use of the authManager to do so.
@@ -8092,7 +8097,7 @@
func (m MethodNotAllowedHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type MiddlewareContextVars struct {
- BaseMiddleware
+ *BaseMiddleware
}
func (m *MiddlewareContextVars) EnabledForSpec() bool
@@ -8292,7 +8297,7 @@
OAuthNotificationType const to reduce risk of collisions
type Oauth2KeyExists struct {
- BaseMiddleware
+ *BaseMiddleware
}
Oauth2KeyExists will check if the key being used to access the API is in the
request data, and then if the key is in the storage engine
@@ -8306,7 +8311,7 @@
system, return an error to have the chain fail
type OpenIDMW struct {
- BaseMiddleware
+ *BaseMiddleware
// Has unexported fields.
}
@@ -8326,7 +8331,7 @@
}
type OrganizationMonitor struct {
- BaseMiddleware
+ *BaseMiddleware
// Has unexported fields.
}
@@ -8356,7 +8361,7 @@
func (k *OrganizationMonitor) SetOrgSentinel(orgChan chan bool, orgId string)
type PersistGraphQLOperationMiddleware struct {
- BaseMiddleware
+ *BaseMiddleware
}
PersistGraphQLOperationMiddleware lets you convert any HTTP request into a
GraphQL Operation
@@ -8546,7 +8551,7 @@
func (r *RPCStorageHandler) StartRPCLoopCheck(orgId string)
type RateCheckMW struct {
- BaseMiddleware
+ *BaseMiddleware
}
func (m *RateCheckMW) Name() string
@@ -8554,7 +8559,7 @@
func (m *RateCheckMW) ProcessRequest(w http.ResponseWriter, r *http.Request, _ interface{}) (error, int)
type RateLimitAndQuotaCheck struct {
- BaseMiddleware
+ *BaseMiddleware
}
RateLimitAndQuotaCheck will check the incomming request and key whether
it is within it's quota and within it's rate limit, it makes use of the
@@ -8569,7 +8574,7 @@
system, return an error to have the chain fail
type RateLimitForAPI struct {
- BaseMiddleware
+ *BaseMiddleware
// Has unexported fields.
}
@@ -8613,7 +8618,7 @@
Stop stops the analytics processing
type RedisCacheMiddleware struct {
- BaseMiddleware
+ *BaseMiddleware
// Has unexported fields.
}
@@ -8798,7 +8803,7 @@
RequestObject is marshalled to JSON string and passed into JSON middleware
type RequestSigning struct {
- BaseMiddleware
+ *BaseMiddleware
}
func (s *RequestSigning) EnabledForSpec() bool
@@ -8808,7 +8813,7 @@
func (s *RequestSigning) ProcessRequest(w http.ResponseWriter, r *http.Request, _ interface{}) (error, int)
type RequestSizeLimitMiddleware struct {
- BaseMiddleware
+ *BaseMiddleware
}
RequestSizeLimitMiddleware is a middleware that will enforce a limit on the
request body size. The request has already been copied to memory when this
@@ -9125,7 +9130,7 @@
type StatsDSinkSanitizationFunc func(*bytes.Buffer, string)
type StripAuth struct {
- BaseMiddleware
+ *BaseMiddleware
}
func (sa *StripAuth) EnabledForSpec() bool
@@ -9135,7 +9140,7 @@
func (sa *StripAuth) ProcessRequest(w http.ResponseWriter, r *http.Request, _ interface{}) (error, int)
type SuccessHandler struct {
- BaseMiddleware
+ *BaseMiddleware
}
SuccessHandler represents the final ServeHTTP() request for a proxied API
request
@@ -9242,7 +9247,7 @@
func (tr TraceMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Request, conf interface{}) (error, int)
type TrackEndpointMiddleware struct {
- BaseMiddleware
+ *BaseMiddleware
}
TrackEndpointMiddleware sets context variables to enable or disable whether
Tyk should record analytitcs for a specific path.
@@ -9256,7 +9261,7 @@
system, return an error to have the chain fail
type TransformHeaders struct {
- BaseMiddleware
+ *BaseMiddleware
}
TransformMiddleware is a middleware that will apply a template to a request
body to transform it's contents ready for an upstream API
@@ -9270,7 +9275,7 @@
system, return an error to have the chain fail
type TransformJQMiddleware struct {
- BaseMiddleware
+ *BaseMiddleware
}
func (t *TransformJQMiddleware) EnabledForSpec() bool
@@ -9286,7 +9291,7 @@
}
type TransformMethod struct {
- BaseMiddleware
+ *BaseMiddleware
}
TransformMiddleware is a middleware that will apply a template to a request
body to transform it's contents ready for an upstream API
@@ -9300,7 +9305,7 @@
system, return an error to have the chain fail
type TransformMiddleware struct {
- BaseMiddleware
+ *BaseMiddleware
}
TransformMiddleware is a middleware that will apply a template to a request
body to transform it's contents ready for an upstream API
@@ -9346,6 +9351,7 @@
type TykMiddleware interface {
Init()
Base() *BaseMiddleware
+
SetName(string)
SetRequestLogger(*http.Request)
Logger() *logrus.Entry
@@ -9382,7 +9388,7 @@
func (rt *TykRoundTripper) RoundTrip(r *http.Request) (*http.Response, error)
type URLRewriteMiddleware struct {
- BaseMiddleware
+ *BaseMiddleware
}
URLRewriteMiddleware Will rewrite an inbund URL to a matching outbound one,
it can also handle dynamic variable substitution
@@ -9496,7 +9502,7 @@
}
type ValidateJSON struct {
- BaseMiddleware
+ *BaseMiddleware
}
func (k *ValidateJSON) EnabledForSpec() bool
@@ -9508,7 +9514,7 @@
system, return an error to have the chain fail
type ValidateRequest struct {
- BaseMiddleware
+ *BaseMiddleware
}
func (k *ValidateRequest) EnabledForSpec() bool
@@ -9528,7 +9534,8 @@
func (e *ValueExtractor) ExtractAndCheck(r *http.Request) (sessionID string, returnOverrides ReturnOverrides)
type VersionCheck struct {
- BaseMiddleware
+ *BaseMiddleware
+
// Has unexported fields.
}
VersionCheck will check whether the version of the requested API the request
@@ -9567,7 +9574,8 @@
func (h *VersionsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type VirtualEndpoint struct {
- BaseMiddleware
+ *BaseMiddleware
+
// Has unexported fields.
}
DynamicMiddleware is a generic middleware that will execute JS code before |
PR Analysis
PR Feedback💡 General suggestions: The PR is well-structured and the changes are consistent across all files. However, it would be beneficial to add tests to ensure that the change from a value to a pointer for BaseMiddleware doesn't introduce any unexpected behavior or bugs. 🤖 Code feedback:
✨ Usage tips:
|
API tests result - postgres15-murmur64 env: success ✅ This resolves vet warnings about copying a mutex value. Before: 189 warnings,
https://tyktech.atlassian.net/browse/TT-10881 Co-authored-by: Tit Petric tit@tyk.io |
API tests result - mongo44-sha256 env: success ✅ This resolves vet warnings about copying a mutex value. Before: 189 warnings,
https://tyktech.atlassian.net/browse/TT-10881 Co-authored-by: Tit Petric tit@tyk.io |
API tests result - postgres15-sha256 env: success ✅ This resolves vet warnings about copying a mutex value. Before: 189 warnings,
https://tyktech.atlassian.net/browse/TT-10881 Co-authored-by: Tit Petric tit@tyk.io |
💥 CI tests failed 🙈git-stateall ok Please look at the run or in the Checks tab. |
API tests result - mongo44-murmur64 env: success ✅ This resolves vet warnings about copying a mutex value. Before: 189 warnings,
https://tyktech.atlassian.net/browse/TT-10881 Co-authored-by: Tit Petric tit@tyk.io |
💥 CI tests failed 🙈git-stateall ok Please look at the run or in the Checks tab. |
@@ -46,6 +46,7 @@ var ( | |||
type TykMiddleware interface { | |||
Init() | |||
Base() *BaseMiddleware | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary line break?
5867d8d
to
96c26cf
Compare
Quality Gate failedFailed conditions 70.6% Coverage on New Code (required ≥ 80%) See analysis details on SonarCloud Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
This resolves vet warnings about copying a mutex value.
Before: 189 warnings,
After: 7 warnings
https://tyktech.atlassian.net/browse/TT-10881