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 81DF3612FA for ; Tue, 20 Oct 2020 12:16:26 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6CFBCDE39 for ; Tue, 20 Oct 2020 12:15:56 +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 EE05BDE2F for ; Tue, 20 Oct 2020 12:15:55 +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 AF0D845E30 for ; Tue, 20 Oct 2020 12:15:55 +0200 (CEST) Date: Tue, 20 Oct 2020 12:15:54 +0200 From: Wolfgang Bumiller To: Fabian =?utf-8?Q?Gr=C3=BCnbichler?= Cc: pbs-devel@lists.proxmox.com Message-ID: <20201020101554.qachhws6pfnibnwi@olga.proxmox.com> References: <20201019073919.588521-1-f.gruenbichler@proxmox.com> <20201019073919.588521-9-f.gruenbichler@proxmox.com> <20201020094222.2wsepswjngyle2ru@olga.proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20201020094222.2wsepswjngyle2ru@olga.proxmox.com> User-Agent: NeoMutt/20180716 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.014 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment 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] [RFC proxmox-backup 08/15] api: add API token endpoints 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: Tue, 20 Oct 2020 10:16:26 -0000 On Tue, Oct 20, 2020 at 11:42:22AM +0200, Wolfgang Bumiller wrote: > On Mon, Oct 19, 2020 at 09:39:12AM +0200, Fabian Grünbichler wrote: > > + let _lock = open_file_locked(user::USER_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?; > > + > > + let (mut config, expected_digest) = user::config()?; > > + > > + if let Some(ref digest) = digest { > > + let digest = proxmox::tools::hex_to_digest(digest)?; > > + crate::tools::detect_modified_configuration_file(&digest, &expected_digest)?; > > + } > > + > > + let tokenname = Tokenname::try_from(tokenname)?; > > + let tokenid = Userid::from((userid.name(), userid.realm(), tokenname.as_ref())); > > + > > + let mut data: user::ApiToken = config.lookup("token", tokenid.as_str())?; > > + > > + if let Some(comment) = comment { > > + let comment = comment.trim().to_string(); > > + if comment.is_empty() { > > + data.comment = None; > > + } else { > > + data.comment = Some(comment); > > + } > > + } > > + > > + if let Some(enable) = enable { > > + data.enable = if enable { None } else { Some(false) }; > > Really not a fan of single line if/else like this. Also with the `if > let` together this isn't actually "fast" to read. > How about: > > data.enabled = match enable { > Some(true) => None, > other => other, > } > > or > > data.enabled = enable.filter(|&b| !b); I missed that there was no `else` case which should leave it unchanged, so only the `match` version really makes sense, but with explicit `None => data.enabled`, maybe include comments: data.enabled = match enable { Some(true) => None, // enabled is default Some(false) => Some(false), None => data.enabled, // unchanged. }