From ee0c5c8e01ef7eac7fa253bf6962cbfaac58b89d Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 4 May 2021 12:19:30 +0200 Subject: [PATCH] use api_string_type macro Signed-off-by: Wolfgang Bumiller Signed-off-by: Dietmar Maurer --- Cargo.toml | 2 +- src/api2/config/acme.rs | 4 +-- src/api2/types/acme.rs | 68 ++++------------------------------------- 3 files changed, 9 insertions(+), 65 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bedef572..be6c7da9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,7 +52,7 @@ percent-encoding = "2.1" pin-utils = "0.1.0" pin-project = "1.0" pathpatterns = "0.1.2" -proxmox = { version = "0.11.2", features = [ "sortable-macro", "api-macro", "websocket" ] } +proxmox = { version = "0.11.3", features = [ "sortable-macro", "api-macro", "websocket" ] } #proxmox = { git = "git://git.proxmox.com/git/proxmox", version = "0.1.2", features = [ "sortable-macro", "api-macro" ] } #proxmox = { path = "../proxmox/proxmox", features = [ "sortable-macro", "api-macro", "websocket" ] } proxmox-fuse = "0.1.1" diff --git a/src/api2/config/acme.rs b/src/api2/config/acme.rs index 8ba38347..d0771f35 100644 --- a/src/api2/config/acme.rs +++ b/src/api2/config/acme.rs @@ -198,7 +198,7 @@ fn register_account( .unwrap_or_else(|| unsafe { AcmeAccountName::from_string_unchecked("default".to_string()) }); if Path::new(&crate::config::acme::account_path(&name)).exists() { - http_bail!(BAD_REQUEST, "account {:?} already exists", name); + http_bail!(BAD_REQUEST, "account {} already exists", name); } let directory = directory.unwrap_or_else(|| { @@ -327,7 +327,7 @@ pub fn deactivate_account( Err(err) if !force => return Err(err), Err(err) => { worker.warn(format!( - "error deactivating account {:?}, proceedeing anyway - {}", + "error deactivating account {}, proceedeing anyway - {}", name, err, )); } diff --git a/src/api2/types/acme.rs b/src/api2/types/acme.rs index cc5df322..59470d1e 100644 --- a/src/api2/types/acme.rs +++ b/src/api2/types/acme.rs @@ -1,6 +1,3 @@ -use std::fmt; - -use anyhow::Error; use serde::{Deserialize, Serialize}; use proxmox::api::{api, schema::{Schema, StringSchema, ApiStringFormat}}; @@ -64,63 +61,10 @@ pub struct KnownAcmeDirectory { pub url: &'static str, } -#[api(format: &PROXMOX_SAFE_ID_FORMAT)] -/// ACME account name. -#[derive(Clone, Eq, PartialEq, Hash, Deserialize, Serialize)] -#[serde(transparent)] -pub struct AcmeAccountName(String); - -impl AcmeAccountName { - pub fn into_string(self) -> String { - self.0 - } - - pub fn from_string(name: String) -> Result { - match &Self::API_SCHEMA { - Schema::String(s) => s.check_constraints(&name)?, - _ => unreachable!(), - } - Ok(Self(name)) - } - - pub unsafe fn from_string_unchecked(name: String) -> Self { - Self(name) - } -} - -impl std::ops::Deref for AcmeAccountName { - type Target = str; - - #[inline] - fn deref(&self) -> &str { - &self.0 - } -} - -impl std::ops::DerefMut for AcmeAccountName { - #[inline] - fn deref_mut(&mut self) -> &mut str { - &mut self.0 - } -} - -impl AsRef for AcmeAccountName { - #[inline] - fn as_ref(&self) -> &str { - self.0.as_ref() - } -} - -impl fmt::Debug for AcmeAccountName { - #[inline] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Debug::fmt(&self.0, f) - } -} - -impl fmt::Display for AcmeAccountName { - #[inline] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Display::fmt(&self.0, f) - } +proxmox::api_string_type! { + #[api(format: &PROXMOX_SAFE_ID_FORMAT)] + /// ACME account name. + #[derive(Clone, Eq, PartialEq, Hash, Deserialize, Serialize)] + #[serde(transparent)] + pub struct AcmeAccountName(String); }