Skip to content

refactor(iam): extract CreateRoleInput from create_role#355

Merged
vieiralucas merged 1 commit intomainfrom
worktree-cleanup-iam-roles-long-fns
Apr 13, 2026
Merged

refactor(iam): extract CreateRoleInput from create_role#355
vieiralucas merged 1 commit intomainfrom
worktree-cleanup-iam-roles-long-fns

Conversation

@vieiralucas
Copy link
Copy Markdown
Member

@vieiralucas vieiralucas commented Apr 13, 2026

Summary

The parse + validate prologue of `create_role` was 28 lines: RoleName, AssumeRolePolicyDocument, Path, Description, MaxSessionDuration, Tags + tag validation, PermissionsBoundary + ARN format check. Extract `CreateRoleInput::from_query` so `create_role` itself is a 35-line state-mutation flow.

Audited and judged already-clean

  • `get_role` (16L): one-shot lookup with one error path. Splitting would not improve readability.
  • `list_roles` (68L): clear sequence of validate → filter by path prefix → sort → marker-paginate → render. Each phase is short and focused; pulling the marker-pagination block out would only make sense if more than two list ops shared the exact shape (currently only `list_roles` and `list_access_keys`).

Test plan

  • `cargo fmt`
  • `cargo clippy -p fakecloud-iam --all-targets -- -D warnings`
  • `cargo test -p fakecloud-iam --lib` — 73 passed
  • `cargo test --workspace --exclude fakecloud-e2e --exclude fakecloud-conformance`

Summary by cubic

Refactored IAM create_role by extracting parsing and validation into CreateRoleInput::from_query, keeping create_role focused on state mutation. No behavior changes.

  • Refactors
    • Added CreateRoleInput with from_query to encapsulate:
      • Required params and length checks (RoleName, AssumeRolePolicyDocument).
      • Defaults (Path="/", MaxSessionDuration=3600).
      • Tag parsing and validation.
      • PermissionsBoundary ARN format check.
    • Updated create_role to construct IamRole from CreateRoleInput.
    • Audited get_role and list_roles; left unchanged.

Written for commit a345221. Summary will update on new commits.

The parse + validate prologue of create_role was 28 lines (RoleName,
AssumeRolePolicyDocument, Path, Description, MaxSessionDuration, Tags
+ tag validation, PermissionsBoundary + ARN format check). Extract
into CreateRoleInput::from_query so create_role itself is a 35-line
state-mutation flow.

get_role (16L) and list_roles (68L) audited in the same pass and judged
already clean: get_role is a one-shot lookup with one error path;
list_roles is a clear sequence of validate → filter by path prefix →
sort → marker-paginate → render, with each phase short and focused.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

@vieiralucas vieiralucas merged commit 4ea29fa into main Apr 13, 2026
22 checks passed
@vieiralucas vieiralucas deleted the worktree-cleanup-iam-roles-long-fns branch April 13, 2026 14:55
vieiralucas added a commit that referenced this pull request Apr 13, 2026
…Input

The two longest functions in the SSM sub-modules were create_patch_baseline
(~150 lines) and create_association_inner (~162 lines). Both were dominated
by body parsing, field validation, and field extraction — with the actual
state mutation only in the last 30-40 lines.

This extracts dedicated *Input structs with from_body() constructors,
leaving each function focused on idempotency, ID generation, and struct
assembly. Same pattern as PRs #324/#328/#338/#355/#356.
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