Add Shield advanced features (iter-18)#27
Conversation
Implement API Guardian, Upload Scanning, Event Logs, WAF Triggered Rule review, and supplementary enum/mapping endpoints for the Shield service. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Free Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThis PR completes iteration 18 by implementing comprehensive Shield API advanced features: API Guardian endpoint management with OpenAPI spec support, Upload Scanning configuration, Event Logs with pagination, WAF Triggered Rules review and recommendations, and supplementary endpoints (plan segmentation, engine config, DDoS enums, zone mappings, access list enums). ChangesShield Advanced Features Implementation
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
There was a problem hiding this comment.
Pull request overview
Extends Hoppy’s Shield support by adding a set of “advanced” Shield endpoints to bunny-api-shield and wiring them into the hoppy shield CLI (API Guardian, Upload Scanning, Event Logs with autopagination, Triggered WAF Rule review/recommendations, plus supplementary endpoints).
Changes:
- Added new Shield client methods + serde models for API Guardian, Upload Scanning, Event Logs, triggered-rule review, and supplementary enum/config endpoints.
- Expanded
hoppy shieldCLI with new subcommands and display row types for the new Shield features. - Added fixtures and wiremock-based tests covering most of the new endpoints.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/commands/shield.rs |
Adds CLI handlers + table row renderers for API Guardian, Upload Scanning, Event Logs (with --all), triggered-rule review/recommendation, and pullzone mapping. |
src/cli.rs |
Adds new hoppy shield subcommands/args (api-guardian, upload-scanning, event-logs, pullzone-mapping) and extends shield waf actions. |
hoppy-knowledgebase/iterations/iteration-18-shield-advanced.md |
Updates iteration plan status/checklist to completed. |
fixtures/shield/waf_triggered_rules.json |
Test fixture for triggered WAF rules list response. |
fixtures/shield/waf_triggered_review.json |
Test fixture for triggered WAF rule review response. |
fixtures/shield/waf_recommendation.json |
Test fixture for triggered-rule AI recommendation response. |
fixtures/shield/waf_plan_segmentation.json |
Test fixture for WAF plan segmentation response. |
fixtures/shield/waf_engine_config.json |
Test fixture for WAF engine config response. |
fixtures/shield/upload_scanning_update.json |
Test fixture for upload scanning update response. |
fixtures/shield/upload_scanning_get.json |
Test fixture for upload scanning get response. |
fixtures/shield/pullzone_mapping.json |
Test fixture for shield-zone ↔ pull-zone mapping response. |
fixtures/shield/event_logs.json |
Test fixture for event logs response. |
fixtures/shield/ddos_enums.json |
Test fixture for DDoS enum mappings response. |
fixtures/shield/api_guardian_upload.json |
Test fixture for API Guardian spec upload response. |
fixtures/shield/api_guardian_update.json |
Test fixture for API Guardian spec update response. |
fixtures/shield/api_guardian_get.json |
Test fixture for API Guardian get response. |
fixtures/shield/api_guardian_endpoint_update.json |
Test fixture for API Guardian endpoint update response. |
fixtures/shield/access_list_enums.json |
Test fixture for access list enums endpoint response. |
crates/bunny-api-shield/tests/e2e/shield_api.rs |
Adds wiremock tests for the newly added Shield endpoints (API Guardian, upload scanning, event logs, triggered rule review/recommendation, supplementary endpoints). |
crates/bunny-api-shield/src/types.rs |
Adds serde types/enums for new Shield endpoints (API Guardian, upload scanning, event logs, triggered rules, plan segmentation, engine config, enums, pullzone mapping). |
crates/bunny-api-shield/src/lib.rs |
Re-exports newly added Shield types for external use. |
crates/bunny-api-shield/src/client.rs |
Implements the new Shield client methods (API Guardian, upload scanning, event logs, triggered rules, supplementary endpoints). |
| spec_file, | ||
| enforce_authorization, | ||
| } => { | ||
| let contents = std::fs::read_to_string(spec_file) |
| spec_file, | ||
| enforce_authorization, | ||
| } => { | ||
| let contents = std::fs::read_to_string(spec_file) |
| ShieldWafAction::PlanSegmentation => { | ||
| let result = client.get_waf_plan_segmentation().await?; | ||
| let json = | ||
| serde_json::to_string_pretty(&result).context("failed to serialize to JSON")?; | ||
| println!("{json}"); | ||
| } |
| let json = | ||
| serde_json::to_string_pretty(&result).context("failed to serialize to JSON")?; | ||
| println!("{json}"); | ||
| } | ||
| ShieldWafAction::EngineConfig => { | ||
| let result = client.get_waf_engine_config().await?; | ||
| let json = | ||
| serde_json::to_string_pretty(&result).context("failed to serialize to JSON")?; | ||
| println!("{json}"); |
| /// Get the current promotional state for the account. | ||
| /// | ||
| /// `GET /shield/promo/state` | ||
| pub async fn get_promo_state(&self) -> Result<serde_json::Value> { | ||
| let resp = self | ||
| .execute(self.auth(self.client.get(self.url("/shield/promo/state")))) | ||
| .await?; | ||
| let (status, bytes) = self.read_body(resp).await?; | ||
| if status.is_success() { | ||
| // The spec declares no response body for this endpoint; return the raw value. | ||
| if bytes.is_empty() { | ||
| return Ok(serde_json::Value::Null); | ||
| } | ||
| return serde_json::from_slice(&bytes).context("failed to decode promo state"); | ||
| } | ||
| if let Ok(problem) = serde_json::from_slice::<ProblemDetails>(&bytes) { | ||
| anyhow::bail!(problem); | ||
| } | ||
| anyhow::bail!("Shield API returned status {status}"); | ||
| } |
- Use percent-encoding crate for event-logs continuation token to safely encode '=' and other reserved path-segment characters - Switch API Guardian spec uploads to tokio::fs (no blocking IO in async) - Honor OutputFormat in WAF plan-segmentation and engine-config; add tabled rows for both - Accumulate event-logs pages into a single JSON object when --all and --format json are used together - Make API Guardian fixtures internally consistent (validation flags match populated schemas / authorization config) - Reword waf_recommendation fixture to avoid contradictory phrasing - Add wiremock tests for get_promo_state covering empty body, JSON body, and ProblemDetails error paths Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
bunny-api-shield--allautopagination), and WAF Triggered Rule review (list/review/AI recommendation)hoppy shieldCLI with newapi-guardian,upload-scanning,event-logs,pullzone-mappingsubcommands plus extensions toshield wafTest plan
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests