Skip to content

Commit

Permalink
Remove duplicated ruleHandler init
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardDowling committed Oct 22, 2024
1 parent bccd68d commit 04f9a49
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (amrh *RuleHandler) HandleAccessMonitoringRule(ctx context.Context, event t
}
amrh.accessMonitoringRules.rules[req.Metadata.Name] = req
if amrh.onCacheUpdateCallback != nil {
amrh.onCacheUpdateCallback(req.Metadata.Name)
amrh.onCacheUpdateCallback(types.OpPut, req.GetMetadata().Name, req)
}
return nil
case types.OpDelete:
Expand Down
24 changes: 6 additions & 18 deletions integrations/access/pagerduty/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,6 @@ func NewApp(conf Config) (*App, error) {
teleport: conf.Client,
statusSink: conf.StatusSink,
}

amrhConf := accessmonitoring.RuleHandlerConfig{
Client: conf.Client,
PluginType: types.PluginTypePagerDuty,
FetchRecipientCallback: func(_ context.Context, name string) (*common.Recipient, error) {
return &common.Recipient{
Name: name,
ID: name,
Kind: common.RecipientKindSchedule,
}, nil
},
}
if conf.OnAccessMonitoringRuleCacheUpdateCallback != nil {
amrhConf.OnCacheUpdateCallback = conf.OnAccessMonitoringRuleCacheUpdateCallback
}
app.accessMonitoringRules = accessmonitoring.NewRuleHandler(amrhConf)
app.mainJob = lib.NewServiceJob(app.run)

return app, nil
Expand Down Expand Up @@ -188,7 +172,7 @@ func (a *App) init(ctx context.Context) error {
}
}

a.accessMonitoringRules = accessmonitoring.NewRuleHandler(accessmonitoring.RuleHandlerConfig{
amrhConf := accessmonitoring.RuleHandlerConfig{
Client: a.teleport,
PluginType: types.PluginTypePagerDuty,
PluginName: pluginName,
Expand All @@ -199,7 +183,11 @@ func (a *App) init(ctx context.Context) error {
Kind: common.RecipientKindSchedule,
}, nil
},
})
}
if a.conf.OnAccessMonitoringRuleCacheUpdateCallback != nil {
amrhConf.OnCacheUpdateCallback = a.conf.OnAccessMonitoringRuleCacheUpdateCallback
}
a.accessMonitoringRules = accessmonitoring.NewRuleHandler(amrhConf)

if pong, err = a.checkTeleportVersion(ctx); err != nil {
return trace.Wrap(err)
Expand Down
4 changes: 2 additions & 2 deletions integrations/access/pagerduty/testlib/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func (s *PagerdutySuiteOSS) TestRecipientsFromAccessMonitoringRule() {
require.EventuallyWithT(t, func(t *assert.CollectT) {
mu.Lock()
require.Contains(t, collectedNames, ruleName)
mu.UnLock()
mu.Unlock()
}, 3*time.Second, time.Millisecond*100, "new access monitoring rule did not begin applying")

// Test execution: create an access request
Expand All @@ -489,7 +489,7 @@ func (s *PagerdutySuiteOSS) TestRecipientsFromAccessMonitoringRule() {
assert.Equal(t, s.pdNotifyService2.ID, pluginData.ServiceID)

assert.NoError(t, s.ClientByName(integration.RulerUserName).
AccessMonitoringRulesClient().DeleteAccessMonitoringRule(ctx, "test-pagerduty-amr"))
AccessMonitoringRulesClient().DeleteAccessMonitoringRule(ctx, ruleName))
}

func (s *PagerdutyBaseSuite) assertNewEvent(ctx context.Context, watcher types.Watcher, opType types.OpType, resourceKind, resourceName string) types.Event {
Expand Down

0 comments on commit 04f9a49

Please sign in to comment.