Skip to content

chore: code quality pass — type safety, macros, dead code removal#4

Merged
ceejbot merged 8 commits intolatestfrom
chore/code-quality-pass
Mar 28, 2026
Merged

chore: code quality pass — type safety, macros, dead code removal#4
ceejbot merged 8 commits intolatestfrom
chore/code-quality-pass

Conversation

@ceejbot
Copy link
Copy Markdown
Owner

@ceejbot ceejbot commented Mar 28, 2026

Summary

Comprehensive quality pass across the codebase following the workspace conversion and AWS SM backend work. Net -1,375 lines (removed 1,688, added 313).

P0: Dead code removal (-1,309 lines)

Deleted three orphaned inline backend files superseded by sub-crates in the workspace conversion.

P1: Type safety — plain string enum serialization

Replaced serde_json::to_string()/from_str() for DB storage of CipherAlgorithm and SecretKind with explicit as_str()&'static str and parse_db() methods. This pattern already caused a production bug (AWS tag value quoting). Includes backward-compatible parsing of legacy JSON-quoted values.

P2: Type safety — newtypes in CredentialRequest

Replaced bare String fields with SecretName, DomainScope, AgentId in CredentialRequest and CredentialGuard. Prevents compile-time field swaps.

P3: Eliminate allocations — borrowed indexed_fields()

Changed AuditEvent::indexed_fields() to return (Option<&str>, Option<&LeaseId>) instead of (Option<String>, Option<String>). Eliminates heap allocations on every audit event.

P4: Dispatch macros — eliminate clone and boilerplate (-72 lines)

Added parse_params! and json_response! macros. Changed dispatch() to take Request by value so params move instead of clone. Reduces 8 near-identical dispatch branches.

P5: Replace eprintln! with tracing::warn!

Standardize on the tracing facade in zerolease-provider.

P6: Typed AWS SDK errors (-25 lines)

Replaced string-matching is_not_found() with typed SdkError::ServiceError pattern matching using is_resource_not_found_exception(), is_resource_exists_exception(), etc.

P7: Row mapping macros (-31 lines)

Added col! macro and parse_id()/parse_timestamp() helpers in both rusqlite and postgres stores. Reduces verbose per-field extraction to concise struct initialization.

Test plan

  • cargo clippy --workspace --all-targets — clean
  • cargo clippy --manifest-path crates/zerolease-store-postgres/Cargo.toml --all-targets — clean
  • cargo test --workspace — all pass, zero failures
  • CI green

ceejbot added 8 commits March 28, 2026 13:49
These inline implementations were superseded by the sub-crates
(zerolease-store-rusqlite, zerolease-store-postgres) in the workspace
conversion. They were never declared as modules and didn't compile.
CipherAlgorithm and SecretKind used serde_json::to_string() for DB
storage, which wrapped enum variants in JSON quotes ("\"Pat\""). This
already caused a production bug with AWS tag values.

Replace with explicit as_str() → &'static str and parse_db() → Result
methods using lowercase plain strings (aes256gcm, pat, apikey, etc.).
Includes backward-compatible parsing of legacy JSON-quoted values.

Eliminates the trim_matches('"') hack in the AWS SM tag code.
Replace bare String fields with SecretName, DomainScope, and AgentId
from zerolease::types. This makes it impossible to accidentally swap
an agent_id with a secret_name at compile time.

Make zerolease a non-optional dependency of zerolease-provider (with
default-features = false) since the types are lightweight.
Change AuditEvent::indexed_fields() to return (Option<&str>,
Option<&LeaseId>) instead of (Option<String>, Option<String>).
Eliminates heap allocations on every audit event. Callers that
need owned strings convert at the point of use.
Add parse_params! and json_response! macros to reduce the 8 nearly-
identical request dispatch branches. Take Request by value in dispatch()
so params can be moved instead of cloned. Reduces ~200 lines of
boilerplate to ~80 lines of clear intent.
Replace is_not_found() string-parsing helper with typed pattern
matching on SdkError::ServiceError variants using the SDK's is_*
methods (is_resource_not_found_exception, is_resource_exists_exception,
is_invalid_request_exception). More robust against SDK changes.
Add col! macro for extracting typed column values with uniform error
handling. Extract parse_id() and parse_timestamp() helpers. Reduces
row_to_stored_secret and row_to_metadata from verbose per-field
extraction to concise struct initialization.

Applied to both rusqlite and postgres store backends. Also extracted
row_to_metadata for postgres list() to match the pattern.
@ceejbot ceejbot merged commit ee5ce2f into latest Mar 28, 2026
3 checks passed
@ceejbot ceejbot deleted the chore/code-quality-pass branch March 28, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant