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 68F48CDAE for ; Wed, 16 Aug 2023 16:49:35 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 488D018065 for ; Wed, 16 Aug 2023 16:49:05 +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 for ; Wed, 16 Aug 2023 16:49:04 +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 A24EC41047 for ; Wed, 16 Aug 2023 16:49:03 +0200 (CEST) From: Christoph Heiss To: pbs-devel@lists.proxmox.com Date: Wed, 16 Aug 2023 16:47:36 +0200 Message-ID: <20230816144746.1265108-7-c.heiss@proxmox.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816144746.1265108-1-c.heiss@proxmox.com> References: <20230816144746.1265108-1-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.041 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy 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 Subject: [pbs-devel] [PATCH proxmox-backup v2 06/15] realm sync: generic-ify `LdapSyncSettings` and `GeneralSyncSettings` 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, 16 Aug 2023 14:49:35 -0000 Since both only needs a handful of attributes anyway, pass them explicitly instead of as an LDAP-specific config object, such that these types can be reused for other realms like the new Active Directory one. No functional changes. Signed-off-by: Christoph Heiss --- Changes v1 -> v2: * No changes src/server/realm_sync_job.rs | 42 ++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/server/realm_sync_job.rs b/src/server/realm_sync_job.rs index 1f92e843..5a7bcf0b 100644 --- a/src/server/realm_sync_job.rs +++ b/src/server/realm_sync_job.rs @@ -81,9 +81,14 @@ impl LdapRealmSyncJob { }; let sync_settings = GeneralSyncSettings::default() - .apply_config(&config)? + .apply_config(config.sync_defaults_options.as_deref())? .apply_override(override_settings)?; - let sync_attributes = LdapSyncSettings::from_config(&config)?; + let sync_attributes = LdapSyncSettings::new( + &config.user_attr, + config.sync_attributes.as_deref(), + config.user_classes.as_deref(), + config.filter.as_deref(), + )?; let ldap_config = auth::LdapAuthenticator::api_type_to_config(&config)?; @@ -385,14 +390,19 @@ struct LdapSyncSettings { } impl LdapSyncSettings { - fn from_config(config: &LdapRealmConfig) -> Result { - let mut attributes = vec![config.user_attr.clone()]; + fn new( + user_attr: &str, + sync_attributes: Option<&str>, + user_classes: Option<&str>, + user_filter: Option<&str>, + ) -> Result { + let mut attributes = vec![user_attr.to_owned()]; let mut email = None; let mut firstname = None; let mut lastname = None; - if let Some(sync_attributes) = &config.sync_attributes { + if let Some(sync_attributes) = &sync_attributes { let value = LdapSyncAttributes::API_SCHEMA.parse_property_string(sync_attributes)?; let sync_attributes: LdapSyncAttributes = serde_json::from_value(value)?; @@ -400,20 +410,20 @@ impl LdapSyncSettings { firstname = sync_attributes.firstname.clone(); lastname = sync_attributes.lastname.clone(); - if let Some(email_attr) = sync_attributes.email { - attributes.push(email_attr); + if let Some(email_attr) = &sync_attributes.email { + attributes.push(email_attr.clone()); } - if let Some(firstname_attr) = sync_attributes.firstname { - attributes.push(firstname_attr); + if let Some(firstname_attr) = &sync_attributes.firstname { + attributes.push(firstname_attr.clone()); } - if let Some(lastname_attr) = sync_attributes.lastname { - attributes.push(lastname_attr); + if let Some(lastname_attr) = &sync_attributes.lastname { + attributes.push(lastname_attr.clone()); } } - let user_classes = if let Some(user_classes) = &config.user_classes { + let user_classes = if let Some(user_classes) = &user_classes { let a = USER_CLASSES_ARRAY.parse_property_string(user_classes)?; serde_json::from_value(a)? } else { @@ -426,13 +436,13 @@ impl LdapSyncSettings { }; Ok(Self { - user_attr: config.user_attr.clone(), + user_attr: user_attr.to_owned(), firstname_attr: firstname, lastname_attr: lastname, email_attr: email, attributes, user_classes, - user_filter: config.filter.clone(), + user_filter: user_filter.map(ToOwned::to_owned), }) } } @@ -447,11 +457,11 @@ impl Default for GeneralSyncSettings { } impl GeneralSyncSettings { - fn apply_config(self, config: &LdapRealmConfig) -> Result { + fn apply_config(self, sync_defaults_options: Option<&str>) -> Result { let mut enable_new = None; let mut remove_vanished = None; - if let Some(sync_defaults_options) = &config.sync_defaults_options { + if let Some(sync_defaults_options) = sync_defaults_options { let sync_defaults_options = Self::parse_sync_defaults_options(sync_defaults_options)?; enable_new = sync_defaults_options.enable_new; -- 2.41.0