diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2025-01-26 22:27:54 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2025-01-26 22:27:54 +0100 |
| commit | 749c892b9cfc6b5b9937b4c3badc713101542fe1 (patch) | |
| tree | 5cba0e9bc7a694e9939bcdb2281fba599df5db04 /server/src/auth.rs | |
| parent | 790e1af298aa7c9f39fb7cfe15615307ed87d597 (diff) | |
Use anyhow to reduce enum error types and map_err
Diffstat (limited to 'server/src/auth.rs')
| -rw-r--r-- | server/src/auth.rs | 35 |
1 files changed, 6 insertions, 29 deletions
diff --git a/server/src/auth.rs b/server/src/auth.rs index 919dd51..edd794c 100644 --- a/server/src/auth.rs +++ b/server/src/auth.rs @@ -302,22 +302,9 @@ async fn setup_ldap( Ok(ret) } -#[derive(Debug)] -#[allow(dead_code)] -enum LdapOrSqlError { - LdapError(ldap3::LdapError), - SqlError(sqlx::Error), -} - #[cfg_attr(test, allow(dead_code))] -async fn sync_ldap( - ldap_state: &LdapState, - config: &AuthConfig<'_>, - db: &Db, -) -> Result<(), LdapOrSqlError> { - let mut ldap = setup_ldap(ldap_state, config) - .map_err(LdapOrSqlError::LdapError) - .await?; +async fn sync_ldap(ldap_state: &LdapState, config: &AuthConfig<'_>, db: &Db) -> anyhow::Result<()> { + let mut ldap = setup_ldap(ldap_state, config).await?; let (entries, _) = ldap .search( &config.ldap_users, @@ -325,10 +312,8 @@ async fn sync_ldap( &config.ldap_filter, vec!["uid"], ) - .map_err(LdapOrSqlError::LdapError) .await? - .success() - .map_err(LdapOrSqlError::LdapError)?; + .success()?; let mut tx = db.begin().await.unwrap(); @@ -391,17 +376,12 @@ async fn sync_ldap( query_builder.push(")"); } - query_builder - .build() - .execute(&mut *tx) - .map_err(LdapOrSqlError::SqlError) - .await?; + query_builder.build().execute(&mut *tx).await?; } for pair in updated_users { sqlx::query!("UPDATE users SET dn=? WHERE id=?", pair.1, pair.0) .execute(&mut *tx) - .map_err(LdapOrSqlError::SqlError) .await?; } @@ -414,13 +394,10 @@ async fn sync_ldap( query = query.bind(id); } - query - .execute(&mut *tx) - .map_err(LdapOrSqlError::SqlError) - .await?; + query.execute(&mut *tx).await?; } - tx.commit().map_err(LdapOrSqlError::SqlError).await?; + tx.commit().await?; Ok(()) } |
