Move vendor-neutral firewall and network types (FirewallAction, Direction,
IpProtocol, NetworkProtocol, VipMode, LaggProtocol) from harmony Score
modules to harmony_types::firewall as industry-standard IaC types.
Display impls use human-readable names (IPv4, CARP, LACP) — not wire
format. OPNsense-specific wire translations live in opnsense-api::wire
via the ToOPNsenseValue trait ("inet", "carp", "lacp").
Dependency chain: harmony_types → opnsense-api → opnsense-config → harmony.
Users import types from harmony_types, translations happen transparently
in the infrastructure layer.
Includes 6 new tests verifying all wire value translations.
62 lines
1.7 KiB
Rust
62 lines
1.7 KiB
Rust
//! OPNsense typed API client.
|
|
//!
|
|
//! ## Design goals
|
|
//!
|
|
//! - **Generated types**: Model structs and enums are produced by `opnsense-codegen`
|
|
//! from OPNsense XML model files and placed in [`generated`].
|
|
//!
|
|
//! - **Hand-written runtime**: HTTP client, auth, and error handling live in this crate
|
|
//! and are never auto-generated.
|
|
//!
|
|
//! ## Crate layout
|
|
//!
|
|
//! ```text
|
|
//! opnsense_api/
|
|
//! src/
|
|
//! lib.rs — public re-exports
|
|
//! error.rs — Error type
|
|
//! client.rs — OpnsenseClient
|
|
//! auth.rs — credentials helpers
|
|
//! generated/
|
|
//! dnsmasq.rs — types from Dnsmasq.xml
|
|
//! interfaces.rs — types from Interfaces/Settings.xml
|
|
//! ...
|
|
//! examples/
|
|
//! list_dnsmasq.rs
|
|
//! list_packages.rs
|
|
//! install_package.rs
|
|
//! firmware_update.rs
|
|
//! ```
|
|
//!
|
|
//! ## Usage
|
|
//!
|
|
//! ```ignore
|
|
//! use opnsense_api::OpnsenseClient;
|
|
//!
|
|
//! let client = OpnsenseClient::builder()
|
|
//! .base_url("https://my-firewall.local/api")
|
|
//! .auth_from_key_secret("key", "secret")
|
|
//! .build()?;
|
|
//!
|
|
//! // GET a typed model response
|
|
//! let resp = client.get_typed::<dnsmasq::DnsmasqSettingsResponse>("dnsmasq", "settings", "get").await?;
|
|
//! println!("{:#?}", resp);
|
|
//! ```
|
|
|
|
pub mod auth;
|
|
pub mod client;
|
|
pub mod error;
|
|
pub mod response;
|
|
pub mod wire;
|
|
|
|
pub use client::OpnsenseClient;
|
|
pub use error::Error;
|
|
pub use response::{SearchResponse, StatusResponse, UuidResponse};
|
|
|
|
/// Auto-generated model types.
|
|
///
|
|
/// Each module corresponds to one OPNsense model (e.g. `interfaces`, `haproxy`,
|
|
/// `dnsmasq`). These files are produced by `opnsense-codegen` — do not edit
|
|
/// by hand. The `mod.rs` index is auto-generated by `opnsense-codegen` too.
|
|
pub mod generated;
|