Refactor Policy Enforcer to Policy Checker
- Renamed the `PolicyEnforcer` interface and related implementations to `PolicyChecker` for clarity and consistency. - Updated configuration keys in YAML files to reflect the new `checkPolicy` terminology. - Adjusted related code, tests, and documentation to support the new naming convention and ensure compatibility. - Enhanced comments and examples for the `checkPolicy` configuration to improve usability.
This commit is contained in:
52
pkg/plugin/implementation/opapolicychecker/testdata/example.rego
vendored
Normal file
52
pkg/plugin/implementation/opapolicychecker/testdata/example.rego
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
package policy
|
||||
|
||||
import rego.v1
|
||||
|
||||
# Example policy: validation rules for beckn messages.
|
||||
# This demonstrates the structured result format used with policy_query_path.
|
||||
#
|
||||
# Available inputs:
|
||||
# - input: the full JSON message body (beckn request)
|
||||
# - data.config: runtime config from the adapter YAML (e.g., minDeliveryLeadHours)
|
||||
|
||||
# Default result: valid with no violations.
|
||||
default result := {
|
||||
"valid": true,
|
||||
"violations": []
|
||||
}
|
||||
|
||||
# Compute the result from collected violations.
|
||||
result := {
|
||||
"valid": count(violations) == 0,
|
||||
"violations": violations
|
||||
}
|
||||
|
||||
# Require provider details on confirm
|
||||
violations contains "confirm: missing provider in order" if {
|
||||
input.context.action == "confirm"
|
||||
not input.message.order.provider
|
||||
}
|
||||
|
||||
# Require at least one fulfillment on confirm
|
||||
violations contains "confirm: order has no fulfillments" if {
|
||||
input.context.action == "confirm"
|
||||
not input.message.order.fulfillments
|
||||
}
|
||||
|
||||
# Require billing details on confirm
|
||||
violations contains "confirm: missing billing info" if {
|
||||
input.context.action == "confirm"
|
||||
not input.message.order.billing
|
||||
}
|
||||
|
||||
# Require payment details on confirm
|
||||
violations contains "confirm: missing payment info" if {
|
||||
input.context.action == "confirm"
|
||||
not input.message.order.payment
|
||||
}
|
||||
|
||||
# Require search intent
|
||||
violations contains "search: missing intent" if {
|
||||
input.context.action == "search"
|
||||
not input.message.intent
|
||||
}
|
||||
Reference in New Issue
Block a user