refactor: extract copy-paste helpers (rds, cognito, s3, bedrock, dynamodb, iam)#310
Merged
vieiralucas merged 1 commit intomainfrom Apr 12, 2026
Merged
Conversation
…modb, iam)
Five copy-pasted blocks are collapsed into named helpers:
- **RDS runtime check**: the six ``self.runtime.as_ref().ok_or_else(...)``
guards in ``fakecloud-rds::service`` become one ``require_runtime``
helper that returns the shared ``ServiceUnavailable`` error. Caller
sites drop from seven lines to one.
- **Cognito user-pool existence**: 57 copies of the
``if !state.user_pools.contains_key(pool_id) { return Err(...) }``
guard across 9 Cognito service submodules become one
``ensure_user_pool_exists(&state, pool_id)?;`` call. Every caller
previously had its own chance to misspell the error string or get the
status code wrong.
- **S3 XML tag scraper**: three byte-identical copies of
``extract_tag`` (in ``lifecycle.rs``, ``inventory.rs``, ``logging.rs``)
become a single private helper in a new ``s3::xml_util`` module.
- **Bedrock short UUIDs**: four copies of
``Uuid::new_v4().to_string()[..8].to_string()`` become a crate-level
``short_uuid()`` helper, and the stray ``uuid`` imports are dropped.
- **DynamoDB filter splitters**: ``split_on_and`` and ``split_on_or``
had the same 30-line parenthesis-aware scanner with only the
separator length and keyword differing. Both now dispatch to
``split_on_top_level_keyword(expr, keyword)``.
- **IAM test ARN extraction**: six copies of
``body.find("<Arn>").unwrap() + 5 ... body.find("</Arn>")`` in the
IAM test suite become ``extract_xml_tag(&body, "Arn")``.
No behavior change; 1102 unit tests still pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Six copy-paste sites are collapsed into named helpers. Net change: -338 lines.
RdsService::require_runtimefakecloud-rds::serviceruntime.as_ref().ok_or_else(...)guardensure_user_pool_existsfakecloud-cognito::service::*(9 files)if !state.user_pools.contains_key(...) { ... }guards3::xml_util::extract_taglifecycle.rs,inventory.rs,logging.rsfakecloud_bedrock::short_uuidguardrails,custom_models,prompt_routers,inference_profilesUuid::new_v4().to_string()[..8].to_string()split_on_top_level_keywordfakecloud-dynamodb::service::modsplit_on_and+split_on_orhad near-identical 30-line parenthesis-aware scanners; they now dispatch to a single keyword-parameterised helperextract_xml_tag(test helper)fakecloud-iam::iam_servicetest modulebody.find("<Arn>").unwrap() + 5 ... body.find("</Arn>").unwrap()No behavior change; the extracted helpers keep byte-identical semantics to what they replace.
Test plan
cargo build --workspacecargo fmt --checkcargo clippy --workspace --all-targets -- -D warningscargo test --workspace --exclude fakecloud-e2e --exclude fakecloud-conformance— 1102 passed, 0 failedSummary by cubic
Collapsed repeated guards and utilities into shared helpers across
fakecloud-rds,fakecloud-cognito,fakecloud-s3,fakecloud-bedrock,fakecloud-dynamodb, andfakecloud-iamto cut duplication. No behavior changes.RdsService::require_runtime()centralizes the Docker/Podman runtime check infakecloud-rds.ensure_user_pool_existsde-duplicates user-pool guards acrossfakecloud-cognitoservice modules.s3::xml_util::extract_tagreplaces three identical XML tag scrapers inlifecycle,inventory, andlogging.fakecloud_bedrock::short_uuid()standardizes 8-char IDs for guardrails, custom models, prompt routers, and inference profiles.split_on_top_level_keywordpowers bothsplit_on_andandsplit_on_orinfakecloud-dynamodb.extract_xml_tagto pull<Arn>from XML responses.Written for commit 7c2edc2. Summary will update on new commits.