Skip to content

Commit dfd9dfc

Browse files
mvdanbuger
authored andcommitted
mw: rename TykMiddleware to BaseMiddleware
Because that's what it is - it's the base on top of which all middlewares are built. And rename TykMiddlewareImplementation, the interface, to TykMiddleware. While at it, also give some variables better and shorter names.
1 parent 8605331 commit dfd9dfc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+222
-222
lines changed

api_loader.go

+59-59
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ func processSpec(referenceSpec *APISpec,
264264
// Create the response processors
265265
creeateResponseMiddlewareChain(referenceSpec)
266266

267-
tykMiddleware := &TykMiddleware{referenceSpec, proxy}
268-
CheckCBEnabled(tykMiddleware)
269-
CheckETEnabled(tykMiddleware)
267+
baseMid := &BaseMiddleware{referenceSpec, proxy}
268+
CheckCBEnabled(baseMid)
269+
CheckETEnabled(baseMid)
270270

271271
keyPrefix := "cache-" + referenceSpec.APIID
272272
cacheStore := &RedisClusterStorageManager{KeyPrefix: keyPrefix, IsCache: true}
@@ -286,19 +286,19 @@ func processSpec(referenceSpec *APISpec,
286286
handleCORS(&chainArray, referenceSpec)
287287

288288
baseChainArray := []alice.Constructor{}
289-
AppendMiddleware(&baseChainArray, &RateCheckMW{TykMiddleware: tykMiddleware}, tykMiddleware)
290-
AppendMiddleware(&baseChainArray, &IPWhiteListMiddleware{TykMiddleware: tykMiddleware}, tykMiddleware)
291-
AppendMiddleware(&baseChainArray, &OrganizationMonitor{TykMiddleware: tykMiddleware}, tykMiddleware)
292-
AppendMiddleware(&baseChainArray, &MiddlewareContextVars{TykMiddleware: tykMiddleware}, tykMiddleware)
293-
AppendMiddleware(&baseChainArray, &VersionCheck{TykMiddleware: tykMiddleware}, tykMiddleware)
294-
AppendMiddleware(&baseChainArray, &RequestSizeLimitMiddleware{tykMiddleware}, tykMiddleware)
295-
AppendMiddleware(&baseChainArray, &TrackEndpointMiddleware{tykMiddleware}, tykMiddleware)
296-
AppendMiddleware(&baseChainArray, &TransformMiddleware{tykMiddleware}, tykMiddleware)
297-
AppendMiddleware(&baseChainArray, &TransformHeaders{TykMiddleware: tykMiddleware}, tykMiddleware)
298-
AppendMiddleware(&baseChainArray, &RedisCacheMiddleware{TykMiddleware: tykMiddleware, CacheStore: cacheStore}, tykMiddleware)
299-
AppendMiddleware(&baseChainArray, &VirtualEndpoint{TykMiddleware: tykMiddleware}, tykMiddleware)
300-
AppendMiddleware(&baseChainArray, &URLRewriteMiddleware{TykMiddleware: tykMiddleware}, tykMiddleware)
301-
AppendMiddleware(&baseChainArray, &TransformMethod{TykMiddleware: tykMiddleware}, tykMiddleware)
289+
AppendMiddleware(&baseChainArray, &RateCheckMW{BaseMiddleware: baseMid}, baseMid)
290+
AppendMiddleware(&baseChainArray, &IPWhiteListMiddleware{BaseMiddleware: baseMid}, baseMid)
291+
AppendMiddleware(&baseChainArray, &OrganizationMonitor{BaseMiddleware: baseMid}, baseMid)
292+
AppendMiddleware(&baseChainArray, &MiddlewareContextVars{BaseMiddleware: baseMid}, baseMid)
293+
AppendMiddleware(&baseChainArray, &VersionCheck{BaseMiddleware: baseMid}, baseMid)
294+
AppendMiddleware(&baseChainArray, &RequestSizeLimitMiddleware{baseMid}, baseMid)
295+
AppendMiddleware(&baseChainArray, &TrackEndpointMiddleware{baseMid}, baseMid)
296+
AppendMiddleware(&baseChainArray, &TransformMiddleware{baseMid}, baseMid)
297+
AppendMiddleware(&baseChainArray, &TransformHeaders{BaseMiddleware: baseMid}, baseMid)
298+
AppendMiddleware(&baseChainArray, &RedisCacheMiddleware{BaseMiddleware: baseMid, CacheStore: cacheStore}, baseMid)
299+
AppendMiddleware(&baseChainArray, &VirtualEndpoint{BaseMiddleware: baseMid}, baseMid)
300+
AppendMiddleware(&baseChainArray, &URLRewriteMiddleware{BaseMiddleware: baseMid}, baseMid)
301+
AppendMiddleware(&baseChainArray, &TransformMethod{BaseMiddleware: baseMid}, baseMid)
302302

303303
log.Debug(referenceSpec.Name, " - CHAIN SIZE: ", len(baseChainArray))
304304

@@ -308,9 +308,9 @@ func processSpec(referenceSpec *APISpec,
308308
"prefix": "coprocess",
309309
"api_name": referenceSpec.Name,
310310
}).Debug("Registering coprocess middleware, hook name: ", obj.Name, "hook type: Pre", ", driver: ", mwDriver)
311-
AppendMiddleware(&chainArray, &CoProcessMiddleware{tykMiddleware, coprocess.HookType_Pre, obj.Name, mwDriver}, tykMiddleware)
311+
AppendMiddleware(&chainArray, &CoProcessMiddleware{baseMid, coprocess.HookType_Pre, obj.Name, mwDriver}, baseMid)
312312
} else {
313-
chainArray = append(chainArray, CreateDynamicMiddleware(obj.Name, true, obj.RequireSession, tykMiddleware))
313+
chainArray = append(chainArray, CreateDynamicMiddleware(obj.Name, true, obj.RequireSession, baseMid))
314314
}
315315
}
316316

@@ -322,14 +322,14 @@ func processSpec(referenceSpec *APISpec,
322322
"prefix": "coprocess",
323323
"api_name": referenceSpec.Name,
324324
}).Debug("Registering coprocess middleware, hook name: ", obj.Name, "hook type: Post", ", driver: ", mwDriver)
325-
AppendMiddleware(&chainArray, &CoProcessMiddleware{tykMiddleware, coprocess.HookType_Post, obj.Name, mwDriver}, tykMiddleware)
325+
AppendMiddleware(&chainArray, &CoProcessMiddleware{baseMid, coprocess.HookType_Post, obj.Name, mwDriver}, baseMid)
326326
} else {
327-
chainArray = append(chainArray, CreateDynamicMiddleware(obj.Name, false, obj.RequireSession, tykMiddleware))
327+
chainArray = append(chainArray, CreateDynamicMiddleware(obj.Name, false, obj.RequireSession, baseMid))
328328
}
329329
}
330330

331331
// for KeyLessAccess we can't support rate limiting, versioning or access rules
332-
chain = alice.New(chainArray...).Then(&DummyProxyHandler{SH: SuccessHandler{tykMiddleware}})
332+
chain = alice.New(chainArray...).Then(&DummyProxyHandler{SH: SuccessHandler{baseMid}})
333333

334334
} else {
335335

@@ -338,13 +338,13 @@ func processSpec(referenceSpec *APISpec,
338338
handleCORS(&chainArray, referenceSpec)
339339

340340
var baseChainArray_PreAuth []alice.Constructor
341-
AppendMiddleware(&baseChainArray_PreAuth, &RateCheckMW{TykMiddleware: tykMiddleware}, tykMiddleware)
342-
AppendMiddleware(&baseChainArray_PreAuth, &IPWhiteListMiddleware{TykMiddleware: tykMiddleware}, tykMiddleware)
343-
AppendMiddleware(&baseChainArray_PreAuth, &OrganizationMonitor{TykMiddleware: tykMiddleware}, tykMiddleware)
344-
AppendMiddleware(&baseChainArray_PreAuth, &VersionCheck{TykMiddleware: tykMiddleware}, tykMiddleware)
345-
AppendMiddleware(&baseChainArray_PreAuth, &RequestSizeLimitMiddleware{tykMiddleware}, tykMiddleware)
346-
AppendMiddleware(&baseChainArray_PreAuth, &MiddlewareContextVars{TykMiddleware: tykMiddleware}, tykMiddleware)
347-
AppendMiddleware(&baseChainArray_PreAuth, &TrackEndpointMiddleware{tykMiddleware}, tykMiddleware)
341+
AppendMiddleware(&baseChainArray_PreAuth, &RateCheckMW{BaseMiddleware: baseMid}, baseMid)
342+
AppendMiddleware(&baseChainArray_PreAuth, &IPWhiteListMiddleware{BaseMiddleware: baseMid}, baseMid)
343+
AppendMiddleware(&baseChainArray_PreAuth, &OrganizationMonitor{BaseMiddleware: baseMid}, baseMid)
344+
AppendMiddleware(&baseChainArray_PreAuth, &VersionCheck{BaseMiddleware: baseMid}, baseMid)
345+
AppendMiddleware(&baseChainArray_PreAuth, &RequestSizeLimitMiddleware{baseMid}, baseMid)
346+
AppendMiddleware(&baseChainArray_PreAuth, &MiddlewareContextVars{BaseMiddleware: baseMid}, baseMid)
347+
AppendMiddleware(&baseChainArray_PreAuth, &TrackEndpointMiddleware{baseMid}, baseMid)
348348

349349
// Add pre-process MW
350350
for _, obj := range mwPreFuncs {
@@ -353,9 +353,9 @@ func processSpec(referenceSpec *APISpec,
353353
"prefix": "coprocess",
354354
"api_name": referenceSpec.Name,
355355
}).Debug("Registering coprocess middleware, hook name: ", obj.Name, "hook type: Pre", ", driver: ", mwDriver)
356-
AppendMiddleware(&chainArray, &CoProcessMiddleware{tykMiddleware, coprocess.HookType_Pre, obj.Name, mwDriver}, tykMiddleware)
356+
AppendMiddleware(&chainArray, &CoProcessMiddleware{baseMid, coprocess.HookType_Pre, obj.Name, mwDriver}, baseMid)
357357
} else {
358-
chainArray = append(chainArray, CreateDynamicMiddleware(obj.Name, true, obj.RequireSession, tykMiddleware))
358+
chainArray = append(chainArray, CreateDynamicMiddleware(obj.Name, true, obj.RequireSession, baseMid))
359359
}
360360
}
361361

@@ -369,7 +369,7 @@ func processSpec(referenceSpec *APISpec,
369369
"prefix": "main",
370370
"api_name": referenceSpec.Name,
371371
}).Info("Checking security policy: OAuth")
372-
authArray = append(authArray, CreateMiddleware(&Oauth2KeyExists{tykMiddleware}, tykMiddleware))
372+
authArray = append(authArray, CreateMiddleware(&Oauth2KeyExists{baseMid}, baseMid))
373373

374374
}
375375

@@ -386,7 +386,7 @@ func processSpec(referenceSpec *APISpec,
386386
"prefix": "main",
387387
"api_name": referenceSpec.Name,
388388
}).Info("Checking security policy: Basic")
389-
authArray = append(authArray, CreateMiddleware(&BasicAuthKeyIsValid{tykMiddleware}, tykMiddleware))
389+
authArray = append(authArray, CreateMiddleware(&BasicAuthKeyIsValid{baseMid}, baseMid))
390390
}
391391

392392
if referenceSpec.EnableSignatureChecking {
@@ -395,7 +395,7 @@ func processSpec(referenceSpec *APISpec,
395395
"prefix": "main",
396396
"api_name": referenceSpec.Name,
397397
}).Info("Checking security policy: HMAC")
398-
authArray = append(authArray, CreateMiddleware(&HMACMiddleware{TykMiddleware: tykMiddleware}, tykMiddleware))
398+
authArray = append(authArray, CreateMiddleware(&HMACMiddleware{BaseMiddleware: baseMid}, baseMid))
399399
}
400400

401401
if referenceSpec.EnableJWT {
@@ -404,7 +404,7 @@ func processSpec(referenceSpec *APISpec,
404404
"prefix": "main",
405405
"api_name": referenceSpec.Name,
406406
}).Info("Checking security policy: JWT")
407-
authArray = append(authArray, CreateMiddleware(&JWTMiddleware{tykMiddleware}, tykMiddleware))
407+
authArray = append(authArray, CreateMiddleware(&JWTMiddleware{baseMid}, baseMid))
408408
}
409409

410410
if referenceSpec.UseOpenID {
@@ -415,7 +415,7 @@ func processSpec(referenceSpec *APISpec,
415415
}).Info("Checking security policy: OpenID")
416416

417417
// initialise the OID configuration on this reference Spec
418-
authArray = append(authArray, CreateMiddleware(&OpenIDMW{TykMiddleware: tykMiddleware}, tykMiddleware))
418+
authArray = append(authArray, CreateMiddleware(&OpenIDMW{BaseMiddleware: baseMid}, baseMid))
419419
}
420420

421421
if useCoProcessAuth {
@@ -431,8 +431,8 @@ func processSpec(referenceSpec *APISpec,
431431
}).Debug("Registering coprocess middleware, hook name: ", mwAuthCheckFunc.Name, "hook type: CustomKeyCheck", ", driver: ", mwDriver)
432432

433433
if useCoProcessAuth {
434-
newExtractor(referenceSpec, tykMiddleware)
435-
AppendMiddleware(&authArray, &CoProcessMiddleware{tykMiddleware, coprocess.HookType_CustomKeyCheck, mwAuthCheckFunc.Name, mwDriver}, tykMiddleware)
434+
newExtractor(referenceSpec, baseMid)
435+
AppendMiddleware(&authArray, &CoProcessMiddleware{baseMid, coprocess.HookType_CustomKeyCheck, mwAuthCheckFunc.Name, mwDriver}, baseMid)
436436
}
437437
}
438438

@@ -441,7 +441,7 @@ func processSpec(referenceSpec *APISpec,
441441
"prefix": "main",
442442
}).Info("----> Checking security policy: JS Plugin")
443443

444-
authArray = append(authArray, CreateDynamicAuthMiddleware(mwAuthCheckFunc.Name, tykMiddleware))
444+
authArray = append(authArray, CreateDynamicAuthMiddleware(mwAuthCheckFunc.Name, baseMid))
445445
}
446446

447447
if referenceSpec.UseStandardAuth || (!referenceSpec.UseOpenID && !referenceSpec.EnableJWT && !referenceSpec.EnableSignatureChecking && !referenceSpec.UseBasicAuth && !referenceSpec.UseOauth2 && !useCoProcessAuth && !useOttoAuth) {
@@ -450,7 +450,7 @@ func processSpec(referenceSpec *APISpec,
450450
"prefix": "main",
451451
"api_name": referenceSpec.Name,
452452
}).Info("Checking security policy: Token")
453-
authArray = append(authArray, CreateMiddleware(&AuthKey{tykMiddleware}, tykMiddleware))
453+
authArray = append(authArray, CreateMiddleware(&AuthKey{baseMid}, baseMid))
454454
}
455455

456456
chainArray = append(chainArray, authArray...)
@@ -460,20 +460,20 @@ func processSpec(referenceSpec *APISpec,
460460
"prefix": "coprocess",
461461
"api_name": referenceSpec.Name,
462462
}).Debug("Registering coprocess middleware, hook name: ", obj.Name, "hook type: Pre", ", driver: ", mwDriver)
463-
AppendMiddleware(&chainArray, &CoProcessMiddleware{tykMiddleware, coprocess.HookType_PostKeyAuth, obj.Name, mwDriver}, tykMiddleware)
463+
AppendMiddleware(&chainArray, &CoProcessMiddleware{baseMid, coprocess.HookType_PostKeyAuth, obj.Name, mwDriver}, baseMid)
464464
}
465465

466466
var baseChainArray_PostAuth []alice.Constructor
467-
AppendMiddleware(&baseChainArray_PostAuth, &KeyExpired{tykMiddleware}, tykMiddleware)
468-
AppendMiddleware(&baseChainArray_PostAuth, &AccessRightsCheck{tykMiddleware}, tykMiddleware)
469-
AppendMiddleware(&baseChainArray_PostAuth, &RateLimitAndQuotaCheck{tykMiddleware}, tykMiddleware)
470-
AppendMiddleware(&baseChainArray_PostAuth, &GranularAccessMiddleware{tykMiddleware}, tykMiddleware)
471-
AppendMiddleware(&baseChainArray_PostAuth, &TransformMiddleware{tykMiddleware}, tykMiddleware)
472-
AppendMiddleware(&baseChainArray_PostAuth, &TransformHeaders{TykMiddleware: tykMiddleware}, tykMiddleware)
473-
AppendMiddleware(&baseChainArray_PostAuth, &URLRewriteMiddleware{TykMiddleware: tykMiddleware}, tykMiddleware)
474-
AppendMiddleware(&baseChainArray_PostAuth, &RedisCacheMiddleware{TykMiddleware: tykMiddleware, CacheStore: cacheStore}, tykMiddleware)
475-
AppendMiddleware(&baseChainArray_PostAuth, &TransformMethod{TykMiddleware: tykMiddleware}, tykMiddleware)
476-
AppendMiddleware(&baseChainArray_PostAuth, &VirtualEndpoint{TykMiddleware: tykMiddleware}, tykMiddleware)
467+
AppendMiddleware(&baseChainArray_PostAuth, &KeyExpired{baseMid}, baseMid)
468+
AppendMiddleware(&baseChainArray_PostAuth, &AccessRightsCheck{baseMid}, baseMid)
469+
AppendMiddleware(&baseChainArray_PostAuth, &RateLimitAndQuotaCheck{baseMid}, baseMid)
470+
AppendMiddleware(&baseChainArray_PostAuth, &GranularAccessMiddleware{baseMid}, baseMid)
471+
AppendMiddleware(&baseChainArray_PostAuth, &TransformMiddleware{baseMid}, baseMid)
472+
AppendMiddleware(&baseChainArray_PostAuth, &TransformHeaders{BaseMiddleware: baseMid}, baseMid)
473+
AppendMiddleware(&baseChainArray_PostAuth, &URLRewriteMiddleware{BaseMiddleware: baseMid}, baseMid)
474+
AppendMiddleware(&baseChainArray_PostAuth, &RedisCacheMiddleware{BaseMiddleware: baseMid, CacheStore: cacheStore}, baseMid)
475+
AppendMiddleware(&baseChainArray_PostAuth, &TransformMethod{BaseMiddleware: baseMid}, baseMid)
476+
AppendMiddleware(&baseChainArray_PostAuth, &VirtualEndpoint{BaseMiddleware: baseMid}, baseMid)
477477

478478
chainArray = append(chainArray, baseChainArray_PostAuth...)
479479

@@ -483,9 +483,9 @@ func processSpec(referenceSpec *APISpec,
483483
"prefix": "coprocess",
484484
"api_name": referenceSpec.Name,
485485
}).Debug("Registering coprocess middleware, hook name: ", obj.Name, "hook type: Post", ", driver: ", mwDriver)
486-
AppendMiddleware(&chainArray, &CoProcessMiddleware{tykMiddleware, coprocess.HookType_Post, obj.Name, mwDriver}, tykMiddleware)
486+
AppendMiddleware(&chainArray, &CoProcessMiddleware{baseMid, coprocess.HookType_Post, obj.Name, mwDriver}, baseMid)
487487
} else {
488-
chainArray = append(chainArray, CreateDynamicMiddleware(obj.Name, false, obj.RequireSession, tykMiddleware))
488+
chainArray = append(chainArray, CreateDynamicMiddleware(obj.Name, false, obj.RequireSession, baseMid))
489489
}
490490
}
491491

@@ -494,20 +494,20 @@ func processSpec(referenceSpec *APISpec,
494494
"api_name": referenceSpec.Name,
495495
}).Debug("Custom middleware completed processing")
496496

497-
// Use CreateMiddleware(&ModifiedMiddleware{tykMiddleware}, tykMiddleware) to run custom middleware
498-
chain = alice.New(chainArray...).Then(&DummyProxyHandler{SH: SuccessHandler{tykMiddleware}})
497+
// Use CreateMiddleware(&ModifiedMiddleware{baseMid}, baseMid) to run custom middleware
498+
chain = alice.New(chainArray...).Then(&DummyProxyHandler{SH: SuccessHandler{baseMid}})
499499

500500
log.Debug("Chain completed")
501501

502502
userCheckHandler := UserRatesCheck()
503503
simpleChain_PreAuth := []alice.Constructor{
504-
CreateMiddleware(&IPWhiteListMiddleware{tykMiddleware}, tykMiddleware),
505-
CreateMiddleware(&OrganizationMonitor{TykMiddleware: tykMiddleware}, tykMiddleware),
506-
CreateMiddleware(&VersionCheck{TykMiddleware: tykMiddleware}, tykMiddleware)}
504+
CreateMiddleware(&IPWhiteListMiddleware{baseMid}, baseMid),
505+
CreateMiddleware(&OrganizationMonitor{BaseMiddleware: baseMid}, baseMid),
506+
CreateMiddleware(&VersionCheck{BaseMiddleware: baseMid}, baseMid)}
507507

508508
simpleChain_PostAuth := []alice.Constructor{
509-
CreateMiddleware(&KeyExpired{tykMiddleware}, tykMiddleware),
510-
CreateMiddleware(&AccessRightsCheck{tykMiddleware}, tykMiddleware)}
509+
CreateMiddleware(&KeyExpired{baseMid}, baseMid),
510+
CreateMiddleware(&AccessRightsCheck{baseMid}, baseMid)}
511511

512512
var fullSimpleChain []alice.Constructor
513513
fullSimpleChain = append(fullSimpleChain, simpleChain_PreAuth...)

coprocess.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var (
2424

2525
// CoProcessMiddleware is the basic CP middleware struct.
2626
type CoProcessMiddleware struct {
27-
*TykMiddleware
27+
*BaseMiddleware
2828
HookType coprocess.HookType
2929
HookName string
3030
MiddlewareDriver apidef.MiddlewareDriver
@@ -35,15 +35,15 @@ func (mw *CoProcessMiddleware) GetName() string {
3535
}
3636

3737
// CreateCoProcessMiddleware initializes a new CP middleware, takes hook type (pre, post, etc.), hook name ("my_hook") and driver ("python").
38-
func CreateCoProcessMiddleware(hookName string, hookType coprocess.HookType, mwDriver apidef.MiddlewareDriver, tykMwSuper *TykMiddleware) func(http.Handler) http.Handler {
38+
func CreateCoProcessMiddleware(hookName string, hookType coprocess.HookType, mwDriver apidef.MiddlewareDriver, baseMid *BaseMiddleware) func(http.Handler) http.Handler {
3939
dMiddleware := &CoProcessMiddleware{
40-
TykMiddleware: tykMwSuper,
40+
BaseMiddleware: baseMid,
4141
HookType: hookType,
4242
HookName: hookName,
4343
MiddlewareDriver: mwDriver,
4444
}
4545

46-
return CreateMiddleware(dMiddleware, tykMwSuper)
46+
return CreateMiddleware(dMiddleware, baseMid)
4747
}
4848

4949
func doCoprocessReload() {
@@ -257,7 +257,7 @@ func (m *CoProcessMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Requ
257257
}).Info("Attempted access with invalid key.")
258258

259259
// Fire Authfailed Event
260-
AuthFailed(m.TykMiddleware, r, token)
260+
AuthFailed(m.BaseMiddleware, r, token)
261261

262262
// Report in health check
263263
ReportHealthCheckValue(m.Spec.Health, KeyFailure, "1")

coprocess_dummy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var (
2929
)
3030

3131
type CoProcessMiddleware struct {
32-
*TykMiddleware
32+
*BaseMiddleware
3333
HookType coprocess.HookType
3434
HookName string
3535
MiddlewareDriver apidef.MiddlewareDriver
@@ -61,4 +61,4 @@ func CoProcessInit() {
6161

6262
func doCoprocessReload() {}
6363

64-
func newExtractor(referenceSpec *APISpec, mw *TykMiddleware) {}
64+
func newExtractor(referenceSpec *APISpec, mw *BaseMiddleware) {}

0 commit comments

Comments
 (0)