Skip to content

Commit

Permalink
Refactor parameter types: change some String parameters to traits (#61)
Browse files Browse the repository at this point in the history
* Refactor parameter types: change some String parameters to traits
  • Loading branch information
kolapapa authored Oct 31, 2024
1 parent 3e0bd7d commit 2972cfd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
4 changes: 3 additions & 1 deletion cli/src/ldap_opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ impl Default for SyncRequestMode {
}
*/

use url::Url;

#[derive(Debug, clap::Subcommand)]
enum LdapAction {
/// Search a directory server
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions client/src/addirsync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ pub struct LdapSyncRepl {

impl LdapClient {
#[tracing::instrument(level = "debug", skip_all)]
pub async fn ad_dirsync(
pub async fn ad_dirsync<S: Into<String>>(
&mut self,
basedn: String,
basedn: S,
cookie: Option<Vec<u8>>,
) -> crate::LdapResult<LdapSyncRepl> {
let msgid = self.get_next_msgid();

let msg = LdapMsg {
msgid,
op: LdapOp::SearchRequest(LdapSearchRequest {
base: basedn,
base: basedn.into(),
scope: LdapSearchScope::Subtree,
aliases: LdapDerefAliases::Never,
sizelimit: 0,
Expand Down
5 changes: 3 additions & 2 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,15 +487,16 @@ impl LdapClient {
}

#[tracing::instrument(level = "debug", skip_all)]
pub async fn bind(&mut self, dn: String, pw: String) -> LdapResult<()> {
pub async fn bind<S: Into<String>>(&mut self, dn: S, pw: S) -> LdapResult<()> {
let dn = dn.into();
info!(%dn);
let msgid = self.get_next_msgid();

let msg = LdapMsg {
msgid,
op: LdapOp::BindRequest(LdapBindRequest {
dn,
cred: LdapBindCred::Simple(pw),
cred: LdapBindCred::Simple(pw.into()),
}),
ctrl: vec![],
};
Expand Down
6 changes: 3 additions & 3 deletions client/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ pub struct LdapSearchResult {

impl LdapClient {
#[tracing::instrument(level = "debug", skip_all)]
pub async fn search(
pub async fn search<S: Into<String>>(
&mut self,
basedn: String,
basedn: S,
filter: LdapFilter,
) -> crate::LdapResult<LdapSearchResult> {
let msgid = self.get_next_msgid();

let msg = LdapMsg {
msgid,
op: LdapOp::SearchRequest(LdapSearchRequest {
base: basedn,
base: basedn.into(),
scope: LdapSearchScope::Subtree,
aliases: LdapDerefAliases::Never,
sizelimit: 0,
Expand Down
6 changes: 3 additions & 3 deletions client/src/syncrepl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ pub enum LdapSyncRepl {

impl LdapClient {
#[tracing::instrument(level = "debug", skip_all)]
pub async fn syncrepl(
pub async fn syncrepl<S: Into<String>>(
&mut self,
basedn: String,
basedn: S,
filter: LdapFilter,
cookie: Option<Vec<u8>>,
mode: SyncRequestMode,
Expand All @@ -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,
Expand Down

0 comments on commit 2972cfd

Please sign in to comment.