From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id E00E275CD6 for ; Thu, 22 Apr 2021 16:02:56 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D73E91CDC8 for ; Thu, 22 Apr 2021 16:02:26 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 61AC91CC8D for ; Thu, 22 Apr 2021 16:02:20 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 3BA8546379 for ; Thu, 22 Apr 2021 16:02:20 +0200 (CEST) From: Wolfgang Bumiller To: pbs-devel@lists.proxmox.com Date: Thu, 22 Apr 2021 16:02:13 +0200 Message-Id: <20210422140213.30989-28-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210422140213.30989-1-w.bumiller@proxmox.com> References: <20210422140213.30989-1-w.bumiller@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.069 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [acme.rs, mod.rs] Subject: [pbs-devel] [PATCH v2 backup 27/27] api: acme: make account name optional in register call X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Apr 2021 14:02:56 -0000 we do this in PVE and PMG and default to "default", so let's do it here too, this is mostly for UI compatibility Signed-off-by: Wolfgang Bumiller --- src/api2/config/acme.rs | 10 ++++++++-- src/config/acme/mod.rs | 14 +++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/api2/config/acme.rs b/src/api2/config/acme.rs index 4f72a94e..25a050e8 100644 --- a/src/api2/config/acme.rs +++ b/src/api2/config/acme.rs @@ -161,7 +161,10 @@ fn account_contact_from_string(s: &str) -> Vec { #[api( input: { properties: { - name: { type: AccountName }, + name: { + type: AccountName, + optional: true, + }, contact: { description: "List of email addresses.", }, @@ -183,7 +186,7 @@ fn account_contact_from_string(s: &str) -> Vec { )] /// Register an ACME account. fn register_account( - name: AccountName, + name: Option, // Todo: email & email-list schema contact: String, tos_url: Option, @@ -192,6 +195,9 @@ fn register_account( ) -> Result { let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; + let name = name + .unwrap_or_else(|| unsafe { AccountName::from_string_unchecked("default".to_string()) }); + if Path::new(&crate::config::acme::account_path(&name)).exists() { http_bail!(BAD_REQUEST, "account {:?} already exists", name); } diff --git a/src/config/acme/mod.rs b/src/config/acme/mod.rs index 0ed4974d..b4f14bff 100644 --- a/src/config/acme/mod.rs +++ b/src/config/acme/mod.rs @@ -5,7 +5,7 @@ use std::path::Path; use anyhow::{bail, format_err, Error}; use serde::{Deserialize, Serialize}; -use proxmox::api::api; +use proxmox::api::{api, schema::Schema}; use proxmox::sys::error::SysError; use proxmox::tools::fs::CreateOptions; @@ -85,6 +85,18 @@ impl AccountName { 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 AccountName { -- 2.20.1