Skip to content

Commit

Permalink
Add debug messages for attribute check failures (#25)
Browse files Browse the repository at this point in the history
Signed-off-by: Aditya Sirish <[email protected]>
  • Loading branch information
adityasaky authored Feb 27, 2024
1 parent 8f37e80 commit ee4d41d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions verifier/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Constraint struct {
Rule string `yaml:"rule"`
AllowIfNoClaim bool `yaml:"allowIfNoClaim"`
Warn bool `yaml:"warn"`
Debug string `yaml:"debug"`
}

type ExpectedStepPredicates struct {
Expand Down
12 changes: 10 additions & 2 deletions verifier/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,18 @@ func applyAttributeRules(env *cel.Env, input interpreter.Activation, rules []Con
switch result := out.Value().(type) {
case bool:
if !result {
var message string
if r.Debug == "" {
message = fmt.Sprintf("verification failed for rule '%s'", r.Rule)
} else {
message = fmt.Sprintf("%s\nin rule '%s'", r.Debug, r.Rule)
}

if !r.Warn {
return fmt.Errorf("verification failed for rule '%s'", r.Rule)
return fmt.Errorf(message)
}
log.Warnf("Rule %s failed.", r.Rule)

log.Warnf("%s", message)
}
case error:
log.Info(result)
Expand Down
1 change: 1 addition & 0 deletions verifier/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ func substituteParameters(layout *Layout, parameters map[string]string) (*Layout
Rule: replace(replacer, attributeRule.Rule),
AllowIfNoClaim: attributeRule.AllowIfNoClaim,
Warn: attributeRule.Warn,
Debug: replace(replacer, attributeRule.Debug),
}
}
}
Expand Down

0 comments on commit ee4d41d

Please sign in to comment.