Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support iamAction for CFN handler permissions #2091

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

### Bug Fixes

* Fixed an issue where `@iamAction` wasn't reflected in CFN resource schema creation. ([#2091](https://github.com/smithy-lang/smithy/pull/2091))
* Fixed tree node start and end locations. ([#2084](https://github.com/smithy-lang/smithy/pull/2084))
* Fixed several minor build warnings. ([2089](https://github.com/smithy-lang/smithy/pull/2089))
* Fixed protocol test service signing name for `awsJson1_1` protocol. ([#2089](https://github.com/smithy-lang/smithy/pull/2089))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import software.amazon.smithy.aws.cloudformation.schema.fromsmithy.Context;
import software.amazon.smithy.aws.cloudformation.schema.model.Handler;
import software.amazon.smithy.aws.cloudformation.schema.model.ResourceSchema;
import software.amazon.smithy.aws.iam.traits.IamActionTrait;
import software.amazon.smithy.aws.iam.traits.RequiredActionsTrait;
import software.amazon.smithy.aws.traits.ServiceTrait;
import software.amazon.smithy.model.Model;
Expand All @@ -30,6 +31,7 @@
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.traits.NoReplaceTrait;
import software.amazon.smithy.utils.ListUtils;
import software.amazon.smithy.utils.SetUtils;
import software.amazon.smithy.utils.SmithyInternalApi;

Expand Down Expand Up @@ -112,9 +114,11 @@ private Set<String> getPermissionsEntriesForOperation(Model model, ServiceShape
permissionsEntries.add(operationActionName);

// Add all the other required actions for the operation.
operation.getTrait(RequiredActionsTrait.class)
.map(RequiredActionsTrait::getValues)
.map(permissionsEntries::addAll);
permissionsEntries.addAll(operation.getTrait(IamActionTrait.class)
.map(IamActionTrait::getRequiredActions)
.orElseGet(() -> operation.getTrait(RequiredActionsTrait.class)
.map(RequiredActionsTrait::getValues)
.orElse(ListUtils.of())));
return permissionsEntries;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void addsHandlerPermissionsByDefault() {
containsInAnyOrder("testservice:CreateFooOperation", "otherservice:DescribeDependencyComponent"));
assertThat(handlersDefined.get("read").expectObjectNode()
.expectArrayMember("permissions").getElementsAs(StringNode::getValue),
contains("testservice:GetFooOperation"));
containsInAnyOrder("testservice:GetFooOperation", "otherservice:DescribeThing"));
assertThat(handlersDefined.get("update").expectObjectNode()
.expectArrayMember("permissions").getElementsAs(StringNode::getValue),
contains("testservice:UpdateFooOperation"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ $version: "2.0"
namespace smithy.example

use aws.cloudformation#cfnResource
use aws.iam#iamAction

service TestService {
version: "2020-07-02",
Expand Down Expand Up @@ -56,6 +57,7 @@ structure CreateFooResponse {
}

@readonly
@iamAction(requiredActions: ["otherservice:DescribeThing"])
operation GetFooOperation {
input: GetFooRequest,
output: GetFooResponse,
Expand Down
Loading