@@ -49,20 +49,20 @@ const (
49
49
50
50
var ErrUnsupportedAuthScheme = errors .New ("unsupported auth scheme" )
51
51
52
- func NewBFLADetector (ctx context.Context , modName string , apiInfoProvider apiInfoProvider , eventAlerter EventAlerter , ctrlNotifier ControllerNotifier , sp recovery.StatePersister , controllerResyncInterval time.Duration ) BFLADetector {
52
+ func NewBFLADetector (ctx context.Context , modName string , apiInfoProvider apiInfoProvider , eventAlerter EventAlerter , bflaNotifier BFLANotifier , sp recovery.StatePersister , notifierResyncInterval time.Duration ) BFLADetector {
53
53
l := & learnAndDetectBFLA {
54
- tracesCh : make (chan * CompositeTrace ),
55
- commandsCh : make (chan Command ),
56
- errCh : make (chan error ),
57
- apiInfoProvider : apiInfoProvider ,
58
- authzModelsMap : recovery .NewPersistedMap (sp , AuthzModelAnnotationName , reflect .TypeOf (AuthorizationModel {})),
59
- tracesCounterMap : recovery .NewPersistedMap (sp , AuthzProcessedTracesAnnotationName , reflect .TypeOf (1 )),
60
- statePersister : sp ,
61
- eventAlerter : eventAlerter ,
62
- controllerNotifier : ctrlNotifier ,
63
- controllerResyncInterval : controllerResyncInterval ,
64
- mu : & sync.RWMutex {},
65
- modName : modName ,
54
+ tracesCh : make (chan * CompositeTrace ),
55
+ commandsCh : make (chan Command ),
56
+ errCh : make (chan error ),
57
+ apiInfoProvider : apiInfoProvider ,
58
+ authzModelsMap : recovery .NewPersistedMap (sp , AuthzModelAnnotationName , reflect .TypeOf (AuthorizationModel {})),
59
+ tracesCounterMap : recovery .NewPersistedMap (sp , AuthzProcessedTracesAnnotationName , reflect .TypeOf (1 )),
60
+ statePersister : sp ,
61
+ eventAlerter : eventAlerter ,
62
+ bflaNotifier : bflaNotifier ,
63
+ notifierResyncInterval : notifierResyncInterval ,
64
+ mu : & sync.RWMutex {},
65
+ modName : modName ,
66
66
}
67
67
go func () {
68
68
for {
@@ -75,7 +75,7 @@ func NewBFLADetector(ctx context.Context, modName string, apiInfoProvider apiInf
75
75
}
76
76
}
77
77
}()
78
- go l .ctrlNotifier (ctx )
78
+ go l .notifier (ctx )
79
79
go l .run (ctx )
80
80
return l
81
81
}
@@ -184,11 +184,11 @@ type learnAndDetectBFLA struct {
184
184
185
185
statePersister recovery.StatePersister
186
186
187
- eventAlerter EventAlerter
188
- controllerNotifier ControllerNotifier
189
- controllerResyncInterval time.Duration
190
- mu * sync.RWMutex
191
- modName string
187
+ eventAlerter EventAlerter
188
+ bflaNotifier BFLANotifier
189
+ notifierResyncInterval time.Duration
190
+ mu * sync.RWMutex
191
+ modName string
192
192
}
193
193
194
194
type CommandsChan chan Command
@@ -266,7 +266,7 @@ func (l *learnAndDetectBFLA) commandsRunner(ctx context.Context, command Command
266
266
return fmt .Errorf ("unable to parse spec info: %w" , err )
267
267
}
268
268
err = l .updateAuthorizationModel (tags , cmd .path , cmd .method , cmd .clientRef , cmd .apiID , cmd .detectedUser , true , true )
269
- l .logError (l .notifyController (ctx , cmd .apiID ))
269
+ l .logError (l .notify (ctx , cmd .apiID ))
270
270
271
271
case * MarkIllegitimateCommand :
272
272
apiInfo , err := l .apiInfoProvider .GetAPIInfo (ctx , cmd .apiID )
@@ -278,7 +278,7 @@ func (l *learnAndDetectBFLA) commandsRunner(ctx context.Context, command Command
278
278
return fmt .Errorf ("unable to parse spec info: %w" , err )
279
279
}
280
280
err = l .updateAuthorizationModel (tags , cmd .path , cmd .method , cmd .clientRef , cmd .apiID , cmd .detectedUser , false , true )
281
- l .logError (l .notifyController (ctx , cmd .apiID ))
281
+ l .logError (l .notify (ctx , cmd .apiID ))
282
282
283
283
case * StopLearningCommand :
284
284
counter , err := l .tracesCounterMap .Get (cmd .apiID )
@@ -287,7 +287,7 @@ func (l *learnAndDetectBFLA) commandsRunner(ctx context.Context, command Command
287
287
}
288
288
289
289
counter .Set (0 )
290
- l .logError (l .notifyController (ctx , cmd .apiID ))
290
+ l .logError (l .notify (ctx , cmd .apiID ))
291
291
292
292
case * StartLearningCommand :
293
293
tracesToProcess , err := l .tracesCounterMap .Get (cmd .apiID )
@@ -313,7 +313,7 @@ func (l *learnAndDetectBFLA) commandsRunner(ctx context.Context, command Command
313
313
return fmt .Errorf ("unable to get authz model state: %w" , err )
314
314
}
315
315
authzModel .Set (AuthorizationModel {})
316
- l .logError (l .notifyController (ctx , cmd .apiID ))
316
+ l .logError (l .notify (ctx , cmd .apiID ))
317
317
318
318
case * ProvideAuthzModelCommand :
319
319
pv , err := l .authzModelsMap .Get (cmd .apiID )
@@ -448,7 +448,7 @@ func (l *learnAndDetectBFLA) traceRunner(ctx context.Context, trace *CompositeTr
448
448
return fmt .Errorf ("unable to set alert annotation: %w" , err )
449
449
}
450
450
451
- l .logError (l .notifyController (ctx , trace .APIEvent .APIInfoID ))
451
+ l .logError (l .notify (ctx , trace .APIEvent .APIInfoID ))
452
452
aud .WarningStatus = ResolveBFLAStatusInt (int (trace .APIEvent .StatusCode ))
453
453
}
454
454
aud .StatusCode = trace .APIEvent .StatusCode
@@ -457,7 +457,7 @@ func (l *learnAndDetectBFLA) traceRunner(ctx context.Context, trace *CompositeTr
457
457
return nil
458
458
}
459
459
460
- func (l * learnAndDetectBFLA ) notifyController (ctx context.Context , apiID uint ) error {
460
+ func (l * learnAndDetectBFLA ) notify (ctx context.Context , apiID uint ) error {
461
461
ntf := AuthzModelNotification {}
462
462
463
463
if l .IsLearning (apiID ) {
@@ -481,7 +481,7 @@ func (l *learnAndDetectBFLA) notifyController(ctx context.Context, apiID uint) e
481
481
ntf .AuthzModel , _ = v .Get ().(AuthorizationModel )
482
482
}
483
483
}
484
- return l .controllerNotifier .Notify (ctx , apiID , ntf )
484
+ return l .bflaNotifier .Notify (ctx , apiID , ntf )
485
485
}
486
486
487
487
func (l * learnAndDetectBFLA ) mustLearn (apiID uint ) (decrementFn func (), ok bool ) {
@@ -696,18 +696,18 @@ func (l *learnAndDetectBFLA) ProvideAuthzModel(apiID uint, am AuthorizationModel
696
696
})
697
697
}
698
698
699
- func (l * learnAndDetectBFLA ) ctrlNotifier (ctx context.Context ) {
700
- t := time .NewTicker (l .controllerResyncInterval )
699
+ func (l * learnAndDetectBFLA ) notifier (ctx context.Context ) {
700
+ t := time .NewTicker (l .notifierResyncInterval )
701
701
defer t .Stop ()
702
702
703
703
for {
704
704
select {
705
705
case <- ctx .Done ():
706
- log .Errorf ("Controller notifier finished working %s" , ctx .Err ())
706
+ log .Errorf ("Bfla notifier finished working %s" , ctx .Err ())
707
707
return
708
708
case <- t .C :
709
709
for _ , key := range l .authzModelsMap .Keys () {
710
- l .logError (l .notifyController (ctx , key ))
710
+ l .logError (l .notify (ctx , key ))
711
711
}
712
712
}
713
713
}
0 commit comments