use api_string_type macro
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com> Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
		
				
					committed by
					
						 Dietmar Maurer
						Dietmar Maurer
					
				
			
			
				
	
			
			
			
						parent
						
							ae5b1e188f
						
					
				
				
					commit
					ee0c5c8e01
				
			| @ -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" | ||||
|  | ||||
| @ -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, | ||||
|                     )); | ||||
|                 } | ||||
|  | ||||
| @ -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<Self, Error> { | ||||
|         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<str> 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); | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user