diff --git a/integrations/access/accessmonitoring/access_monitoring_rules.go b/integrations/access/accessmonitoring/access_monitoring_rules.go index 0146e07fa0d96..7fb2c045d57ea 100644 --- a/integrations/access/accessmonitoring/access_monitoring_rules.go +++ b/integrations/access/accessmonitoring/access_monitoring_rules.go @@ -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: diff --git a/integrations/access/pagerduty/app.go b/integrations/access/pagerduty/app.go index ca3592468d461..8c1e7f4c6b52a 100644 --- a/integrations/access/pagerduty/app.go +++ b/integrations/access/pagerduty/app.go @@ -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 @@ -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, @@ -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) diff --git a/integrations/access/pagerduty/testlib/suite.go b/integrations/access/pagerduty/testlib/suite.go index c5accacc67d3c..b68c4d7e8d706 100644 --- a/integrations/access/pagerduty/testlib/suite.go +++ b/integrations/access/pagerduty/testlib/suite.go @@ -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 @@ -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 {