-
Notifications
You must be signed in to change notification settings - Fork 84
/
do_not_generate_formation_assignment_notification_for_loops.go
37 lines (28 loc) · 1.81 KB
/
do_not_generate_formation_assignment_notification_for_loops.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package operators
import (
"context"
"github.com/kyma-incubator/compass/components/director/pkg/formationconstraint"
"github.com/kyma-incubator/compass/components/director/pkg/log"
"github.com/pkg/errors"
)
const (
// DoNotGenerateFormationAssignmentNotificationForLoopsOperator represents the DoNotGenerateFormationAssignmentNotificationForLoops operator
DoNotGenerateFormationAssignmentNotificationForLoopsOperator = "DoNotGenerateFormationAssignmentNotificationForLoops"
)
// NewDoNotGenerateFormationAssignmentNotificationForLoopsInput is input constructor for DoNotGenerateFormationAssignmentNotificationForLoopsOperator operator. It returns empty OperatorInput
func NewDoNotGenerateFormationAssignmentNotificationForLoopsInput() OperatorInput {
return &formationconstraint.DoNotGenerateFormationAssignmentNotificationInput{}
}
// DoNotGenerateFormationAssignmentNotificationForLoops is a constraint operator. It skips the generation of formation assignment notifications for loops
func (e *ConstraintEngine) DoNotGenerateFormationAssignmentNotificationForLoops(ctx context.Context, input OperatorInput) (bool, error) {
log.C(ctx).Infof("Executing operator: %q", DoNotGenerateFormationAssignmentNotificationForLoopsOperator)
i, ok := input.(*formationconstraint.DoNotGenerateFormationAssignmentNotificationInput)
if !ok {
return false, errors.Errorf("Incompatible input for operator %q", DoNotGenerateFormationAssignmentNotificationForLoopsOperator)
}
log.C(ctx).Infof("Enforcing %q constraint on resource of type: %q, subtype: %q and ID: %q", DoNotGenerateFormationAssignmentNotificationForLoopsOperator, i.ResourceType, i.ResourceSubtype, i.ResourceID)
if i.ResourceID != i.SourceResourceID || i.ResourceType != i.SourceResourceType {
return true, nil
}
return e.DoNotGenerateFormationAssignmentNotification(ctx, input)
}