From 67b9c80d73c0ec295a64bf806c3720431040231c Mon Sep 17 00:00:00 2001 From: Edward Dowling Date: Thu, 26 Sep 2024 17:28:21 +0100 Subject: [PATCH] Add check AMRs are being watched before initialising cache --- integrations/access/pagerduty/app.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/integrations/access/pagerduty/app.go b/integrations/access/pagerduty/app.go index b697f75aa981b..316476b106097 100644 --- a/integrations/access/pagerduty/app.go +++ b/integrations/access/pagerduty/app.go @@ -22,6 +22,7 @@ import ( "context" "errors" "fmt" + "slices" "strings" "time" @@ -152,8 +153,17 @@ func (a *App) run(ctx context.Context) error { if err != nil { return trace.Wrap(err) } - if err := a.accessMonitoringRules.InitAccessMonitoringRulesCache(ctx); err != nil { - return trace.Wrap(err) + + if len(acceptedWatchKinds) == 0 { + return trace.BadParameter("failed to initialize watcher for all the required resources: %+v", + watchKinds) + } + // Check if KindAccessMonitoringRule resources are being watched, + // the role the plugin is running as may not have access. + if slices.Contains(acceptedWatchKinds, types.KindAccessMonitoringRule) { + if err := a.accessMonitoringRules.InitAccessMonitoringRulesCache(ctx); err != nil { + return trace.Wrap(err, "initializing Access Monitoring Rule cache") + } } a.mainJob.SetReady(ok)