Validation Warnings
Source: hello-pepr-warnings
This module demonstrates how to use the warnings feature in Pepr validation responses.
Overview
Section titled “Overview”The warnings feature allows Pepr modules to include warning messages in both approval and denial responses during validation. This provides a way to communicate important information to users without necessarily blocking their requests.
Scenarios
Section titled “Scenarios”This module includes three key scenarios that demonstrate different ways to use warnings:
-
Approval with Warnings (
warnings-approve)- Approves a ConfigMap while including warnings about:
- Use of deprecated fields
- Missing recommended labels
- Too many configuration items in a single ConfigMap
- Approves a ConfigMap while including warnings about:
-
Denial with Warnings (
warnings-deny)- Denies a ConfigMap that contains dangerous settings
- Includes warnings that explain why the settings are dangerous
- Uses a custom status code (422) for the denial
-
Multiple Warnings (
warnings-multiple)- Demonstrates how to aggregate multiple warnings in a single approval
- Shows warnings for deprecated and insecure settings
- Shows warnings for missing recommended labels
Implementation Details
Section titled “Implementation Details”The module demonstrates three key validation patterns:
- Using
request.Approve(warnings)to approve a request with warnings - Using
request.Deny(message, statusCode, warnings)to deny a request with warnings - Collecting and aggregating multiple warnings in a single response
These patterns can be used to provide helpful feedback to users while still enforcing policies. The warnings appear in both the API response and in the Pepr logs.
Testing
Section titled “Testing”The module includes end-to-end tests that verify:
- Resources with warnings are properly approved when appropriate
- Resources with dangerous settings are denied with appropriate warnings
- Multiple warnings are correctly aggregated and returned in responses