Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug messages for attribute check failures #25

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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