Skip to content

Commit 2be4f24

Browse files
committed
Allow more complex ARN templates
This commit adds support for more complex ARN formats, including those with colon (':') chars or a combination of colons and foward slashes ('/').
1 parent 5f89b6d commit 2be4f24

File tree

2 files changed

+43
-25
lines changed

2 files changed

+43
-25
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public List<ValidationEvent> validate(Model model) {
5151
}
5252

5353
private List<String> parseArnComponents(String arnTemplate) {
54-
return Arrays.asList(arnTemplate.split("/"));
54+
List<String> components = new ArrayList<>();
55+
for (String component : arnTemplate.split("/")) {
56+
components.addAll(Arrays.asList(component.split(":")));
57+
}
58+
return components;
5559
}
5660
}
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,67 @@
11
$version: "2"
2+
23
namespace smithy.example
34

45
use aws.api#arn
6+
use aws.api#service
7+
use aws.iam#defineConditionKeys
8+
use aws.iam#iamResource
59

6-
@aws.api#service(sdkId: "My")
7-
@aws.iam#defineConditionKeys("foo:baz": {type: "String", documentation: "Foo baz"})
10+
@service(sdkId: "My")
11+
@defineConditionKeys(
12+
"foo:baz": { type: "String", documentation: "Foo baz" }
13+
)
814
service MyService {
9-
version: "2019-02-20",
15+
version: "2019-02-20"
1016
resources: [
11-
BadIamResourceName,
12-
Beer,
13-
InvalidResource,
17+
BadIamResourceName
18+
Beer
19+
InvalidResource
1420
ShouldNotThrowAnError
21+
ColonResource
22+
CombinedResource
1523
]
1624
}
1725

18-
@aws.iam#iamResource(name: "bad-iam-resourceName")
26+
@iamResource(name: "bad-iam-resourceName")
1927
@arn(template: "bad-iam-resource-name/{id}")
2028
resource BadIamResourceName {
21-
identifiers: {
22-
id: String
23-
}
29+
identifiers: { id: String }
2430
}
2531

26-
@aws.iam#iamResource(name: "beer")
32+
@iamResource(name: "beer")
2733
@arn(template: "beer/{beerId}")
2834
resource Beer {
29-
identifiers: {
30-
beerId: String
31-
}
32-
resources: [IncompatibleResourceName]
35+
identifiers: { beerId: String }
36+
resources: [
37+
IncompatibleResourceName
38+
]
3339
}
3440

3541
@arn(template: "beer/{beerId}/incompatible-resource-name")
36-
@aws.iam#iamResource(name: "IncompatibleResourceName")
42+
@iamResource(name: "IncompatibleResourceName")
3743
resource IncompatibleResourceName {
38-
identifiers: {
39-
beerId: String
40-
}
44+
identifiers: { beerId: String }
4145
}
4246

43-
@aws.iam#iamResource(name: "invalidResource")
47+
@iamResource(name: "invalidResource")
4448
@arn(template: "invalid-resource")
4549
resource InvalidResource {}
4650

47-
@aws.iam#iamResource(name: "shouldNotThrowError")
51+
@iamResource(name: "shouldNotThrowError")
4852
@arn(template: "{arn}", absolute: true)
4953
resource ShouldNotThrowAnError {
50-
identifiers: {
51-
arn: String
52-
}
54+
identifiers: { arn: String }
55+
}
56+
57+
@iamResource(name: "colon")
58+
@arn(template: "colon:{fooId}")
59+
resource ColonResource {
60+
identifiers: { fooId: String }
61+
}
62+
63+
@iamResource(name: "combined")
64+
@arn(template: "combined:{fooId}/{barId}")
65+
resource CombinedResource {
66+
identifiers: { fooId: String, barId: String }
5367
}

0 commit comments

Comments
 (0)