Skip to content

Add Shield advanced features (iter-18)#27

Merged
ractive merged 2 commits into
mainfrom
iter-18/shield-advanced
May 7, 2026
Merged

Add Shield advanced features (iter-18)#27
ractive merged 2 commits into
mainfrom
iter-18/shield-advanced

Conversation

@ractive

@ractive ractive commented May 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add API Guardian endpoints (get/upload/update spec, update endpoint config) to bunny-api-shield
  • Add Upload Scanning, Event Logs (with --all autopagination), and WAF Triggered Rule review (list/review/AI recommendation)
  • Add supplementary endpoints: WAF plan-segmentation, engine-config, DDoS enums, pullzone-mapping, promo state, access-list enums
  • Wire all 16 new methods into the hoppy shield CLI with new api-guardian, upload-scanning, event-logs, pullzone-mapping subcommands plus extensions to shield waf

Test plan

  • `cargo fmt`
  • `cargo clippy --workspace --all-targets -- -D warnings` clean
  • `cargo test --workspace` — all tests pass, including 15 new wiremock tests covering each new endpoint
  • Manual smoke test: `hoppy shield api-guardian get --shield-zone-id ` against live API
  • Manual smoke test: `hoppy shield upload-scanning get --shield-zone-id `
  • Manual smoke test: `hoppy shield event-logs --shield-zone-id --date `

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • API Guardian: view endpoints, upload OpenAPI specs, and update per-endpoint settings
    • Upload scanning: view and modify scanning configuration
    • Event logs: paginated access for auditing
    • WAF triggered rules: list, review actions, and fetch AI recommendations
    • Supplementary Shield endpoints: WAF plan segmentation, engine config, DDoS/access-list enums, and shield↔pull-zone mapping
    • CLI: commands to manage all above features
  • Bug Fixes

    • Promo-state endpoint: correctly handle empty successful responses
  • Tests

    • Extended end-to-end tests and fixtures covering all new Shield features

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>
@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Free

Run ID: f71f02cf-9387-46d4-abea-9383844dc996

📥 Commits

Reviewing files that changed from the base of the PR and between d16a172 and ecff922.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • crates/bunny-api-shield/Cargo.toml
  • crates/bunny-api-shield/src/client.rs
  • crates/bunny-api-shield/tests/e2e/shield_api.rs
  • fixtures/shield/api_guardian_get.json
  • fixtures/shield/api_guardian_update.json
  • fixtures/shield/waf_recommendation.json
  • src/commands/shield.rs

📝 Walkthrough

Walkthrough

This 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).

Changes

Shield Advanced Features Implementation

Layer / File(s) Summary
Type System & Contracts
crates/bunny-api-shield/src/types.rs, crates/bunny-api-shield/src/lib.rs
Adds 30+ new data types: API Guardian endpoint models, Upload Scanning configuration enums and states, Event Log structures with labels, WAF Triggered Rules items and review actions, WAF engine/plan/mapping models, and supplementary response wrappers with serde round-trip tests.
API Client Methods
crates/bunny-api-shield/src/client.rs
Extends ShieldClient with 16 new async methods: API Guardian (get/upload/update endpoints), Upload Scanning (get/update), Event Logs (with continuation token pagination), triggered WAF rules (list/review/recommend), and supplementary endpoints (plan segmentation, engine config, DDoS enums, pullzone mapping, access list enums).
CLI Command Definitions
src/cli.rs
Adds four new ShieldAction variants (ApiGuardian, UploadScanning, EventLogs, PullzoneMapping) with corresponding action enums, and extends ShieldWafAction with triggered-rule operations plus plan/engine config subcommands.
CLI Handlers & Output Rendering
src/commands/shield.rs
Implements four new feature handlers with table row formatting: handle_api_guardian() (reads OpenAPI spec files), handle_upload_scanning() (enum validation), handle_event_logs() (pagination loop), handle_pullzone_mapping(). Updates WAF handler for triggered-rule workflows and table rendering for endpoints, logs, and mappings.
E2E Tests & Fixtures
crates/bunny-api-shield/tests/e2e/shield_api.rs, fixtures/shield/*.json
Adds 16 WireMock-backed test cases and 15 JSON fixture files covering API Guardian (get/upload/update/endpoint-update), Upload Scanning (get/update), Event Logs with pagination, WAF Triggered Rules (list/review/recommend), WAF plan segmentation, engine config, DDoS enums, pullzone mapping, and access list enums.
Documentation & Status
hoppy-knowledgebase/iterations/iteration-18-shield-advanced.md
Marks iteration 18 status as completed and updates five feature checklists (API Guardian, Upload Scanning, Event Logs, WAF Triggered Rules, Supplementary Endpoints) with completed API client methods, types, CLI commands, and Wiremock tests; fixture recording and live E2E marked as skipped.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

"I hopped through code by moonlit beams,
APIs guarded in my dreams,
Logs paged onward, tokens neat,
WAFs reviewed with gentle feet,
Fixtures set — the Shield's complete."


Note

🎁 Summarized by CodeRabbit Free

Your 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 @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 shield CLI 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).

Comment thread src/commands/shield.rs Outdated
spec_file,
enforce_authorization,
} => {
let contents = std::fs::read_to_string(spec_file)
Comment thread src/commands/shield.rs Outdated
spec_file,
enforce_authorization,
} => {
let contents = std::fs::read_to_string(spec_file)
Comment thread src/commands/shield.rs
Comment on lines +832 to +837
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}");
}
Comment thread src/commands/shield.rs Outdated
Comment on lines +834 to +842
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}");
Comment on lines +978 to +997
/// 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>
@ractive
ractive merged commit 257de57 into main May 7, 2026
5 of 8 checks passed
@ractive
ractive deleted the iter-18/shield-advanced branch May 7, 2026 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants