|
| 1 | +// Copyright (c) [2025] SUSE LLC |
| 2 | +// |
| 3 | +// All Rights Reserved. |
| 4 | +// |
| 5 | +// This program is free software; you can redistribute it and/or modify it |
| 6 | +// under the terms of the GNU General Public License as published by the Free |
| 7 | +// Software Foundation; either version 2 of the License, or (at your option) |
| 8 | +// any later version. |
| 9 | +// |
| 10 | +// This program is distributed in the hope that it will be useful, but WITHOUT |
| 11 | +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | +// more details. |
| 14 | +// |
| 15 | +// You should have received a copy of the GNU General Public License along |
| 16 | +// with this program; if not, contact SUSE LLC. |
| 17 | +// |
| 18 | +// To contact SUSE LLC about this file by physical or electronic mail, you may |
| 19 | +// find current contact information at www.suse.com. |
| 20 | + |
| 21 | +use crate::api::config::Config; |
| 22 | +use serde::{Deserialize, Serialize}; |
| 23 | +use serde_json::Value; |
| 24 | + |
| 25 | +#[derive(thiserror::Error, Debug)] |
| 26 | +pub enum Error { |
| 27 | + #[error(transparent)] |
| 28 | + Json(#[from] serde_json::Error), |
| 29 | +} |
| 30 | + |
| 31 | +/// Patch for the config. |
| 32 | +#[derive(Deserialize, Serialize, utoipa::ToSchema)] |
| 33 | +#[serde(rename_all = "camelCase")] |
| 34 | +pub struct Patch { |
| 35 | + /// Update for the current config. |
| 36 | + pub update: Option<Value>, |
| 37 | +} |
| 38 | + |
| 39 | +impl Patch { |
| 40 | + pub fn with_update(config: &Config) -> Result<Self, Error> { |
| 41 | + Ok(Self { |
| 42 | + update: Some(serde_json::to_value(config)?), |
| 43 | + }) |
| 44 | + } |
| 45 | +} |
0 commit comments