From e121fb42660f8dc11597dda216d5eb9bb285c0fe Mon Sep 17 00:00:00 2001 From: nutcas3 Date: Sat, 25 Apr 2026 05:52:35 +0300 Subject: [PATCH] feat: Add runtime configuration management API for packet gateway with sync interval and charging engine URL updates - Add PacketGatewayConfig struct with interface, redis_url, charging_engine_url, sync_interval, and health_port fields - Add ConfigUpdateRequest struct with optional sync_interval and charging_engine_url fields - Add ConfigResponse struct with config and status fields - Add ConfigState wrapper with Arc> for thread-safe config access - Add create_config_ --- apps/packet-gateway/src/config.rs | 78 +++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 apps/packet-gateway/src/config.rs diff --git a/apps/packet-gateway/src/config.rs b/apps/packet-gateway/src/config.rs new file mode 100644 index 0000000..5173e6c --- /dev/null +++ b/apps/packet-gateway/src/config.rs @@ -0,0 +1,78 @@ +use axum::{ + extract::State, + routing::{get, post}, + Json, Router, +}; +use serde::{Deserialize, Serialize}; +use std::sync::Arc; +use tokio::sync::RwLock; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PacketGatewayConfig { + pub interface: String, + pub redis_url: String, + pub charging_engine_url: String, + pub sync_interval: u64, + pub health_port: u16, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ConfigUpdateRequest { + pub sync_interval: Option, + pub charging_engine_url: Option, +} + +#[derive(Debug, Clone, Serialize)] +pub struct ConfigResponse { + pub config: PacketGatewayConfig, + pub status: String, +} + +#[derive(Clone)] +pub struct ConfigState { + pub config: Arc>, +} + +pub fn create_config_router(config_state: ConfigState) -> Router { + Router::new() + .route("/config", get(get_config).post(update_config)) + .route("/config/sync", post(trigger_sync)) + .with_state(config_state) +} + +pub async fn get_config(State(state): State) -> Json { + let config = state.config.read().await; + Json(ConfigResponse { + config: config.clone(), + status: "active".to_string(), + }) +} + +pub async fn update_config( + State(state): State, + Json(req): Json, +) -> Json { + let mut config = state.config.write().await; + + if let Some(interval) = req.sync_interval { + config.sync_interval = interval; + } + + if let Some(url) = req.charging_engine_url { + config.charging_engine_url = url; + } + + Json(ConfigResponse { + config: config.clone(), + status: "updated".to_string(), + }) +} + +pub async fn trigger_sync(State(state): State) -> Json { + // This would trigger a manual sync from Redis to eBPF maps + // For now, return a success response + Json(serde_json::json!({ + "status": "sync_triggered", + "message": "Manual sync triggered" + })) +}