snap_control/server/state/
dto.rs1use anyhow::Context;
17use serde::{Deserialize, Serialize};
18use utoipa::ToSchema;
19
20use crate::server::state::ControlPlaneIoConfig;
21
22#[derive(Debug, Serialize, Deserialize, ToSchema, Clone)]
24pub struct IoControlPlaneConfigDto {
25 #[schema(nullable = false)]
27 #[serde(skip_serializing_if = "Option::is_none", default)]
28 pub api_addr: Option<String>,
29}
30
31impl TryFrom<IoControlPlaneConfigDto> for ControlPlaneIoConfig {
32 type Error = anyhow::Error;
33
34 fn try_from(value: IoControlPlaneConfigDto) -> Result<Self, Self::Error> {
35 let api_addr = match value.api_addr {
36 Some(addr) => Some(addr.parse().context("invalid control plane API address")?),
37 None => None,
38 };
39
40 Ok(Self { api_addr })
41 }
42}
43
44impl From<&ControlPlaneIoConfig> for IoControlPlaneConfigDto {
45 fn from(value: &ControlPlaneIoConfig) -> Self {
46 IoControlPlaneConfigDto {
47 api_addr: value.api_addr.map(|addr| addr.to_string()),
48 }
49 }
50}