From dbf476fe5ea2c120dff9a85e552be9f898c69ce7 Mon Sep 17 00:00:00 2001 From: Allan Date: Wed, 1 Nov 2023 01:54:29 -0400 Subject: [PATCH] Remove unused imports and clippy lint (#2276) * Fix unused import errors * Apply clippy get_first lint * Add contributor --------- Co-authored-by: James Hodgkinson --- CONTRIBUTORS.md | 1 + libs/client/src/sync_account.rs | 2 +- libs/crypto/src/lib.rs | 2 +- server/lib/src/credential/mod.rs | 2 +- server/lib/src/idm/authsession.rs | 2 -- server/lib/src/idm/credupdatesession.rs | 6 +++--- server/lib/src/idm/scim.rs | 12 ++++++------ server/lib/src/idm/server.rs | 4 ++-- server/web_ui/login_flows/src/oauth2.rs | 5 +---- tools/cli/src/cli/session.rs | 4 ++-- unix_integration/nss_kanidm/src/lib.rs | 3 --- 11 files changed, 18 insertions(+), 25 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index b33814ca0..617227e34 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -32,6 +32,7 @@ - Samuel Cabrero (scabrero) - philipcristiano - Jianchen Zhao (bolu61) +- Allan Zhang (allan2) ## Acknowledgements diff --git a/libs/client/src/sync_account.rs b/libs/client/src/sync_account.rs index da2b6e507..0806a8dc4 100644 --- a/libs/client/src/sync_account.rs +++ b/libs/client/src/sync_account.rs @@ -40,7 +40,7 @@ impl KanidmClient { format!("/v1/sync_account/{}/_attr/sync_credential_portal", id).as_str(), ) .await - .map(|values: Vec| values.get(0).cloned()) + .map(|values: Vec| values.first().cloned()) } pub async fn idm_sync_account_set_yield_attributes( diff --git a/libs/crypto/src/lib.rs b/libs/crypto/src/lib.rs index 9ca2605e0..e4ec436d0 100644 --- a/libs/crypto/src/lib.rs +++ b/libs/crypto/src/lib.rs @@ -83,7 +83,7 @@ pub enum CryptoError { impl From for CryptoError { fn from(ossl_err: OpenSSLErrorStack) -> Self { error!(?ossl_err); - let code = ossl_err.errors().get(0).map(|e| e.code()).unwrap_or(0); + let code = ossl_err.errors().first().map(|e| e.code()).unwrap_or(0); #[cfg(not(target_family = "windows"))] let result = CryptoError::OpenSSL(code); diff --git a/server/lib/src/credential/mod.rs b/server/lib/src/credential/mod.rs index c6ea20711..9d42e4431 100644 --- a/server/lib/src/credential/mod.rs +++ b/server/lib/src/credential/mod.rs @@ -372,7 +372,7 @@ impl Credential { pub fn try_from_repl_v1(rc: &ReplCredV1) -> Result<(String, Self), OperationError> { match rc { ReplCredV1::TmpWn { tag, set } => { - let m_uuid: Option = set.get(0).map(|v| v.uuid); + let m_uuid: Option = set.first().map(|v| v.uuid); let v_webauthn = set .iter() diff --git a/server/lib/src/idm/authsession.rs b/server/lib/src/idm/authsession.rs index 734864f0d..a54a3bb00 100644 --- a/server/lib/src/idm/authsession.rs +++ b/server/lib/src/idm/authsession.rs @@ -3,7 +3,6 @@ //! factor to assert that the user is legitimate. This also contains some //! support code for asynchronous task execution. use std::collections::BTreeMap; -pub use std::collections::BTreeSet as Set; use std::convert::TryFrom; use std::fmt; use std::time::Duration; @@ -1237,7 +1236,6 @@ impl AuthSession { #[cfg(test)] mod tests { - pub use std::collections::BTreeSet as Set; use std::str::FromStr; use std::time::Duration; diff --git a/server/lib/src/idm/credupdatesession.rs b/server/lib/src/idm/credupdatesession.rs index f67faaec3..7f0444808 100644 --- a/server/lib/src/idm/credupdatesession.rs +++ b/server/lib/src/idm/credupdatesession.rs @@ -372,7 +372,7 @@ impl<'a> IdmServerProxyWriteTransaction<'a> { &[entry], )?; - let eperm = effective_perms.get(0).ok_or_else(|| { + let eperm = effective_perms.first().ok_or_else(|| { error!("Effective Permission check returned no results"); OperationError::InvalidState })?; @@ -485,7 +485,7 @@ impl<'a> IdmServerProxyWriteTransaction<'a> { &[entry], )?; - let eperm = effective_perms.get(0).ok_or_else(|| { + let eperm = effective_perms.first().ok_or_else(|| { admin_error!("Effective Permission check returned no results"); OperationError::InvalidState })?; @@ -2782,7 +2782,7 @@ mod tests { assert!(c_status.passkeys.len() == 1); // Get the UUID of the passkey here. - let pk_uuid = c_status.passkeys.get(0).map(|pkd| pkd.uuid).unwrap(); + let pk_uuid = c_status.passkeys.first().map(|pkd| pkd.uuid).unwrap(); // Commit drop(cutxn); diff --git a/server/lib/src/idm/scim.rs b/server/lib/src/idm/scim.rs index edffb93bf..8733340e7 100644 --- a/server/lib/src/idm/scim.rs +++ b/server/lib/src/idm/scim.rs @@ -251,7 +251,7 @@ impl<'a> IdmServerProxyWriteTransaction<'a> { .get_accesscontrols() .effective_permission_check(&sfe.ident, Some(BTreeSet::default()), &[entry])?; - let eperm = effective_perms.get(0).ok_or_else(|| { + let eperm = effective_perms.first().ok_or_else(|| { admin_error!("Effective Permission check returned no results"); OperationError::InvalidState })?; @@ -382,7 +382,7 @@ impl<'a> IdmServerProxyWriteTransaction<'a> { .get_accesscontrols() .effective_permission_check(&ste.ident, Some(BTreeSet::default()), &[entry])?; - let eperm = effective_perms.get(0).ok_or_else(|| { + let eperm = effective_perms.first().ok_or_else(|| { admin_error!("Effective Permission check returned no results"); OperationError::InvalidState })?; @@ -2153,7 +2153,7 @@ mod tests { // Should be none as the entry was masked by being recycled. .map(|entries| { assert!(entries.len() == 1); - let ent = entries.get(0).unwrap(); + let ent = entries.first().unwrap(); ent.mask_recycled_ts().is_none() }) .unwrap_or(false)); @@ -2348,7 +2348,7 @@ mod tests { // Should be none as the entry was masked by being recycled. .map(|entries| { assert!(entries.len() == 1); - let ent = entries.get(0).unwrap(); + let ent = entries.first().unwrap(); ent.mask_recycled_ts().is_none() }) .unwrap_or(false)); @@ -2432,7 +2432,7 @@ mod tests { // Should be none as the entry was masked by being recycled. .map(|entries| { assert!(entries.len() == 1); - let ent = entries.get(0).unwrap(); + let ent = entries.first().unwrap(); ent.mask_recycled_ts().is_none() }) .unwrap_or(false)); @@ -2447,7 +2447,7 @@ mod tests { // Should be none as the entry was masked by being recycled. .map(|entries| { assert!(entries.len() == 1); - let ent = entries.get(0).unwrap(); + let ent = entries.first().unwrap(); ent.mask_recycled_ts().is_none() }) .unwrap_or(false)); diff --git a/server/lib/src/idm/server.rs b/server/lib/src/idm/server.rs index 14efe35bb..84da52299 100644 --- a/server/lib/src/idm/server.rs +++ b/server/lib/src/idm/server.rs @@ -926,7 +926,7 @@ impl<'a> IdmServerAuthTransaction<'a> { pub fn get_origin(&self) -> &Url { #[allow(clippy::unwrap_used)] - self.webauthn.get_allowed_origins().get(0).unwrap() + self.webauthn.get_allowed_origins().first().unwrap() } #[instrument(level = "trace", skip(self))] @@ -1544,7 +1544,7 @@ impl<'a> IdmServerProxyWriteTransaction<'a> { pub fn get_origin(&self) -> &Url { #[allow(clippy::unwrap_used)] - self.webauthn.get_allowed_origins().get(0).unwrap() + self.webauthn.get_allowed_origins().first().unwrap() } fn check_password_quality( diff --git a/server/web_ui/login_flows/src/oauth2.rs b/server/web_ui/login_flows/src/oauth2.rs index a41e3083f..83fbe29fc 100644 --- a/server/web_ui/login_flows/src/oauth2.rs +++ b/server/web_ui/login_flows/src/oauth2.rs @@ -1,10 +1,7 @@ use gloo::console; use kanidm_proto::constants::uri::{OAUTH2_AUTHORISE, OAUTH2_AUTHORISE_PERMIT}; use kanidm_proto::constants::{APPLICATION_JSON, KOPID}; -pub use kanidm_proto::oauth2::{ - AccessTokenRequest, AccessTokenResponse, AuthorisationRequest, AuthorisationResponse, - CodeChallengeMethod, ErrorResponse, -}; +pub use kanidm_proto::oauth2::{AuthorisationRequest, AuthorisationResponse}; use kanidmd_web_ui_shared::constants::{CONTENT_TYPE, CSS_ALERT_DANGER, URL_OAUTH2}; use kanidmd_web_ui_shared::utils::{do_alert_error, do_footer, window}; use kanidmd_web_ui_shared::{ diff --git a/tools/cli/src/cli/session.rs b/tools/cli/src/cli/session.rs index 1f45546e3..a79d1e475 100644 --- a/tools/cli/src/cli/session.rs +++ b/tools/cli/src/cli/session.rs @@ -259,7 +259,7 @@ async fn process_auth_state( { #[allow(clippy::expect_used)] allowed - .get(0) + .first() .expect("can not fail - bounds already checked.") } _ => { @@ -387,7 +387,7 @@ impl LoginOpt { { #[allow(clippy::expect_used)] mechs - .get(0) + .first() .expect("can not fail - bounds already checked.") } _ => { diff --git a/unix_integration/nss_kanidm/src/lib.rs b/unix_integration/nss_kanidm/src/lib.rs index ef13192b9..4d1cdbb92 100644 --- a/unix_integration/nss_kanidm/src/lib.rs +++ b/unix_integration/nss_kanidm/src/lib.rs @@ -19,6 +19,3 @@ extern crate lazy_static; #[cfg(target_family = "unix")] mod implementation; - -#[cfg(target_family = "unix")] -pub use implementation::*;