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) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id F23626D132 for ; Wed, 31 Mar 2021 16:08:27 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id DAD6810912 for ; Wed, 31 Mar 2021 16:07:57 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 601F810904 for ; Wed, 31 Mar 2021 16:07:57 +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 505E642F71 for ; Wed, 31 Mar 2021 16:07:56 +0200 (CEST) Message-ID: Date: Wed, 31 Mar 2021 16:07:55 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Thunderbird/88.0 Content-Language: en-US To: Proxmox Backup Server development discussion , Wolfgang Bumiller , Stefan Reiter References: <20210331102202.14767-1-s.reiter@proxmox.com> <20210331102202.14767-10-s.reiter@proxmox.com> <20210331125557.xcrymxfbcedqjegj@wobu-vie.proxmox.com> From: Thomas Lamprecht In-Reply-To: <20210331125557.xcrymxfbcedqjegj@wobu-vie.proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.044 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -0.001 Looks like a legit reply (A) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: Re: [pbs-devel] [PATCH v3 proxmox-backup 09/20] server/rest: add ApiAuth trait to make user auth generic 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: Wed, 31 Mar 2021 14:08:28 -0000 On 31.03.21 14:55, Wolfgang Bumiller wrote: >> -pub struct UserAuthData { >> +pub enum AuthError { >> + Generic(Error), >> + NoData, >> +} >> + >> +impl From for AuthError { >> + fn from(err: Error) -> Self { >> + AuthError::Generic(err) >> + } >> +} > ^ When you define an Error type you should immediately also derive Debug > and implement `std::fmt::Display`. While you only "display" it once, I > don't think the error message should be left up to the caller (see > further down below). > > In order to make this shorter and easier, I'd propose the inclusion of > the `thiserror` helper crate, then we'd need only as little code as: > > #[derive(thiserror::Error, Debug)] > pub enum AuthError { > #[error(transparent)] > Generic(#[from] Error), > > #[error("no authentication credentials provided")] > NoData, > } > > And the manual `From` impl can simply be dropped ;-) +1 for using thiserror in general from my side... > > That is *unless* you explicitly want this to *not* be convertible to > `anyhow::Error` automagically. Then you don't want this to impl > `std::error::Error`, but then you should add a comment for this ;-) > Which would be a valid way to go given that you're already wrapping > `anyhow::Error` in there... OTOH all the token parsing errors could be > combined into a single `AuthError::BadToken` instead of multiple > "slightly different" `format_err!` messages where the minor difference > in the error message doesn't really provide much value anyway (IMO). > > Anyway, this can easily be left as is and updated up in a later series. >