Be calm clippy (#1015)

This commit is contained in:
Firstyear 2022-09-05 23:00:48 +10:00 committed by GitHub
parent aa07019b4d
commit a7ce5baf0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 123 additions and 90 deletions

View file

@ -3,12 +3,13 @@
#![deny(clippy::todo)]
#![deny(clippy::unimplemented)]
#![deny(clippy::unwrap_used)]
#![deny(clippy::expect_used)]
#![deny(clippy::panic)]
#![deny(clippy::unreachable)]
#![deny(clippy::await_holding_lock)]
#![deny(clippy::needless_pass_by_value)]
#![deny(clippy::trivially_copy_pass_by_ref)]
// We allow expect since it forces good error messages at the least.
#![allow(clippy::expect_used)]
#[macro_use]
extern crate tracing;

View file

@ -3,12 +3,13 @@
#![deny(clippy::todo)]
#![deny(clippy::unimplemented)]
#![deny(clippy::unwrap_used)]
#![deny(clippy::expect_used)]
#![deny(clippy::panic)]
#![deny(clippy::unreachable)]
#![deny(clippy::await_holding_lock)]
#![deny(clippy::needless_pass_by_value)]
#![deny(clippy::trivially_copy_pass_by_ref)]
// We allow expect since it forces good error messages at the least.
#![allow(clippy::expect_used)]
use clap::Parser;
use kanidm_cli::KanidmClientParser;

View file

@ -478,8 +478,7 @@ impl AccountCredential {
ClientErrorHttp(status_code, error, _kopid) => {
eprintln!(
"Error completing command: HTTP{} - {:?}",
status_code,
error.unwrap()
status_code, error
);
}
_ => error!("Error starting use_reset_token -> {:?}", e),
@ -496,7 +495,13 @@ impl AccountCredential {
.await
{
Ok(cuintent_token) => {
let mut url = Url::parse(client.get_url()).expect("Invalid server url.");
let mut url = match Url::parse(client.get_url()) {
Ok(u) => u,
Err(e) => {
error!("Unable to parse url - {:?}", e);
return;
}
};
url.set_path("/ui/reset");
url.query_pairs_mut()
.append_pair("token", cuintent_token.token.as_str());
@ -666,7 +671,7 @@ async fn totp_enroll_prompt(session_token: &CUSessionToken, client: &KanidmClien
}
})
.interact_text()
.unwrap();
.expect("Failed to interact with interactive session");
// cancel, submit the reg cancel.
let totp_chal = match input.trim().parse::<u32>() {
@ -722,7 +727,7 @@ async fn totp_enroll_prompt(session_token: &CUSessionToken, client: &KanidmClien
.items(&items)
.default(0)
.interact()
.unwrap();
.expect("Failed to interact with interactive session");
match selection {
1 => {
@ -801,7 +806,7 @@ async fn passkey_enroll_prompt(session_token: &CUSessionToken, client: &KanidmCl
.with_prompt("\nEnter a label for this Passkey # ")
.allow_empty(false)
.interact_text()
.unwrap();
.expect("Failed to interact with interactive session");
match client
.idm_account_credential_update_passkey_finish(session_token, label, rego)
@ -814,56 +819,6 @@ async fn passkey_enroll_prompt(session_token: &CUSessionToken, client: &KanidmCl
};
}
// For webauthn later
/*
AccountCredential::RegisterWebauthn(acsopt) => {
let client = acsopt.copt.to_client().await;
let (session, chal) = match client
.idm_account_primary_credential_register_webauthn(
acsopt.aopts.account_id.as_str(),
acsopt.tag.as_str(),
)
.await
{
Ok(v) => v,
Err(e) => {
error!("Error Starting Registration -> {:?}", e);
return;
}
};
let mut wa = WebauthnAuthenticator::new(U2FHid::new());
eprintln!("Your authenticator will now flash for you to interact with.");
let rego = match wa.do_registration(client.get_origin(), chal) {
Ok(rego) => rego,
Err(e) => {
error!("Error Signing -> {:?}", e);
return;
}
};
match client
.idm_account_primary_credential_complete_webuthn_registration(
acsopt.aopts.account_id.as_str(),
rego,
session,
)
.await
{
Ok(()) => {
println!("Webauthn token registration success.");
}
Err(e) => {
error!("Error Completing -> {:?}", e);
}
}
}
*/
fn display_status(status: CUStatus) {
let CUStatus {
spn,
@ -921,7 +876,7 @@ async fn credential_update_exec(
}
})
.interact_text()
.unwrap();
.expect("Failed to interact with interactive session");
// Get action
let action = match CUAction::from_str(&input) {
@ -950,11 +905,11 @@ async fn credential_update_exec(
let password_a = Password::new()
.with_prompt("New password")
.interact()
.unwrap();
.expect("Failed to interact with interactive session");
let password_b = Password::new()
.with_prompt("Confirm password")
.interact()
.unwrap();
.expect("Failed to interact with interactive session");
if password_a != password_b {
eprintln!("Passwords do not match");
@ -980,7 +935,7 @@ async fn credential_update_exec(
if Confirm::new()
.with_prompt("Do you want to remove your totp?")
.interact()
.unwrap()
.expect("Failed to interact with interactive session")
{
if let Err(e) = client
.idm_account_credential_update_remove_totp(&session_token)
@ -1022,7 +977,7 @@ async fn credential_update_exec(
if Confirm::new()
.with_prompt("Do you want to remove your primary credential?")
.interact()
.unwrap()
.expect("Failed to interact with interactive session")
{
if let Err(e) = client
.idm_account_credential_update_primary_remove(&session_token)
@ -1068,7 +1023,7 @@ async fn credential_update_exec(
})
.allow_empty(true)
.interact_text()
.unwrap();
.expect("Failed to interact with interactive session");
// Remeber, if it's NOT a valid uuid, it must have been empty as a termination.
if let Ok(uuid) = Uuid::parse_str(&uuid_s) {
@ -1092,7 +1047,7 @@ async fn credential_update_exec(
if Confirm::new()
.with_prompt("Do you want to commit your changes?")
.interact()
.unwrap()
.expect("Failed to interact with interactive session")
{
if let Err(e) = client
.idm_account_credential_update_commit(&session_token)

View file

@ -47,7 +47,7 @@ async fn main() {
None => client_builder,
};
let ca_path = opt.ca_path.as_ref().map(|p| p.to_str()).flatten();
let ca_path = opt.ca_path.as_ref().and_then(|p| p.to_str());
let client_builder = match ca_path {
Some(p) => client_builder
.add_root_certificate_filepath(p)

View file

@ -1475,6 +1475,7 @@ impl<'a> AccessControlsTransaction<'a> for AccessControlsReadTransaction<'a> {
// =========================================================================
impl AccessControls {
#![allow(clippy::expect_used)]
pub fn new() -> Self {
AccessControls {
inner: CowCell::new(AccessControlsInner {
@ -1483,12 +1484,8 @@ impl AccessControls {
acps_modify: Vec::new(),
acps_delete: Vec::new(),
}),
/*
acp_related_search_cache: ARCache::new_size(
ACP_RELATED_SEARCH_CACHE_MAX,
ACP_RELATED_SEARCH_CACHE_LOCAL,
),
*/
// Allow the expect, if this fails it reperesents a programming/development
// failure.
acp_resolve_filter_cache: ARCacheBuilder::new()
.set_size(ACP_RESOLVE_FILTER_CACHE_MAX, ACP_RESOLVE_FILTER_CACHE_LOCAL)
.set_reader_quiesce(true)

View file

@ -407,7 +407,7 @@ fn from_vec_dbval1(attr_val: Vec<DbValueV1>) -> Result<DbValueSetV2, OperationEr
}
impl DbEntry {
pub(crate) fn to_v2(self) -> Result<Self, OperationError> {
pub(crate) fn convert_to_v2(self) -> Result<Self, OperationError> {
if let DbEntryVers::V1(dbe) = self.ent {
dbe.attrs
.into_iter()

View file

@ -865,7 +865,7 @@ impl IdlSqliteWriteTransaction {
admin_error!(?e, "Serde CBOR Error");
OperationError::SerdeCborError
})
.and_then(|dbe: DbEntry| dbe.to_v2())
.and_then(|dbe: DbEntry| dbe.convert_to_v2())
.and_then(|dbe| {
serde_json::to_vec(&dbe)
.map(|data| IdRawEntry { id: raw.id, data })

View file

@ -1494,7 +1494,7 @@ impl<'a> BackendWriteTransaction<'a> {
// Migrate any v1 entries to v2 if needed.
let dbentries = dbentries
.into_iter()
.map(|dbe| dbe.to_v2())
.map(|dbe| dbe.convert_to_v2())
.collect::<Result<Vec<_>, _>>()?;
// Now, we setup all the entries with new ids.

View file

@ -1782,8 +1782,9 @@ impl<VALID, STATE> Entry<VALID, STATE> {
let r = vs.insert_checked(value);
debug_assert!(r.is_ok());
} else {
#[allow(clippy::expect_used)]
let vs = valueset::from_value_iter(std::iter::once(value))
.expect("Unable to fail - not empty, and only one type!");
.expect("Unable to fail - non-zero iter, and single value type!");
self.attrs.insert(AttrString::from(attr), vs);
}
// Doesn't matter if it already exists, equality will replace.

View file

@ -163,6 +163,9 @@ pub struct CredentialUpdateSessionStatus {
mfaregstate: MfaRegStateStatus,
}
// We allow Into here because CUStatus is foreign so it's impossible for us to implement From
// in a valid manner
#[allow(clippy::from_over_into)]
impl Into<CUStatus> for CredentialUpdateSessionStatus {
fn into(self) -> CUStatus {
CUStatus {

View file

@ -33,6 +33,9 @@ impl IntervalActor {
});
}
// Allow this because result is the only way to map and ? to bubble up, but we aren't
// returning an op-error here because this is in early start up.
#[allow(clippy::result_unit_err)]
pub fn start_online_backup(
server: &'static QueryServerReadV1,
cfg: &OnlineBackup,

View file

@ -111,8 +111,9 @@ impl State {
assert!(r.is_ok());
// Reject if it fails?
} else {
#[allow(clippy::expect_used)]
let vs = valueset::from_value_iter(std::iter::once(value.as_ref().clone()))
.expect("Unable to fail - not empty, and only one type!");
.expect("Unable to fail - always single value, and only one type!");
attrs.insert(attr.clone(), vs);
}
}

View file

@ -1366,12 +1366,6 @@ impl Value {
}
}
pub fn to_partialvalue(&self) -> PartialValue {
// Match on self to become a partialvalue.
// self.pv.clone()
unimplemented!();
}
pub fn to_utf8(self) -> Option<String> {
match self {
Value::Utf8(s) => Some(s),

View file

@ -49,8 +49,10 @@ impl ValueSetAddress {
.collect();
Ok(Box::new(ValueSetAddress { set }))
}
}
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
impl FromIterator<Address> for Option<Box<ValueSetAddress>> {
fn from_iter<T>(iter: T) -> Option<Box<ValueSetAddress>>
where
T: IntoIterator<Item = Address>,
{
@ -215,7 +217,10 @@ impl ValueSetEmailAddress {
}
}
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and tuples are always foreign.
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<ValueSetEmailAddress>>
where
T: IntoIterator<Item = (String, bool)>,
{

View file

@ -28,7 +28,10 @@ impl ValueSetPrivateBinary {
Ok(Box::new(ValueSetPrivateBinary { set }))
}
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and vec is foreign
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<ValueSetPrivateBinary>>
where
T: IntoIterator<Item = Vec<u8>>,
{
@ -157,7 +160,10 @@ impl ValueSetPublicBinary {
Ok(Box::new(ValueSetPublicBinary { map }))
}
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and tuples are always foreign.
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<ValueSetPublicBinary>>
where
T: IntoIterator<Item = (String, Vec<u8>)>,
{

View file

@ -25,6 +25,9 @@ impl ValueSetBool {
Ok(Box::new(ValueSetBool { set }))
}
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and bool is foreign.
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
where
T: IntoIterator<Item = bool>,

View file

@ -34,8 +34,10 @@ impl ValueSetCid {
.collect();
Ok(Box::new(ValueSetCid { set }))
}
}
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
impl FromIterator<Cid> for Option<Box<ValueSetCid>> {
fn from_iter<T>(iter: T) -> Option<Box<ValueSetCid>>
where
T: IntoIterator<Item = Cid>,
{

View file

@ -43,6 +43,9 @@ impl ValueSetCredential {
Ok(Box::new(ValueSetCredential { map }))
}
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and tuples are always foreign.
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
where
T: IntoIterator<Item = (String, Credential)>,
@ -214,6 +217,9 @@ impl ValueSetIntentToken {
Ok(Box::new(ValueSetIntentToken { map }))
}
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and tuples are always foreign.
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
where
T: IntoIterator<Item = (String, IntentTokenState)>,
@ -375,6 +381,9 @@ impl ValueSetPasskey {
Ok(Box::new(ValueSetPasskey { map }))
}
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and tuples are always foreign.
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
where
T: IntoIterator<Item = (Uuid, String, PasskeyV4)>,
@ -531,6 +540,9 @@ impl ValueSetDeviceKey {
Ok(Box::new(ValueSetDeviceKey { map }))
}
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and tuples are always foreign.
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
where
T: IntoIterator<Item = (Uuid, String, DeviceKeyV4)>,

View file

@ -33,6 +33,9 @@ impl ValueSetDateTime {
Ok(Box::new(ValueSetDateTime { set }))
}
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and offset date time is foreign
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
where
T: IntoIterator<Item = OffsetDateTime>,

View file

@ -27,6 +27,9 @@ impl ValueSetIname {
Ok(Box::new(ValueSetIname { set }))
}
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and str is foreign
#[allow(clippy::should_implement_trait)]
pub fn from_iter<'a, T>(iter: T) -> Option<Box<Self>>
where
T: IntoIterator<Item = &'a str>,

View file

@ -26,7 +26,9 @@ impl ValueSetIndex {
Ok(Box::new(ValueSetIndex { set }))
}
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
// We need to allow this, because there seems to be a bug using it fromiterator in entry.rs
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<ValueSetIndex>>
where
T: IntoIterator<Item = IndexType>,
{

View file

@ -27,6 +27,9 @@ impl ValueSetIutf8 {
Ok(Box::new(ValueSetIutf8 { set }))
}
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and str is foreign.
#[allow(clippy::should_implement_trait)]
pub fn from_iter<'a, T>(iter: T) -> Option<Box<Self>>
where
T: IntoIterator<Item = &'a str>,

View file

@ -29,6 +29,9 @@ impl ValueSetJsonFilter {
Ok(Box::new(ValueSetJsonFilter { set }))
}
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and protofilter is foreign.
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
where
T: IntoIterator<Item = ProtoFilter>,

View file

@ -26,6 +26,9 @@ impl ValueSetNsUniqueId {
Ok(Box::new(ValueSetNsUniqueId { set }))
}
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and String is foreign.
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
where
T: IntoIterator<Item = String>,

View file

@ -32,6 +32,9 @@ impl ValueSetOauthScope {
Ok(Box::new(ValueSetOauthScope { set }))
}
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and String is foreign.
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
where
T: IntoIterator<Item = String>,
@ -178,6 +181,9 @@ impl ValueSetOauthScopeMap {
Ok(Box::new(ValueSetOauthScopeMap { map }))
}
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and tuples are always foreign.
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
where
T: IntoIterator<Item = (Uuid, BTreeSet<String>)>,

View file

@ -25,6 +25,9 @@ impl ValueSetRestricted {
Ok(Box::new(ValueSetRestricted { set }))
}
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and String is foreign.
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
where
T: IntoIterator<Item = String>,

View file

@ -25,6 +25,9 @@ impl ValueSetSecret {
Ok(Box::new(ValueSetSecret { set }))
}
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and String is foreign.
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
where
T: IntoIterator<Item = String>,

View file

@ -26,6 +26,9 @@ impl ValueSetSpn {
Ok(Box::new(ValueSetSpn { set }))
}
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and tuples are always foreign.
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
where
T: IntoIterator<Item = (String, String)>,

View file

@ -28,6 +28,9 @@ impl ValueSetSshKey {
Ok(Box::new(ValueSetSshKey { map }))
}
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and tuples are always foreign.
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
where
T: IntoIterator<Item = (String, String)>,

View file

@ -25,8 +25,10 @@ impl ValueSetSyntax {
let set = set.map_err(|()| OperationError::InvalidValueState)?;
Ok(Box::new(ValueSetSyntax { set }))
}
}
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
impl FromIterator<SyntaxType> for Option<Box<ValueSetSyntax>> {
fn from_iter<T>(iter: T) -> Option<Box<ValueSetSyntax>>
where
T: IntoIterator<Item = SyntaxType>,
{

View file

@ -25,6 +25,9 @@ impl ValueSetUint32 {
Ok(Box::new(ValueSetUint32 { set }))
}
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and u32 is foreign.
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
where
T: IntoIterator<Item = u32>,

View file

@ -25,6 +25,9 @@ impl ValueSetUrl {
Ok(Box::new(ValueSetUrl { set }))
}
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and Url is foreign.
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
where
T: IntoIterator<Item = Url>,

View file

@ -28,6 +28,9 @@ impl ValueSetUuid {
Ok(Box::new(ValueSetUuid { set }))
}
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and uuid is foreign.
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
where
T: IntoIterator<Item = Uuid>,
@ -170,6 +173,9 @@ impl ValueSetRefer {
Ok(Box::new(ValueSetRefer { set }))
}
// We need to allow this, because rust doesn't allow us to impl FromIterator on foreign
// types, and uuid is foreign.
#[allow(clippy::should_implement_trait)]
pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
where
T: IntoIterator<Item = Uuid>,