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 0F180C0DF2 for ; Fri, 12 Jan 2024 17:16:58 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 187AE34B08 for ; Fri, 12 Jan 2024 17:16:57 +0100 (CET) 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 ; Fri, 12 Jan 2024 17:16:55 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 1A9F449129 for ; Fri, 12 Jan 2024 17:16:55 +0100 (CET) From: Christoph Heiss To: pbs-devel@lists.proxmox.com Date: Fri, 12 Jan 2024 17:16:01 +0100 Message-ID: <20240112161614.1012311-7-c.heiss@proxmox.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240112161614.1012311-1-c.heiss@proxmox.com> References: <20240112161614.1012311-1-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.003 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 T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pbs-devel] [PATCH proxmox-backup v3 06/13] 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: Fri, 12 Jan 2024 16:16:58 -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 --- 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 9094c2fa..d73bffdb 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.42.0