Skip to main content

AirLibrary/Client/AirClient/
GetConfiguration.rs

1//! `AirClient::GetConfiguration` - reads back the daemon's current
2//! configuration for a named section.
3//!
4//! Sections are daemon-defined; canonical names include `"grpc"`,
5//! `"authentication"`, `"updates"`. Returns the raw key → value map; the
6//! caller parses individual entries.
7
8use std::collections::HashMap;
9
10use tonic::Request;
11
12use crate::{AirError, Client::AirClient::AirClient, Vine::Generated::air::ConfigurationRequest, dev_log};
13
14impl AirClient {
15	/// Reads a configuration section from the daemon.
16	pub async fn GetConfiguration(
17		&self,
18
19		request_id:String,
20
21		section:String,
22	) -> Result<HashMap<String, String>, AirError> {
23		let SectionDisplay = section.clone();
24
25		dev_log!("grpc", "[AirClient] Getting configuration for section: {}", section);
26
27		let RequestPayload = ConfigurationRequest { request_id, section };
28
29		let Client = self
30			.Client()
31			.ok_or_else(|| AirError::Network("Air client not initialized".to_string()))?;
32
33		let mut ClientGuard = Client.lock().await;
34
35		match ClientGuard.get_configuration(Request::new(RequestPayload)).await {
36			Ok(Response) => {
37				let Response = Response.into_inner();
38
39				dev_log!(
40					"grpc",
41					"[AirClient] Configuration retrieved for section: {} ({} keys)",
42					SectionDisplay,
43					Response.configuration.len()
44				);
45
46				Ok(Response.configuration)
47			},
48
49			Err(Status) => {
50				dev_log!("grpc", "error: [AirClient] Get configuration RPC error: {}", Status);
51
52				Err(AirError::Network(format!("Get configuration RPC error: {}", Status)))
53			},
54		}
55	}
56}