Skip to content

Iter-14: Pull zone edge rule management#18

Merged
ractive merged 2 commits into
mainfrom
iter-14/edge-rules
May 4, 2026
Merged

Iter-14: Pull zone edge rule management#18
ractive merged 2 commits into
mainfrom
iter-14/edge-rules

Conversation

@ractive

@ractive ractive commented May 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add edge rule CRUD on pull zones: list, add, update (upsert), delete, enable/disable. Edge rules let users redirect/rewrite URLs, override headers, swap origins, and block requests at the CDN edge.
  • bunny-api-core: new types (EdgeRule, EdgeRuleTrigger, EdgeRuleActionType, TriggerType, TriggerMatchingType, AddOrUpdateEdgeRule) and three client methods (add_or_update_edge_rule, delete_edge_rule, set_edge_rule_enabled).
  • CLI: hoppy pull-zone edge-rule {list, add, update, delete, enable} with repeatable --trigger type:pat1,pat2 syntax. Add omits Guid (creates), update requires --rule-id (upserts).
  • Tests: wiremock + insta snapshot coverage for list (json/table), add, delete, enable; live-api E2E lifecycle (create PZ → add redirect rule → list/verify → disable → re-enable → delete → verify gone → cleanup PZ).

Test plan

  • cargo fmt
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test --workspace (all suites green)
  • cargo check --features live-api --tests
  • Live E2E run against bunny.net once API key is available

Summary by CodeRabbit

  • New Features

    • Added pull zone edge rules support: create, update, delete, and enable/disable rules; CLI commands to list, add, update, delete, and toggle rules; support for actions, triggers with matching modes, and rule metadata.
  • Tests

    • Added live and mock tests covering edge-rule lifecycle and CLI behaviors.
  • Documentation

    • Marked edge-rules iteration notes as completed.
  • Chores

    • Added fixtures for edge-rule requests and pull zone responses.

Adds edge rule CRUD on pull zones: list, add, update (upsert),
delete, and enable/disable. Edge rules drive URL rewrites,
redirects, header manipulation, origin overrides, and request
blocking at the CDN edge.

- bunny-api-core: EdgeRule, EdgeRuleTrigger, EdgeRuleActionType,
  TriggerType enums plus three new client methods
  (add_or_update_edge_rule, delete_edge_rule, set_edge_rule_enabled)
- CLI: hoppy pull-zone edge-rule {list,add,update,delete,enable}
  with --trigger type:patterns repeatable syntax
- Tests: wiremock + insta snapshots for list/add/delete/enable
  and a live-api E2E lifecycle test

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 4, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Free

Run ID: 37c9f87c-c620-4a3b-8995-833598dcb53b

📥 Commits

Reviewing files that changed from the base of the PR and between 756122b and ad25b61.

📒 Files selected for processing (3)
  • src/cli.rs
  • src/commands/pull_zone.rs
  • tests/cli_pull_zone.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/commands/pull_zone.rs
  • tests/cli_pull_zone.rs

📝 Walkthrough

Walkthrough

Adds full Pull Zone edge rule support: new API client endpoints, edge-rule types and request builders, CLI subcommands/handlers for listing/adding/updating/deleting/enabling rules with trigger parsing, fixtures and tests (API and CLI), and documentation status update.

Changes

Edge Rules Feature

Layer / File(s) Summary
Data Types
crates/bunny-api-core/src/types.rs
Add EdgeRuleActionType, TriggerType, MatchingType enums with Display/FromStr; add EdgeRuleTrigger, EdgeRuleExtraAction, EdgeRule models; add AddOrUpdateEdgeRule request builder; extend PullZone with edge_rules: Vec<EdgeRule>.
API Client
crates/bunny-api-core/src/client.rs
Add CoreClient methods: add_or_update_edge_rule(pull_zone_id, body) -> POST /pullzone/{id}/edgerules/addOrUpdate; delete_edge_rule(pull_zone_id, edge_rule_id) -> DELETE /pullzone/{id}/edgerules/{edge_rule_id}; set_edge_rule_enabled(pull_zone_id, edge_rule_id, enabled) -> POST /pullzone/{id}/edgerules/{edge_rule_id}/setEdgeRuleEnabled.
API Exports
crates/bunny-api-core/src/lib.rs
Re-export new edge-rule types: AddOrUpdateEdgeRule, EdgeRule, EdgeRuleActionType, EdgeRuleExtraAction, EdgeRuleTrigger, MatchingType, etc.
API Fixtures & Tests
fixtures/core/pullzone_edgerule_add.json, fixtures/core/pullzone_get_with_edgerules.json, crates/bunny-api-core/tests/pullzone_api.rs
Add fixtures for add and get-with-edgerules; add tests verifying add/update request body, delete request, set enabled request, and deserialization of edge_rules from GET.
CLI Command Structure
src/cli.rs
Add PullZoneAction::EdgeRule { action: EdgeRuleAction } and EdgeRuleAction enum with List, Add, Update, Delete, Enable variants and corresponding CLI arguments (triggers, action params, matching type, etc.).
CLI Handlers
src/commands/pull_zone.rs
Add handle_edge_rule implementation, EdgeRuleRow table model, parse_trigger helper for type:pattern1,pattern2, and build_edge_rule_body to convert CLI inputs into AddOrUpdateEdgeRule; implement list/add/update/delete/enable flows (delete gated by --yes).
CLI & Integration Tests
tests/cli_pull_zone.rs
Add live-API lifecycle test for edge-rule add/list/disable/enable/delete; add mock-based CLI tests for JSON/table list snapshots, add, delete, enable; remove two obsolete nonexistent-resource live tests.
Documentation
hoppy-knowledgebase/iterations/iteration-14-edge-rules.md
Mark iteration status completed and check off API client, CLI, and testing checklist items.

Sequence Diagram

sequenceDiagram
    actor User
    participant CLI as CLI Handler
    participant Parser as Trigger Parser
    participant Builder as Request Builder
    participant Client as API Client
    participant Server as Bunny API

    User->>CLI: hoppy pullzone edge-rule add --id 123 --action-type redirect --trigger "url:*/old-path*" --action-param1 /new-path
    CLI->>Parser: parse_trigger("url:*/old-path*")
    Parser->>Parser: split type and patterns
    Parser-->>CLI: EdgeRuleTrigger
    CLI->>Builder: build_edge_rule_body(action_type, triggers, ...)
    Builder->>Builder: construct AddOrUpdateEdgeRule
    Builder-->>CLI: request body
    CLI->>Client: add_or_update_edge_rule(123, body)
    Client->>Server: POST /pullzone/123/edgerules/addOrUpdate
    Server-->>Client: 200 OK (empty)
    Client-->>CLI: Result<()>
    CLI-->>User: "Edge rule added"
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

🐰 Hoppy hops and parses strings with care,

Builds a rule and sends it through the air,
Triggers split and enums find their name,
CLI, client, fixtures — all play the game,
A tiny rabbit cheers: rules routed fair!


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

This PR adds pull zone edge rule management to Hoppy, wiring new bunny.net edge rule API support in bunny-api-core through to new hoppy pull-zone edge-rule ... CLI subcommands, along with fixtures and tests to validate behavior.

Changes:

  • Introduce edge rule request/response types and client methods in bunny-api-core (upsert, delete, enable/disable) and deserialize PullZone.EdgeRules.
  • Add CLI support for pull-zone edge-rule {list, add, update, delete, enable} plus trigger parsing and table/JSON output formatting.
  • Expand test coverage with new fixtures, wiremock tests, snapshots, and a live-api lifecycle test.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/snapshots/cli_pull_zone__pull_zone_list_json.snap Updates pull zone list JSON snapshot to include EdgeRules.
tests/snapshots/cli_pull_zone__pull_zone_get_json.snap Updates pull zone get JSON snapshot to include EdgeRules.
tests/snapshots/cli_pull_zone__pull_zone_create_json.snap Updates pull zone create JSON snapshot to include EdgeRules.
tests/snapshots/cli_pull_zone__pull_zone_edge_rule_list_table.snap New snapshot for edge rule list table output.
tests/snapshots/cli_pull_zone__pull_zone_edge_rule_list_json.snap New snapshot for edge rule list JSON output.
tests/cli_pull_zone.rs Adds wiremock tests + snapshots for edge rules and a live-api edge rule lifecycle test.
src/commands/pull_zone.rs Implements edge rule subcommand handling (list/add/update/delete/enable) and trigger parsing.
src/cli.rs Adds pull-zone edge-rule clap subcommands and flags.
hoppy-knowledgebase/iterations/iteration-14-edge-rules.md Marks iteration 14 work as completed and checks off tasks.
fixtures/core/pullzone_get_with_edgerules.json New fixture containing EdgeRules data for list/get tests.
fixtures/core/pullzone_edgerule_add.json New edge rule fixture payload.
crates/bunny-api-core/tests/pullzone_api.rs Adds unit tests for edge rule endpoints and edge rule deserialization.
crates/bunny-api-core/src/types.rs Adds edge rule enums/models + AddOrUpdateEdgeRule, and adds edge_rules to PullZone.
crates/bunny-api-core/src/lib.rs Re-exports new edge rule types.
crates/bunny-api-core/src/client.rs Adds edge rule client methods (upsert, delete, enable/disable).

Comment thread src/cli.rs Outdated
#[arg(long)]
rule_id: String,
/// Whether to enable (true) or disable (false) the rule
#[arg(long)]
Comment thread tests/cli_pull_zone.rs
Comment on lines +689 to +693
"--rule-id",
&guid,
"--enabled",
"false",
]);
Comment thread src/commands/pull_zone.rs Outdated
let pz = client.get_pull_zone(*id).await?;
if let OutputFormat::Json = format {
let json = serde_json::to_string_pretty(&pz.edge_rules)
.expect("failed to serialize to JSON");
- src/cli.rs: --enabled now uses ArgAction::Set so users can pass
  --enabled true/false (matches the help text and the pattern used
  by hostname force-ssl). Reported by Copilot, CodeRabbit, and local.
- tests/cli_pull_zone.rs: mock enable test now passes "true" as the
  flag value to match the new arg syntax.
- src/commands/pull_zone.rs: replace .expect() with .context()? for
  edge rule list JSON serialization, per the project rule against
  panicking outside tests.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ractive
ractive merged commit b076859 into main May 4, 2026
5 of 8 checks passed
@ractive
ractive deleted the iter-14/edge-rules branch May 4, 2026 23:10
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