-
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-13155] Ensure BaseMiddleware is a middleware scoped copy #6094
base: master
Are you sure you want to change the base?
Conversation
PR Description updated to latest commit (fe5c542) |
API Changes --- prev.txt 2024-10-10 19:26:33.517998358 +0000
+++ current.txt 2024-10-10 19:26:27.340986306 +0000
@@ -7835,7 +7835,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").
@@ -8079,7 +8079,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
@@ -8093,7 +8093,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
@@ -8105,7 +8105,7 @@
type BaseExtractor struct {
Config *apidef.MiddlewareIdExtractor
IDExtractorConfig apidef.IDExtractorConfig
- *BaseMiddleware
+ BaseMiddleware
Spec *APISpec
}
@@ -8200,7 +8200,7 @@
func (b *BaseTykResponseHandler) Name() string
type BasicAuthKeyIsValid struct {
- *BaseMiddleware
+ BaseMiddleware
// Has unexported fields.
}
@@ -8279,7 +8279,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
@@ -8315,7 +8315,7 @@
}
type CoProcessMiddleware struct {
- *BaseMiddleware
+ BaseMiddleware
HookType coprocess.HookType
HookName string
@@ -8481,7 +8481,7 @@
func (d *DummyProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type DynamicMiddleware struct {
- *BaseMiddleware
+ BaseMiddleware
MiddlewareClassName string
Pre bool
@@ -8608,7 +8608,7 @@
}
type ExternalOAuthMiddleware struct {
- *BaseMiddleware
+ BaseMiddleware
}
func (k *ExternalOAuthMiddleware) EnabledForSpec() bool
@@ -8839,7 +8839,7 @@
}
type GoPluginMiddleware struct {
- *BaseMiddleware
+ BaseMiddleware
Path string // path to .so file
SymbolName string // function symbol to look up
@@ -8865,7 +8865,7 @@
GranularAccessFailReasonValidationError
)
type GranularAccessMiddleware struct {
- *BaseMiddleware
+ BaseMiddleware
}
GranularAccessMiddleware will check if a URL is specifically enabled for the
key
@@ -8877,7 +8877,7 @@
system, return an error to have the chain fail
type GraphQLComplexityMiddleware struct {
- *BaseMiddleware
+ BaseMiddleware
}
func (m *GraphQLComplexityMiddleware) EnabledForSpec() bool
@@ -8889,7 +8889,7 @@
system, return an error to have the chain fail
type GraphQLGranularAccessMiddleware struct {
- *BaseMiddleware
+ BaseMiddleware
}
func (m *GraphQLGranularAccessMiddleware) EnabledForSpec() bool
@@ -8901,7 +8901,7 @@
system, return an error to have the chain fail
type GraphQLMiddleware struct {
- *BaseMiddleware
+ BaseMiddleware
}
func (m *GraphQLMiddleware) EnabledForSpec() bool
@@ -8988,7 +8988,7 @@
func (h *HTTPDashboardHandler) StopBeating()
type HTTPSignatureValidationMiddleware struct {
- *BaseMiddleware
+ BaseMiddleware
// Has unexported fields.
}
@@ -9181,7 +9181,7 @@
func (h *HostUptimeChecker) Stop()
type IPBlackListMiddleware struct {
- *BaseMiddleware
+ BaseMiddleware
}
IPBlackListMiddleware lets you define a list of IPs to block from upstream
@@ -9194,7 +9194,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
@@ -9275,7 +9275,7 @@
}
type JWTMiddleware struct {
- *BaseMiddleware
+ BaseMiddleware
}
func (k *JWTMiddleware) EnabledForSpec() bool
@@ -9285,7 +9285,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.
@@ -9395,7 +9395,7 @@
func (m MethodNotAllowedHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type MiddlewareContextVars struct {
- *BaseMiddleware
+ BaseMiddleware
}
func (m *MiddlewareContextVars) EnabledForSpec() bool
@@ -9590,7 +9590,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
@@ -9604,7 +9604,7 @@
system, return an error to have the chain fail
type OpenIDMW struct {
- *BaseMiddleware
+ BaseMiddleware
// Has unexported fields.
}
@@ -9624,7 +9624,7 @@
}
type OrganizationMonitor struct {
- *BaseMiddleware
+ BaseMiddleware
// Has unexported fields.
}
@@ -9654,7 +9654,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
@@ -9846,7 +9846,7 @@
func (r *RPCStorageHandler) StartRPCLoopCheck(orgId string)
type RateCheckMW struct {
- *BaseMiddleware
+ BaseMiddleware
}
func (m *RateCheckMW) Name() string
@@ -9854,7 +9854,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
@@ -9869,7 +9869,7 @@
system, return an error to have the chain fail
type RateLimitForAPI struct {
- *BaseMiddleware
+ BaseMiddleware
// Has unexported fields.
}
@@ -9913,7 +9913,7 @@
Stop stops the analytics processing
type RedisCacheMiddleware struct {
- *BaseMiddleware
+ BaseMiddleware
// Has unexported fields.
}
@@ -10103,7 +10103,7 @@
RequestObject is marshalled to JSON string and passed into JSON middleware
type RequestSigning struct {
- *BaseMiddleware
+ BaseMiddleware
}
func (s *RequestSigning) EnabledForSpec() bool
@@ -10113,7 +10113,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
@@ -10453,7 +10453,7 @@
StreamManager is responsible for creating a single stream
type StreamingMiddleware struct {
- *BaseMiddleware
+ BaseMiddleware
// Has unexported fields.
}
@@ -10483,7 +10483,7 @@
StreamsConfig represents a stream configuration
type StripAuth struct {
- *BaseMiddleware
+ BaseMiddleware
}
func (sa *StripAuth) EnabledForSpec() bool
@@ -10600,7 +10600,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.
@@ -10614,7 +10614,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
@@ -10628,7 +10628,7 @@
system, return an error to have the chain fail
type TransformJQMiddleware struct {
- *BaseMiddleware
+ BaseMiddleware
}
func (t *TransformJQMiddleware) EnabledForSpec() bool
@@ -10644,7 +10644,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
@@ -10658,7 +10658,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
@@ -10745,7 +10745,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
@@ -10833,7 +10833,7 @@
a proxy request
type UpstreamBasicAuth struct {
- *BaseMiddleware
+ BaseMiddleware
}
UpstreamBasicAuth is a middleware that will do basic authentication for
upstream connections. UpstreamBasicAuth middleware is only supported in Tyk
@@ -10892,7 +10892,7 @@
}
type ValidateJSON struct {
- *BaseMiddleware
+ BaseMiddleware
}
func (k *ValidateJSON) EnabledForSpec() bool
@@ -10904,7 +10904,7 @@
system, return an error to have the chain fail
type ValidateRequest struct {
- *BaseMiddleware
+ BaseMiddleware
}
func (k *ValidateRequest) EnabledForSpec() bool
@@ -10924,7 +10924,7 @@
func (e *ValueExtractor) ExtractAndCheck(r *http.Request) (sessionID string, returnOverrides ReturnOverrides)
type VersionCheck struct {
- *BaseMiddleware
+ BaseMiddleware
// Has unexported fields.
}
@@ -10964,7 +10964,7 @@
func (h *VersionsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type VirtualEndpoint struct {
- *BaseMiddleware
+ BaseMiddleware
// Has unexported fields.
} |
PR Review
Code feedback:
✨ Review tool usage guide:Overview:
With a configuration file, use the following template:
See the review usage page for a comprehensive guide on using this tool. |
PR Code Suggestions
✨ Improve tool usage guide:Overview:
With a configuration file, use the following template:
See the improve usage page for a more comprehensive guide on using this tool. |
fe5c542
to
468ba07
Compare
💥 CI tests failed 🙈git-stateall ok Please look at the run or in the Checks tab. |
Quality Gate passedIssues Measures |
API tests result - postgres15-sha256 env: success ✅ |
API tests result - mongo44-sha256 env: success ✅ |
With this change we do not modify t.logger, which means that when logger used outside of BaseMiddleware call, e.g. inside middleware like MWRewrite or similar, that logger will not contain MW name in its context. |
@buger yep, there are a few options:
I'd have a preference to fix for correctness and safety, meaning pass along the values explicitly or in a way so they can remain request scoped (meaning, context value, idealy on stack). Would you consider a context logger (less explicit)? Rationale:
|
6f36c25
to
f6a525d
Compare
f6a525d
to
11a5f65
Compare
💔 The detected issue is not in one of the allowed statuses 💔
Please ensure your jira story is in one of the allowed statuses |
💔 The detected issue is not in one of the allowed statuses 💔
Please ensure your jira story is in one of the allowed statuses |
This PR reverts #5914 for the most part.
It covers BaseMiddleware decisions/requirements in docs/arch/middleware.md
https://tyktech.atlassian.net/browse/TT-13155