-
Notifications
You must be signed in to change notification settings - Fork 11
Document the config template and harden config validation #870
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
base: main
Are you sure you want to change the base?
Changes from all commits
edd7250
8861e9b
4dd9250
5c1e427
8d63d56
70cfb07
e64902c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize}; | |
| use serde_json::{json, Value as Json}; | ||
| use std::collections::HashMap; | ||
| use std::time::Duration; | ||
| use validator::Validate; | ||
| use validator::{Validate, ValidationError}; | ||
|
|
||
| use crate::auction::provider::AuctionProvider; | ||
| use crate::auction::types::{AuctionContext, AuctionRequest, AuctionResponse, Bid, MediaType}; | ||
|
|
@@ -201,6 +201,7 @@ pub struct ApsConfig { | |
|
|
||
| /// APS publisher ID (accepts both string and integer from config) | ||
| #[serde(deserialize_with = "deserialize_pub_id")] | ||
| #[validate(length(min = 1), custom(function = validate_aps_pub_id))] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2 — Whitespace-only APS publisher IDs pass the new non-empty check
Please reject
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔧 wrench — A whitespace-only Please reject |
||
| pub pub_id: String, | ||
|
|
||
| /// APS API endpoint | ||
|
|
@@ -210,6 +211,7 @@ pub struct ApsConfig { | |
|
|
||
| /// Timeout in milliseconds | ||
| #[serde(default = "default_timeout_ms")] | ||
| #[validate(range(min = 1, max = 60000))] | ||
| pub timeout_ms: u32, | ||
| } | ||
|
|
||
|
|
@@ -285,6 +287,26 @@ impl Default for ApsConfig { | |
| } | ||
| } | ||
|
|
||
| /// Validator for [`ApsConfig::pub_id`]: rejects the known template placeholder | ||
| /// publisher ID. Non-emptiness is enforced by the built-in `length` validator; | ||
| /// this runs only when APS is enabled, because integration configs validate | ||
| /// lazily via `get_typed`. | ||
| fn validate_aps_pub_id(pub_id: &str) -> Result<(), ValidationError> { | ||
| if ApsConfig::PUB_ID_PLACEHOLDERS | ||
| .iter() | ||
| .any(|placeholder| placeholder.eq_ignore_ascii_case(pub_id.trim())) | ||
| { | ||
| return Err(ValidationError::new("aps_pub_id_placeholder")); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| impl ApsConfig { | ||
| /// Reserved example `pub_id` values from the config template that must not | ||
| /// be deployed while APS is enabled. | ||
| pub const PUB_ID_PLACEHOLDERS: &[&str] = &["your-aps-publisher-id"]; | ||
| } | ||
|
|
||
| impl IntegrationConfig for ApsConfig { | ||
| fn is_enabled(&self) -> bool { | ||
| self.enabled | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1 — APS validation runs even when the integration resolves to disabled
enableddefaults tofalse, butIntegrationSettings::get_typedonly short-circuits raw configs that explicitly containenabled = false. Otherwise it callsconfig.validate()before checkingconfig.is_enabled(). Consequently, an APS section that omitsenabledbut contains this documented placeholder now failsts config validateeven though APS resolves to disabled. This is a backward-incompatible config regression and can prevent application-state construction after an upgrade.Please check the resolved
is_enabled()value before field validation, while retaining the explicit-falsefast path, and add regression coverage for APS andadserver_mocksections with omittedenabled.