Skip to content

Commit 76b4ad9

Browse files
author
Amrith Kumar
committed
fix: update stale license headers and resolve clippy pedantic warnings
- Update 7 files with old 'DynamoDB Open' copyright to 'ExtendDB contributors' - Rename _backend field to backend (resolves underscore-prefix warnings) - Apply clippy auto-fixes: redundant closures, format string variables, unnecessary raw string hashes, missing backtick docs, must_use attributes - Rewrite match-to-let-else patterns (6 instances) - Fix long literal lacking separators in build.rs - Fix Map::default() clarity warning Clippy pedantic count: 504 -> 171 (66% reduction)
1 parent cbea20f commit 76b4ad9

113 files changed

Lines changed: 392 additions & 357 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/auth/src/credential_cache.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl CachedCredentialStore {
122122
) -> Result<(), extenddb_cache::PredicateError> {
123123
let acct = account_id.to_owned();
124124
self.cache
125-
.invalidate_if_value(move |v| v.map(|cred| cred.account_id == acct).unwrap_or(false))
125+
.invalidate_if_value(move |v| v.is_some_and(|cred| cred.account_id == acct))
126126
}
127127

128128
/// Drop every cached credential for `principal_name` in `account_id`.
@@ -140,8 +140,7 @@ impl CachedCredentialStore {
140140
let acct = account_id.to_owned();
141141
let principal = principal_name.to_owned();
142142
self.cache.invalidate_if_value(move |v| {
143-
v.map(|cred| cred.account_id == acct && cred.principal_name == principal)
144-
.unwrap_or(false)
143+
v.is_some_and(|cred| cred.account_id == acct && cred.principal_name == principal)
145144
})
146145
}
147146

crates/auth/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! Authentication and authorization for extenddb.
55
//!
66
//! Defines the `AuthProvider` trait for pluggable auth backends. Ships with
7-
//! `BuiltinAuthProvider` (full SigV4 verification with local credential store).
7+
//! `BuiltinAuthProvider` (full `SigV4` verification with local credential store).
88
99
pub mod cache_registry;
1010
pub mod credential_cache;
@@ -20,7 +20,7 @@ use zeroize::{Zeroize, ZeroizeOnDrop};
2020

2121
/// Auth provider trait — pluggable authentication.
2222
///
23-
/// `BuiltinAuthProvider` performs SigV4 verification.
23+
/// `BuiltinAuthProvider` performs `SigV4` verification.
2424
/// Fix #11: Accept `&HeaderMap` directly to avoid per-request `HashMap` allocation.
2525
#[async_trait::async_trait]
2626
pub trait AuthProvider: Send + Sync {
@@ -102,10 +102,10 @@ pub trait CredentialStore: Send + Sync {
102102
) -> Result<Option<StoredCredential>, DynamoDbError>;
103103
}
104104

105-
/// SigV4 auth provider with local credential store.
105+
/// `SigV4` auth provider with local credential store.
106106
///
107107
/// Parses the `Authorization` header, looks up the access key, decrypts the
108-
/// secret, verifies the SigV4 signature, and validates the request timestamp.
108+
/// secret, verifies the `SigV4` signature, and validates the request timestamp.
109109
/// Handles both long-lived (AKIA*) and temporary (ASIA* + X-Amz-Security-Token)
110110
/// credentials.
111111
pub struct BuiltinAuthProvider<C: CredentialStore> {

crates/auth/src/policy/condition.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//!
66
//! Evaluates condition blocks against a `ConditionContext`. Supports all IAM
77
//! condition operators: String*, Numeric*, Date*, Bool, Null, Arn*, and the
8-
//! set operators ForAllValues/ForAnyValue with optional IfExists suffix.
8+
//! set operators ForAllValues/ForAnyValue with optional `IfExists` suffix.
99
1010
use super::context::ConditionContext;
1111
use super::document::{Condition, ConditionOperator};
@@ -160,10 +160,10 @@ fn unwrap_if_exists(op: &ConditionOperator) -> (bool, &ConditionOperator) {
160160
/// For multi-valued keys (e.g., `dynamodb:LeadingKeys`), all context values
161161
/// must satisfy the condition (implicit AND).
162162
///
163-
/// For positive operators (StringEquals, NumericEquals, etc.): each context
163+
/// For positive operators (`StringEquals`, `NumericEquals`, etc.): each context
164164
/// value must match at least one policy value (OR semantics — "value in set").
165165
///
166-
/// For negative operators (StringNotEquals, NumericNotEquals, etc.): each
166+
/// For negative operators (`StringNotEquals`, `NumericNotEquals`, etc.): each
167167
/// context value must satisfy the negative comparison against ALL policy
168168
/// values (AND semantics — "value not in set"). This matches AWS IAM behavior
169169
/// where `StringNotEquals` with `["a", "b"]` means "value is neither a nor b".

crates/auth/src/policy/context.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// Copyright 2026 ExtendDB contributors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
//! Condition context trait and DynamoDB request context.
4+
//! Condition context trait and `DynamoDB` request context.
55
//!
66
//! `ConditionContext` is the shared trait for resolving condition keys during
7-
//! policy evaluation. `RequestContext` implements it for DynamoDB operations;
7+
//! policy evaluation. `RequestContext` implements it for `DynamoDB` operations;
88
//! `AssumeRoleContext` implements it for trust policy evaluation.
99
1010
use std::collections::HashMap;
1111

1212
/// Trait for resolving condition keys during policy evaluation.
1313
///
14-
/// Implemented by `RequestContext` (DynamoDB operations) and
15-
/// `AssumeRoleContext` (trust policy / AssumeRole).
14+
/// Implemented by `RequestContext` (`DynamoDB` operations) and
15+
/// `AssumeRoleContext` (trust policy / `AssumeRole`).
1616
pub trait ConditionContext {
1717
/// Resolve a condition key to its value(s).
1818
///
@@ -21,29 +21,29 @@ pub trait ConditionContext {
2121
fn resolve_key(&self, key: &str) -> Option<Vec<&str>>;
2222
}
2323

24-
/// Request parameters extracted from a DynamoDB operation for condition evaluation.
24+
/// Request parameters extracted from a `DynamoDB` operation for condition evaluation.
2525
#[derive(Debug, Default)]
2626
pub struct RequestParams {
2727
/// Partition key values being accessed (for `dynamodb:LeadingKeys`).
28-
/// `None` for table-level operations (CreateTable, etc.).
28+
/// `None` for table-level operations (`CreateTable`, etc.).
2929
pub leading_keys: Option<Vec<String>>,
3030
/// Attribute names being read/written (for `dynamodb:Attributes`).
3131
/// `None` when not applicable.
3232
pub attributes: Option<Vec<String>>,
3333
/// The Select parameter value (for `dynamodb:Select`).
3434
pub select: Option<String>,
35-
/// The ReturnValues parameter value (for `dynamodb:ReturnValues`).
35+
/// The `ReturnValues` parameter value (for `dynamodb:ReturnValues`).
3636
pub return_values: Option<String>,
37-
/// The ReturnConsumedCapacity parameter value.
37+
/// The `ReturnConsumedCapacity` parameter value.
3838
pub return_consumed_capacity: Option<String>,
3939
/// The enclosing operation for batch/transact sub-operations.
4040
pub enclosing_operation: Option<String>,
4141
}
4242

43-
/// Context for evaluating conditions on DynamoDB operations.
43+
/// Context for evaluating conditions on `DynamoDB` operations.
4444
///
4545
/// Built by the server middleware before policy evaluation. Contains all
46-
/// condition keys that IAM policies can reference for DynamoDB access control.
46+
/// condition keys that IAM policies can reference for `DynamoDB` access control.
4747
#[derive(Debug)]
4848
pub struct RequestContext {
4949
/// Tags on the authenticated principal (`aws:PrincipalTag/*`).
@@ -56,9 +56,9 @@ pub struct RequestContext {
5656
pub attributes: Option<Vec<String>>,
5757
/// The Select parameter value.
5858
pub select: Option<String>,
59-
/// The ReturnValues parameter value.
59+
/// The `ReturnValues` parameter value.
6060
pub return_values: Option<String>,
61-
/// The ReturnConsumedCapacity parameter value.
61+
/// The `ReturnConsumedCapacity` parameter value.
6262
pub return_consumed_capacity: Option<String>,
6363
/// Whether this is a Scan operation.
6464
pub full_table_scan: Option<bool>,
@@ -67,11 +67,12 @@ pub struct RequestContext {
6767
}
6868

6969
impl RequestContext {
70-
/// Build context for a DynamoDB operation.
70+
/// Build context for a `DynamoDB` operation.
7171
///
7272
/// `principal_tags` and `resource_tags` come from the identity and target
7373
/// table respectively. `is_scan` should be true for Scan operations.
7474
/// `params` carries operation-specific request parameters.
75+
#[must_use]
7576
pub fn build(
7677
principal_tags: HashMap<String, String>,
7778
resource_tags: HashMap<String, String>,
@@ -103,11 +104,11 @@ impl ConditionContext for RequestContext {
103104
"dynamodb:LeadingKeys" => self
104105
.leading_keys
105106
.as_ref()
106-
.map(|v| v.iter().map(|s| s.as_str()).collect()),
107+
.map(|v| v.iter().map(std::string::String::as_str).collect()),
107108
"dynamodb:Attributes" => self
108109
.attributes
109110
.as_ref()
110-
.map(|v| v.iter().map(|s| s.as_str()).collect()),
111+
.map(|v| v.iter().map(std::string::String::as_str).collect()),
111112
"dynamodb:Select" => self.select.as_deref().map(|v| vec![v]),
112113
"dynamodb:ReturnValues" => self.return_values.as_deref().map(|v| vec![v]),
113114
"dynamodb:ReturnConsumedCapacity" => {
@@ -125,15 +126,15 @@ impl ConditionContext for RequestContext {
125126
}
126127
}
127128

128-
/// Context for evaluating trust policy conditions during AssumeRole.
129+
/// Context for evaluating trust policy conditions during `AssumeRole`.
129130
///
130131
/// Trust policies can reference `aws:PrincipalTag/*` and `sts:ExternalId`.
131132
/// DynamoDB-specific keys are not applicable.
132133
#[derive(Debug)]
133134
pub struct AssumeRoleContext {
134135
/// Tags on the calling principal.
135136
pub principal_tags: HashMap<String, String>,
136-
/// The external ID provided in the AssumeRole call (if any).
137+
/// The external ID provided in the `AssumeRole` call (if any).
137138
pub external_id: Option<String>,
138139
}
139140

crates/auth/src/policy/document.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ pub struct Statement {
2626
pub sid: Option<String>,
2727
/// Allow or Deny.
2828
pub effect: Effect,
29-
/// Action or NotAction matching.
29+
/// Action or `NotAction` matching.
3030
pub action_match: ActionMatch,
31-
/// Resource or NotResource matching.
31+
/// Resource or `NotResource` matching.
3232
pub resource_match: ResourceMatch,
3333
/// Conditions that must all be true for the statement to apply.
3434
pub conditions: Vec<Condition>,
@@ -43,7 +43,7 @@ pub enum Effect {
4343
Deny,
4444
}
4545

46-
/// Action matching: either Action (include list) or NotAction (exclude list).
46+
/// Action matching: either Action (include list) or `NotAction` (exclude list).
4747
/// A statement uses exactly one — never both.
4848
#[derive(Debug, Clone)]
4949
pub enum ActionMatch {
@@ -53,7 +53,7 @@ pub enum ActionMatch {
5353
NotActions(Vec<String>),
5454
}
5555

56-
/// Resource matching: either Resource (include list) or NotResource (exclude list).
56+
/// Resource matching: either Resource (include list) or `NotResource` (exclude list).
5757
#[derive(Debug, Clone)]
5858
pub enum ResourceMatch {
5959
/// Matches listed resources.
@@ -82,7 +82,7 @@ pub struct Condition {
8282
pub values: Vec<String>,
8383
}
8484

85-
/// All IAM condition operators relevant to DynamoDB access control.
85+
/// All IAM condition operators relevant to `DynamoDB` access control.
8686
///
8787
/// Set operators (`ForAllValues`, `ForAnyValue`) and `IfExists` wrap a base
8888
/// operator. Valid nestings: `ForAllValues(IfExists(base))`,
@@ -148,7 +148,7 @@ impl PolicyDocument {
148148
/// # Errors
149149
///
150150
/// Returns `PolicyParseError` if the JSON is malformed or contains
151-
/// invalid policy constructs (e.g., both Action and NotAction).
151+
/// invalid policy constructs (e.g., both Action and `NotAction`).
152152
pub fn from_json(json: &str) -> Result<Self, PolicyParseError> {
153153
Self::from_json_with_size_limit(json, 6_144)
154154
}
@@ -214,7 +214,7 @@ fn parse_statement(value: &Value) -> Result<Statement, PolicyParseError> {
214214
})
215215
}
216216

217-
/// Parse Action or NotAction (mutually exclusive).
217+
/// Parse Action or `NotAction` (mutually exclusive).
218218
fn parse_action_match(value: &Value) -> Result<ActionMatch, PolicyParseError> {
219219
let has_action = !value["Action"].is_null();
220220
let has_not_action = !value["NotAction"].is_null();
@@ -234,7 +234,7 @@ fn parse_action_match(value: &Value) -> Result<ActionMatch, PolicyParseError> {
234234
}
235235
}
236236

237-
/// Parse Resource or NotResource (mutually exclusive).
237+
/// Parse Resource or `NotResource` (mutually exclusive).
238238
fn parse_resource_match(value: &Value) -> Result<ResourceMatch, PolicyParseError> {
239239
let has_resource = !value["Resource"].is_null();
240240
let has_not_resource = !value["NotResource"].is_null();
@@ -254,7 +254,7 @@ fn parse_resource_match(value: &Value) -> Result<ResourceMatch, PolicyParseError
254254
}
255255
}
256256

257-
/// Parse Principal or NotPrincipal (optional, for trust policies).
257+
/// Parse Principal or `NotPrincipal` (optional, for trust policies).
258258
fn parse_principal_match(value: &Value) -> Result<Option<PrincipalMatch>, PolicyParseError> {
259259
let has_principal = !value["Principal"].is_null();
260260
let has_not_principal = !value["NotPrincipal"].is_null();

crates/auth/src/policy/evaluator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ pub enum AuthzDecision {
3333
///
3434
/// - `identity_policies`: user + group policies, or role policies.
3535
/// - `permissions_boundary`: optional boundary policy on the user or role.
36-
/// - `session_policy`: optional inline policy from AssumeRole.
37-
/// - `action`: the DynamoDB action (e.g., "dynamodb:PutItem").
36+
/// - `session_policy`: optional inline policy from `AssumeRole`.
37+
/// - `action`: the `DynamoDB` action (e.g., "dynamodb:PutItem").
3838
/// - `resource_arn`: the target resource ARN.
3939
/// - `context`: condition context for evaluating condition blocks.
4040
pub fn evaluate_policies(

crates/auth/src/policy/matcher.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
/// assert!(!wildcard_match("dynamodb:Get*", "dynamodb:PutItem"));
2424
/// assert!(wildcard_match("s?s", "sis"));
2525
/// ```
26+
#[must_use]
2627
pub fn wildcard_match(pattern: &str, value: &str) -> bool {
2728
wildcard_match_impl(pattern.as_bytes(), value.as_bytes(), false)
2829
}
@@ -40,6 +41,7 @@ pub fn wildcard_match(pattern: &str, value: &str) -> bool {
4041
/// assert!(wildcard_match_ignore_case("dynamodb:Get*", "dynamodb:getitem"));
4142
/// assert!(!wildcard_match_ignore_case("dynamodb:Get*", "dynamodb:PutItem"));
4243
/// ```
44+
#[must_use]
4345
pub fn wildcard_match_ignore_case(pattern: &str, value: &str) -> bool {
4446
wildcard_match_impl(pattern.as_bytes(), value.as_bytes(), true)
4547
}
@@ -104,6 +106,7 @@ fn wildcard_match_impl(p: &[u8], v: &[u8], ignore_case: bool) -> bool {
104106
/// "arn:aws:dynamodb:us-east-1:123456789012:table/Users"
105107
/// ));
106108
/// ```
109+
#[must_use]
107110
pub fn arn_match(pattern: &str, value: &str) -> bool {
108111
// "*" as a pattern matches any ARN
109112
if pattern == "*" {

crates/auth/src/sigv4/canonical.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Copyright 2026 ExtendDB contributors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
//! Canonical request construction for SigV4 verification.
4+
//! Canonical request construction for `SigV4` verification.
55
//!
66
//! Builds the canonical request string from the HTTP method, URI path,
7-
//! query string, signed headers, and body hash per the AWS SigV4 spec.
7+
//! query string, signed headers, and body hash per the AWS `SigV4` spec.
88
99
use axum::http::HeaderMap;
1010
use sha2::{Digest, Sha256};
@@ -21,7 +21,7 @@ use sha2::{Digest, Sha256};
2121
/// HashedPayload
2222
/// ```
2323
///
24-
/// For DynamoDB, the URI is always `/` and there is no query string.
24+
/// For `DynamoDB`, the URI is always `/` and there is no query string.
2525
pub fn canonical_request(
2626
method: &str,
2727
uri_path: &str,
@@ -39,15 +39,14 @@ pub fn canonical_request(
3939
let payload_hash = headers
4040
.get("x-amz-content-sha256")
4141
.and_then(|v| v.to_str().ok())
42-
.map(str::to_owned)
43-
.unwrap_or_else(|| sha256_hex(body));
42+
.map_or_else(|| sha256_hex(body), str::to_owned);
4443

4544
format!(
4645
"{method}\n{uri_path}\n{query_string}\n{canonical_headers}\n{signed_lower}\n{payload_hash}"
4746
)
4847
}
4948

50-
/// Build the string-to-sign for SigV4.
49+
/// Build the string-to-sign for `SigV4`.
5150
///
5251
/// Format:
5352
/// ```text
@@ -56,6 +55,7 @@ pub fn canonical_request(
5655
/// <scope>\n
5756
/// Hex(SHA256(canonical_request))
5857
/// ```
58+
#[must_use]
5959
pub fn string_to_sign(timestamp: &str, scope: &str, canonical_request: &str) -> String {
6060
let hashed = sha256_hex(canonical_request.as_bytes());
6161
format!("AWS4-HMAC-SHA256\n{timestamp}\n{scope}\n{hashed}")

crates/auth/src/sigv4/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
//! AWS Signature Version 4 verification.
55
//!
6-
//! Implements server-side SigV4 verification: parsing the `Authorization` header,
6+
//! Implements server-side `SigV4` verification: parsing the `Authorization` header,
77
//! reconstructing the canonical request, deriving the signing key, and performing
88
//! constant-time signature comparison.
99

crates/auth/src/sigv4/parse.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2026 ExtendDB contributors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
//! Parse the AWS SigV4 `Authorization` header.
4+
//! Parse the AWS `SigV4` `Authorization` header.
55
//!
66
//! Format:
77
//! ```text
@@ -12,7 +12,7 @@
1212
1313
use extenddb_core::error::DynamoDbError;
1414

15-
/// Parsed components of a SigV4 `Authorization` header.
15+
/// Parsed components of a `SigV4` `Authorization` header.
1616
#[derive(Debug, PartialEq)]
1717
pub struct ParsedAuthorization {
1818
/// The access key ID (e.g. `AKIAIOSFODNN7EXAMPLE`).
@@ -29,7 +29,7 @@ pub struct ParsedAuthorization {
2929
pub signature: String,
3030
}
3131

32-
/// Parse a SigV4 `Authorization` header value.
32+
/// Parse a `SigV4` `Authorization` header value.
3333
///
3434
/// Returns `IncompleteSignature` if the header is malformed.
3535
/// S-2: Rejects headers exceeding 8 KB to prevent heap abuse.

0 commit comments

Comments
 (0)