Skip to content

Commit 840f69e

Browse files
committed
Make IAM resource name validation case-insensitive
1 parent b1a9be4 commit 840f69e

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

smithy-aws-iam-traits/src/main/java/software/amazon/smithy/aws/iam/traits/IamResourceTraitConflictingNameValidator.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.ArrayList;
1010
import java.util.HashMap;
1111
import java.util.List;
12+
import java.util.Locale;
1213
import java.util.Map;
1314
import java.util.stream.Collectors;
1415
import software.amazon.smithy.model.Model;
@@ -38,16 +39,17 @@ private List<ValidationEvent> validateService(TopDownIndex topDownIndex, Service
3839
List<ValidationEvent> events = new ArrayList<>();
3940
Map<String, List<ShapeId>> resourceMap = new HashMap<>();
4041
for (ResourceShape resource : topDownIndex.getContainedResources(service)) {
41-
String resourceName = IamResourceTrait.resolveResourceName(resource);
42+
String resourceName = IamResourceTrait.resolveResourceName(resource).toLowerCase(Locale.US);
4243
resourceMap.computeIfAbsent(resourceName, k -> new ArrayList<>()).add(resource.getId());
4344
}
4445
resourceMap.entrySet()
4546
.stream()
4647
.filter(entry -> entry.getValue().size() > 1)
4748
.map(entry -> error(service,
4849
String.format(
49-
"Multiple IAM resources defined with the same IAM resource name is not allowed in a service "
50-
+ "closure, but found multiple resources named `%s` in the service `%s`: [%s]",
50+
"Multiple IAM resources defined with the same IAM resource name is not allowed in a "
51+
+ "service closure, but found multiple resources case-insensitively named `%s` "
52+
+ "in the service `%s`: [%s]",
5153
entry.getKey(),
5254
service.getId(),
5355
tickedList(entry.getValue()))))
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[ERROR] smithy.example#MyService: Multiple IAM resources defined with the same IAM resource name is not allowed in a service closure, but found multiple resources named `Beer` in the service `smithy.example#MyService`: [`smithy.example#BadIamResourceName1`, `smithy.example#BadIamResourceName2`, `smithy.example#Beer`] | IamResourceTraitConflictingName
1+
[ERROR] smithy.example#MyService: Multiple IAM resources defined with the same IAM resource name is not allowed in a service closure, but found multiple resources case-insensitively named `beer` in the service `smithy.example#MyService`: [`smithy.example#BadIamResourceName1`, `smithy.example#BadIamResourceName2`, `smithy.example#Beer`] | IamResourceTraitConflictingName

smithy-aws-iam-traits/src/test/resources/software/amazon/smithy/aws/iam/traits/errorfiles/iam-resources/duplicate-iam-resources-name.smithy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ resource Beer {}
2121
@aws.iam#iamResource(name: "Beer")
2222
resource BadIamResourceName1 {}
2323

24-
@aws.iam#iamResource(name: "Beer")
24+
@aws.iam#iamResource(name: "beer")
2525
resource BadIamResourceName2 {}
2626

2727
@aws.iam#iamResource(name: "shouldNotThrowErrorSecond")

0 commit comments

Comments
 (0)