Skip to content

refactor(iam): extract per-service IAM strategies from compileIamRole#711

Merged
zirkelc merged 1 commit intoserverless-operations:masterfrom
BANCS-Norway:refactor-707-iam-strategy
Mar 27, 2026
Merged

refactor(iam): extract per-service IAM strategies from compileIamRole#711
zirkelc merged 1 commit intoserverless-operations:masterfrom
BANCS-Norway:refactor-707-iam-strategy

Conversation

@VirtueMe
Copy link
Copy Markdown
Collaborator

Summary

Replaces the 130-line switch statement in compileIamRole.js with a registry-based Strategy pattern. Each AWS service now lives in its own module under iamStrategies/, making it straightforward to add, modify, or test individual service permissions in isolation.

  • iamStrategies/utils.js — shared helpers (ARN builders, parameter extraction, SQS URL parser)
  • iamStrategies/index.js — registry (Map<arn, handler>) + dispatch
  • iamStrategies/{service}.js — sqs, sns, dynamodb, redshiftData, batch, glue, ecs, lambda, stepFunctions, codebuild, sagemaker, bedrock, eventbridge, http, s3, ses

compileIamRole.js drops from 1,025 to ~155 lines.

Tests

The monolithic 4,863-line compileIamRole.test.js is split into 16 co-located strategy test files, each testing its strategy function directly (no Serverless instance, no CloudFormation pipeline — just getPermissions(state) → check the permissions array). compileIamRole.test.js is trimmed to ~30 orchestration tests covering role creation, state traversal, Map/Distributed Map, permissionsBoundary, iam.role.path, loggingConfig, tracingConfig, and encryptionConfig.

483 tests, all passing. No behaviour change.

Closes #707

🤖 Generated with Claude Code

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 23, 2026

Open in StackBlitz

npm i https://pkg.pr.new/serverless-operations/serverless-step-functions@711

commit: ca39a42

@zirkelc
Copy link
Copy Markdown
Collaborator

zirkelc commented Mar 26, 2026

Thanks! Could you fix the merge conflicts?

Replaces the 130-line switch statement in compileIamRole.js with a
registry-based Strategy pattern. Each AWS service now lives in its
own module under iamStrategies/, making it straightforward to add,
modify, or test individual service permissions in isolation.

- iamStrategies/utils.js   — shared helpers (ARN builders, parameter
                              extraction, SQS URL parser)
- iamStrategies/index.js   — registry (Map<arn, handler>) + dispatch
- iamStrategies/{service}  — sqs, sns, dynamodb, redshiftData, batch,
                              glue, ecs, lambda, stepFunctions,
                              codebuild, sagemaker, bedrock,
                              eventbridge, http, s3, ses

compileIamRole.js drops from 1025 to ~155 lines. Tests split from
the 4,863-line monolith into 16 co-located strategy test files, each
testing its strategy function directly. compileIamRole.test.js trimmed
to ~30 orchestration tests. Total: 483 tests, all passing.

Closes serverless-operations#707

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@VirtueMe VirtueMe force-pushed the refactor-707-iam-strategy branch from ca862e0 to ca39a42 Compare March 26, 2026 14:29
@VirtueMe
Copy link
Copy Markdown
Collaborator Author

Rebased onto master to resolve the conflict with #712 (JSONata EventBridge Scheduler support). The fix from that commit has been applied to iamStrategies/eventbridge.js with a corresponding test added to iamStrategies/eventbridge.test.js.

@zirkelc
Copy link
Copy Markdown
Collaborator

zirkelc commented Mar 26, 2026

Thanks! I have to wait a bit as my user that I'm using for the release got rate-limited by GitHub.

@zirkelc zirkelc merged commit 3e400cd into serverless-operations:master Mar 27, 2026
3 checks passed
@VirtueMe VirtueMe deleted the refactor-707-iam-strategy branch March 27, 2026 07:29
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.

refactor(iam): split compileIamRole into Strategy pattern with per-service modules

2 participants