From 2972cfdeef4d2a52552a04e6093a3d616ae0b0d0 Mon Sep 17 00:00:00 2001 From: Mika Date: Fri, 1 Nov 2024 07:04:07 +0800 Subject: [PATCH] Refactor parameter types: change some String parameters to traits (#61) * Refactor parameter types: change some String parameters to traits --- cli/src/ldap_opt.rs | 4 +++- client/src/addirsync.rs | 6 +++--- client/src/lib.rs | 5 +++-- client/src/search.rs | 6 +++--- client/src/syncrepl.rs | 6 +++--- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/cli/src/ldap_opt.rs b/cli/src/ldap_opt.rs index b52baff..663d72f 100644 --- a/cli/src/ldap_opt.rs +++ b/cli/src/ldap_opt.rs @@ -12,6 +12,8 @@ impl Default for SyncRequestMode { } */ +use url::Url; + #[derive(Debug, clap::Subcommand)] enum LdapAction { /// Search a directory server @@ -58,7 +60,7 @@ struct LdapOpt { verbose: bool, #[clap(short = 'H', long = "url")] - url: url::Url, + url: Url, #[clap(short = 'j', long = "json")] json: bool, diff --git a/client/src/addirsync.rs b/client/src/addirsync.rs index 8dec196..1f4a7bd 100644 --- a/client/src/addirsync.rs +++ b/client/src/addirsync.rs @@ -18,9 +18,9 @@ pub struct LdapSyncRepl { impl LdapClient { #[tracing::instrument(level = "debug", skip_all)] - pub async fn ad_dirsync( + pub async fn ad_dirsync>( &mut self, - basedn: String, + basedn: S, cookie: Option>, ) -> crate::LdapResult { let msgid = self.get_next_msgid(); @@ -28,7 +28,7 @@ impl LdapClient { let msg = LdapMsg { msgid, op: LdapOp::SearchRequest(LdapSearchRequest { - base: basedn, + base: basedn.into(), scope: LdapSearchScope::Subtree, aliases: LdapDerefAliases::Never, sizelimit: 0, diff --git a/client/src/lib.rs b/client/src/lib.rs index b97e81c..7e46848 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -487,7 +487,8 @@ impl LdapClient { } #[tracing::instrument(level = "debug", skip_all)] - pub async fn bind(&mut self, dn: String, pw: String) -> LdapResult<()> { + pub async fn bind>(&mut self, dn: S, pw: S) -> LdapResult<()> { + let dn = dn.into(); info!(%dn); let msgid = self.get_next_msgid(); @@ -495,7 +496,7 @@ impl LdapClient { msgid, op: LdapOp::BindRequest(LdapBindRequest { dn, - cred: LdapBindCred::Simple(pw), + cred: LdapBindCred::Simple(pw.into()), }), ctrl: vec![], }; diff --git a/client/src/search.rs b/client/src/search.rs index b072f56..8921efe 100644 --- a/client/src/search.rs +++ b/client/src/search.rs @@ -8,9 +8,9 @@ pub struct LdapSearchResult { impl LdapClient { #[tracing::instrument(level = "debug", skip_all)] - pub async fn search( + pub async fn search>( &mut self, - basedn: String, + basedn: S, filter: LdapFilter, ) -> crate::LdapResult { let msgid = self.get_next_msgid(); @@ -18,7 +18,7 @@ impl LdapClient { let msg = LdapMsg { msgid, op: LdapOp::SearchRequest(LdapSearchRequest { - base: basedn, + base: basedn.into(), scope: LdapSearchScope::Subtree, aliases: LdapDerefAliases::Never, sizelimit: 0, diff --git a/client/src/syncrepl.rs b/client/src/syncrepl.rs index f890b1b..6fefe32 100644 --- a/client/src/syncrepl.rs +++ b/client/src/syncrepl.rs @@ -46,9 +46,9 @@ pub enum LdapSyncRepl { impl LdapClient { #[tracing::instrument(level = "debug", skip_all)] - pub async fn syncrepl( + pub async fn syncrepl>( &mut self, - basedn: String, + basedn: S, filter: LdapFilter, cookie: Option>, mode: SyncRequestMode, @@ -58,7 +58,7 @@ impl LdapClient { let msg = LdapMsg { msgid, op: LdapOp::SearchRequest(LdapSearchRequest { - base: basedn, + base: basedn.into(), scope: LdapSearchScope::Subtree, aliases: LdapDerefAliases::Never, sizelimit: 0,