//! # Collar API //! //! HTTP API for network management and instance management functionality. //! //! ## Network Endpoints //! //! - `GET /networks` - List all networks //! - `POST /networks` - Create a new network //! - `GET /networks/{name}` - Get network details //! - `DELETE /networks/{name}` - Delete a network //! //! ## Network Creation //! //! Networks can be created with different provider and assigner configurations: //! //! ### Basic Network //! ```json //! { //! "name": "test-network", //! "cidr": "192.168.1.0/24" //! } //! ``` //! //! ### Network with Basic Assigner //! ```json //! { //! "name": "test-network", //! "cidr": "192.168.1.0/24", //! "assigner_type": "basic", //! "assigner_config": { //! "strategy": "sequential" //! } //! } //! ``` //! //! ### Network with Range Assigner //! ```json //! { //! "name": "test-network", //! "cidr": "192.168.1.0/24", //! "assigner_type": "range", //! "assigner_config": { //! "range_name": "my-range" //! } //! } //! ``` //! //! ## Instance Endpoints //! //! - `GET /instances` - List all instances //! - `POST /instances` - Create a new instance //! - `GET /instances/{name}` - Get instance details //! - `DELETE /instances/{name}` - Delete an instance //! //! ## Instance Creation //! //! Instances can be created with different provider types: //! //! ### Jail Instance //! ```json //! { //! "name": "my-jail", //! "provider_type": "jail", //! "provider_config": { //! "jail_conf": "/etc/jail.conf", //! "dataset": "zroot/jails" //! } //! } //! ``` //! //! ### Container Instance //! ```json //! { //! "name": "my-container", //! "provider_type": "container", //! "provider_config": { //! "runtime": "docker", //! "image": "alpine:latest" //! } //! } //! ``` //! //! ### Instance with Network Interfaces //! ```json //! { //! "name": "networked-instance", //! "provider_type": "jail", //! "provider_config": {}, //! "network_interfaces": [ //! { //! "network_name": "test-network", //! "interface_name": "eth0" //! } //! ] //! } //! ``` //! //! ## Internal Debug Endpoints //! //! The API also provides several internal debug endpoints that will be removed in the future. //! These are organized in the `internal` module. use std::sync::Arc; use axum::routing::get; use axum::routing::post; use axum::routing::delete; pub use axum::serve; mod network; mod instance; mod internal; pub struct AppState { collar: libcollar::State, } pub fn app(collar: libcollar::State) -> axum::Router { let state = Arc::new(AppState { collar }); // build our application with routes let app = axum::Router::new() .route("/", get(|| async { "collared." })) // Instances routes .route("/instances", get(instance::get_instances)) .route("/instances", post(instance::post_instances)) .route("/instances/{name}", get(instance::get_instance)) .route("/instances/{name}", delete(instance::delete_instance)) // Network management routes .route("/networks", get(network::get_networks)) .route("/networks", post(network::post_networks)) .route("/networks/{name}", get(network::get_network)) .route("/networks/{name}", delete(network::delete_network)) // Internal debug routes .route("/internal/ng/eiface/{name}", axum::routing::post(internal::ng::post_ng_eiface)) .route("/internal/store/namespace/{name}", axum::routing::post(internal::namespace::post_ns)) .route("/internal/store/namespace/{name}/{key}/{value}", axum::routing::post(internal::namespace::post_ns_key)) .route("/internal/store/namespace/{name}/{key}", get(internal::namespace::get_ns_key)) .route("/internal/store/range/new/{name}/{size}", axum::routing::post(internal::range::post_range_define)) .route("/internal/store/range/{name}/assign/{value}", axum::routing::post(internal::range::post_range_assign)) .route("/internal/store/range/{name}/unassign/{value}", axum::routing::post(internal::range::post_range_unassign)) .route("/internal/store/range/{name}/{position}", get(internal::range::get_range_position)) .route("/internal/store/range/{name}", get(internal::range::get_range_list)) .route("/internal/store/ranges", get(internal::range::get_ranges_list)) .with_state(state) .layer(tower_http::trace::TraceLayer::new_for_http()); app }