Skip to content

Commit 2761e2b

Browse files
committed
Clippy lints
1 parent 274ff08 commit 2761e2b

File tree

26 files changed

+152
-154
lines changed

26 files changed

+152
-154
lines changed

dropshot-authorization-header/src/basic.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ impl SharedExtractor for BasicAuth {
5050
header
5151
.to_str()
5252
.map(|s| s.to_string())
53-
.map_err(|err| {
54-
tracing::info!("Failed to turn Authorization header into string");
55-
err
53+
.inspect_err(|err| {
54+
tracing::info!(?err, "Failed to turn Authorization header into string");
5655
})
5756
.ok()
5857
});
@@ -64,18 +63,17 @@ impl SharedExtractor for BasicAuth {
6463
match parts {
6564
Some(("Basic", token)) => BASE64_STANDARD
6665
.decode(token)
67-
.map_err(|err| {
68-
tracing::info!("Failed to decode basic auth header");
69-
err
66+
.inspect_err(|err| {
67+
tracing::info!(?err, "Failed to decode basic auth header");
7068
})
7169
.ok()
7270
.and_then(|decoded| {
7371
String::from_utf8(decoded)
74-
.map_err(|err| {
72+
.inspect_err(|err| {
7573
tracing::info!(
74+
?err,
7675
"Failed to interpret decoded bytes from authorization header"
7776
);
78-
err
7977
})
8078
.ok()
8179
})

dropshot-authorization-header/src/bearer.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl BearerAuth {
1717
}
1818

1919
pub fn key(&self) -> Option<&str> {
20-
self.0.as_ref().map(|s| s.as_str())
20+
self.0.as_deref()
2121
}
2222

2323
pub fn consume(self) -> Option<String> {
@@ -43,9 +43,8 @@ impl SharedExtractor for BearerAuth {
4343
header
4444
.to_str()
4545
.map(|s| s.to_string())
46-
.map_err(|err| {
47-
tracing::info!("Failed to turn Authorization header into string");
48-
err
46+
.inspect_err(|err| {
47+
tracing::info!(?err, "Failed to turn Authorization header into string");
4948
})
5049
.ok()
5150
});

v-api-installer/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn migrations() -> Vec<Box<dyn Migration<Pg>>> {
1717
}
1818

1919
pub fn run_migrations(url: &str) {
20-
let mut conn = db_conn(&url);
20+
let mut conn = db_conn(url);
2121
run_migrations_on_conn(&mut conn);
2222
}
2323

v-api-permission-derive/src/lib.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ impl Parse for ContractSettings {
168168

169169
let kind = settings
170170
.iter()
171+
.find(|&s| s.name == "kind")
171172
.cloned()
172-
.find(|s| s.name == "kind")
173173
.ok_or_else(|| Error::new(span, "Expand must contain a \"kind\" setting"))?;
174174

175175
Ok(ContractSettings {
@@ -201,8 +201,8 @@ impl Parse for ExpandSettings {
201201

202202
let kind = settings
203203
.iter()
204+
.find(|&s| s.name == "kind")
204205
.cloned()
205-
.find(|s| s.name == "kind")
206206
.ok_or_else(|| Error::new(span, "Expand must contain a \"kind\" setting"))?;
207207

208208
Ok(ExpandSettings {
@@ -214,8 +214,8 @@ impl Parse for ExpandSettings {
214214
},
215215
variant: settings
216216
.iter()
217+
.find(|&s| s.name == "variant")
217218
.cloned()
218-
.find(|s| s.name == "variant")
219219
.expect("Expand must contain a \"variant\" setting")
220220
.value,
221221
source: settings.iter().find(|s| s.name == "source").map(|s| {
@@ -253,13 +253,13 @@ impl Parse for ScopeSettings {
253253
Ok(ScopeSettings {
254254
from: settings
255255
.iter()
256+
.find(|&v| v.name == "from")
256257
.cloned()
257-
.find(|v| v.name == "from")
258258
.map(|v| v.value),
259259
to: settings
260260
.iter()
261+
.find(|&v| v.name == "to")
261262
.cloned()
262-
.find(|v| v.name == "to")
263263
.map(|v| v.value),
264264
})
265265
}
@@ -313,12 +313,10 @@ pub fn v_api(attr: TokenStream, input: TokenStream) -> TokenStream {
313313
#as_scope_out
314314
#permission_storage_out
315315
}
316-
.into()
317316
}
318317
_ => quote_spanned! {
319318
input_span => compile_error!("v_api may only be applied to enums");
320-
}
321-
.into(),
319+
},
322320
};
323321

324322
let from = from_system_permission_tokens(&attr.source, &input.ident);
@@ -734,7 +732,7 @@ fn as_scope_trait_tokens(
734732
) -> proc_macro2::TokenStream {
735733
let as_scope_mapping = scope_settings.iter().filter_map(|(variant, settings)| {
736734
settings.to.as_ref().map(|to| {
737-
let fields = if variant.fields.len() > 0 {
735+
let fields = if !variant.fields.is_empty() {
738736
let mut fields = quote! {};
739737
variant
740738
.fields
@@ -802,7 +800,6 @@ fn as_scope_trait_tokens(
802800
}
803801
}
804802
}
805-
.into()
806803
}
807804

808805
fn permission_storage_trait_tokens(
@@ -844,7 +841,7 @@ fn permission_storage_contract_tokens(
844841
.then(|| set_name.clone()),
845842
);
846843

847-
let fields = if variant.fields.len() > 0 && setting.kind != ContractKind::Drop {
844+
let fields = if !variant.fields.is_empty() && setting.kind != ContractKind::Drop {
848845
let mut fields = quote! {};
849846
variant
850847
.fields

v-api/src/authn/jwt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl Claims {
7979
scp: scope,
8080
exp: expires_at.timestamp(),
8181
nbf: Utc::now().timestamp(),
82-
jti: id.unwrap_or_else(|| TypedUuid::new_v4()),
82+
jti: id.unwrap_or_else(TypedUuid::new_v4),
8383
}
8484
}
8585
}
@@ -106,8 +106,8 @@ impl Jwt {
106106

107107
// The only JWKs supported are those that are available in the server context
108108
let jwk = ctx.jwks().await.find(&kid).ok_or(JwtError::NoMatchingKey)?;
109-
let (key, algorithm) = DecodingKey::from_jwk(&jwk)
110-
.map(|key| (key, Jwt::algo(&jwk)))
109+
let (key, algorithm) = DecodingKey::from_jwk(jwk)
110+
.map(|key| (key, Jwt::algo(jwk)))
111111
.map_err(JwtError::InvalidJwk)?;
112112

113113
tracing::trace!(?jwk, ?algorithm, "Kid matched known decoding key");

v-api/src/authn/key.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl RawKey {
5252
pub async fn sign(self, signer: &dyn Signer) -> Result<SignedKey, ApiKeyError> {
5353
let signature = hex::encode(
5454
signer
55-
.sign(&self.clear.expose_secret())
55+
.sign(self.clear.expose_secret())
5656
.await
5757
.map_err(ApiKeyError::Signing)?,
5858
);
@@ -68,7 +68,7 @@ impl RawKey {
6868
{
6969
let signature = hex::decode(signature)?;
7070
if verifier
71-
.verify(&self.clear.expose_secret(), &signature)
71+
.verify(self.clear.expose_secret(), &signature)
7272
.verified
7373
{
7474
return Ok(());

v-api/src/authn/mod.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl From<AuthError> for HttpError {
117117
#[derive(Debug, Error)]
118118
pub enum SigningKeyError {
119119
#[error("Cloud signing failed: {0}")]
120-
CloudKmsError(#[from] CloudKmsError),
120+
CloudKmsError(#[from] Box<CloudKmsError>),
121121
#[error("Failed to immediately verify generated signature")]
122122
GeneratedInvalidSignature,
123123
#[error("Failed to parse public key: {0}")]
@@ -288,16 +288,20 @@ impl Signer for CloudKmsSigningKey {
288288
let signature = match response {
289289
Ok((_, response)) => {
290290
tracing::info!("Library deserialization succeeded");
291-
response.signature.ok_or(CloudKmsError::MissingSignature)
291+
response
292+
.signature
293+
.ok_or_else(|| Box::new(CloudKmsError::MissingSignature))
292294
}
293295
Err(google_cloudkms1::Error::JsonDecodeError(body, _)) => {
294296
tracing::info!("Using fallback deserialization");
295297
serde_json::from_str::<CloudKmsSignatureResponse>(&body)
296-
.map_err(|err| CloudKmsError::FailedToDeserialize(err))
298+
.map_err(CloudKmsError::FailedToDeserialize)
299+
.map_err(Box::new)
297300
.and_then(|resp| {
298-
let decoded = BASE64_STANDARD
301+
BASE64_STANDARD
299302
.decode(&resp.signature)
300303
.map_err(CloudKmsError::FailedToDecodeSignature)
304+
.map_err(Box::new)
301305
.and_then(|decoded| {
302306
let check = crc32c(&decoded);
303307
let check_valid = resp
@@ -309,14 +313,12 @@ impl Signer for CloudKmsSigningKey {
309313
if check_valid {
310314
Ok(decoded)
311315
} else {
312-
Err(CloudKmsError::CorruptedSignature)
316+
Err(Box::new(CloudKmsError::CorruptedSignature))
313317
}
314-
});
315-
316-
decoded
318+
})
317319
})
318320
}
319-
Err(err) => Err(CloudKmsError::from(err)),
321+
Err(err) => Err(Box::new(CloudKmsError::from(err))),
320322
}?;
321323

322324
Ok(signature)
@@ -381,7 +383,7 @@ impl AsymmetricKey {
381383
pub async fn private_key(&self) -> Result<RsaPrivateKey, SigningKeyError> {
382384
Ok(match self {
383385
AsymmetricKey::LocalSigner { private, .. } => {
384-
RsaPrivateKey::from_pkcs8_pem(&private).unwrap()
386+
RsaPrivateKey::from_pkcs8_pem(private).unwrap()
385387
}
386388
_ => unimplemented!(),
387389
})
@@ -390,7 +392,7 @@ impl AsymmetricKey {
390392
pub fn public_key(&self) -> Result<RsaPublicKey, SigningKeyError> {
391393
Ok(match self {
392394
AsymmetricKey::LocalVerifier { public, .. } => {
393-
RsaPublicKey::from_public_key_pem(&public)?
395+
RsaPublicKey::from_public_key_pem(public)?
394396
}
395397
AsymmetricKey::LocalSigner { .. } => Err(SigningKeyError::KeyDoesNotSupportFunction)?,
396398
AsymmetricKey::CkmsVerifier { .. } => {
@@ -405,12 +407,16 @@ impl AsymmetricKey {
405407
)
406408
.doit()
407409
.await
408-
.map_err(|err| CloudKmsError::from(err))?
410+
.map_err(CloudKmsError::from)
411+
.map_err(Box::new)?
409412
.1,
410413
)
411414
})?;
412415

413-
let pem = public_key.pem.ok_or(CloudKmsError::MissingPem)?;
416+
let pem = public_key
417+
.pem
418+
.ok_or(CloudKmsError::MissingPem)
419+
.map_err(Box::new)?;
414420
RsaPublicKey::from_public_key_pem(&pem)?
415421
}
416422
AsymmetricKey::CkmsSigner { .. } => Err(SigningKeyError::KeyDoesNotSupportFunction)?,
@@ -420,7 +426,7 @@ impl AsymmetricKey {
420426
pub fn as_signer(&self) -> Result<Arc<dyn Signer>, SigningKeyError> {
421427
Ok(match self {
422428
AsymmetricKey::LocalSigner { private, .. } => {
423-
let private_key = RsaPrivateKey::from_pkcs8_pem(&private).unwrap();
429+
let private_key = RsaPrivateKey::from_pkcs8_pem(private).unwrap();
424430
let signing_key = SigningKey::new(private_key);
425431

426432
Arc::new(LocalSigningKey { signing_key })

v-api/src/context/auth.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@ where
5858
registration_caller: Caller {
5959
id: "00000000-0000-4000-8000-000000000001".parse().unwrap(),
6060
permissions: vec![
61-
VPermission::CreateApiUser.into(),
62-
VPermission::GetApiUsersAll.into(),
63-
VPermission::ManageApiUsersAll.into(),
64-
VPermission::GetApiKeysAll.into(),
65-
VPermission::CreateGroup.into(),
66-
VPermission::GetGroupsAll.into(),
67-
VPermission::CreateMapper.into(),
68-
VPermission::GetMappersAll.into(),
69-
VPermission::GetOAuthClientsAll.into(),
70-
VPermission::CreateAccessToken.into(),
61+
VPermission::CreateApiUser,
62+
VPermission::GetApiUsersAll,
63+
VPermission::ManageApiUsersAll,
64+
VPermission::GetApiKeysAll,
65+
VPermission::CreateGroup,
66+
VPermission::GetGroupsAll,
67+
VPermission::CreateMapper,
68+
VPermission::GetMappersAll,
69+
VPermission::GetOAuthClientsAll,
70+
VPermission::CreateAccessToken,
7171
]
7272
.into(),
7373
extensions: HashMap::default(),
@@ -78,26 +78,26 @@ where
7878
keys: verifiers
7979
.iter()
8080
.map(|k| k.as_jwk())
81-
.into_iter()
82-
.collect::<Result<Vec<_>, _>>()?,
81+
.collect::<Result<Vec<_>, _>>()
82+
.map_err(Box::new)?,
8383
},
8484
signers: signers
8585
.iter()
8686
.map(|k| JwtSigner::new(k))
87-
.into_iter()
88-
.collect::<Result<Vec<_>, _>>()?,
87+
.collect::<Result<Vec<_>, _>>()
88+
.map_err(Box::new)?,
8989
},
9090
secrets: SecretContext {
9191
signers: signers
9292
.iter()
9393
.map(|k| k.as_signer())
94-
.into_iter()
95-
.collect::<Result<Vec<_>, _>>()?,
94+
.collect::<Result<Vec<_>, _>>()
95+
.map_err(Box::new)?,
9696
verifiers: verifiers
9797
.iter()
9898
.map(|k| k.as_verifier())
99-
.into_iter()
100-
.collect::<Result<Vec<_>, _>>()?,
99+
.collect::<Result<Vec<_>, _>>()
100+
.map_err(Box::new)?,
101101
},
102102
oauth_providers: HashMap::new(),
103103
})

v-api/src/context/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ where
4343
&self,
4444
id: &TypedUuid<LinkRequestId>,
4545
) -> Result<Option<LinkRequest>, StoreError> {
46-
Ok(LinkRequestStore::get(&*self.storage, id, false, false).await?)
46+
LinkRequestStore::get(&*self.storage, id, false, false).await
4747
}
4848

4949
pub async fn create_link_request_token(

v-api/src/context/magic_link.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,17 @@ where
295295
&self,
296296
signature: &str,
297297
) -> ResourceResult<MagicLinkAttempt, StoreError> {
298-
let mut filter = MagicLinkAttemptFilter::default();
299-
filter.signature = Some(vec![signature.to_string()]);
298+
let filter = MagicLinkAttemptFilter {
299+
signature: Some(vec![signature.to_string()]),
300+
..Default::default()
301+
};
300302
MagicLinkAttemptStore::list(&*self.storage, filter, &ListPagination::latest())
301303
.await
302304
.map(|mut results| results.pop())
303305
.optional()
304306
}
305307

308+
#[allow(clippy::too_many_arguments)]
306309
#[instrument(skip(self, key, signer, redirect_uri, recipient), err(Debug))]
307310
pub async fn send_login_attempt(
308311
&self,

0 commit comments

Comments
 (0)