Skip to content

Commit 866dae7

Browse files
fix: Don't assume that all service bindings existed before (#2405)
1 parent a7c3fd5 commit 866dae7

File tree

4 files changed

+73
-17
lines changed

4 files changed

+73
-17
lines changed

smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,27 @@ public List<ValidationEvent> evaluate(Differences differences) {
8383
}
8484
// Validate Operation effective auth schemes
8585
for (ServiceShape newServiceShape : newOperationServiceBindings) {
86-
ServiceShape oldServiceShape = oldModel.expectShape(newServiceShape.getId(), ServiceShape.class);
87-
OperationShape oldOperationShape = change.getOldShape();
88-
List<ShapeId> oldAuthSchemes = oldServiceIndex
89-
.getEffectiveAuthSchemes(oldServiceShape, oldOperationShape)
90-
.keySet()
91-
.stream()
92-
.collect(Collectors.toList());
93-
List<ShapeId> newAuthSchemes = newServiceIndex
94-
.getEffectiveAuthSchemes(newServiceShape, newOperationShape)
95-
.keySet()
96-
.stream()
97-
.collect(Collectors.toList());
98-
validateMigration(
99-
newOperationShape,
100-
oldAuthSchemes,
101-
newAuthSchemes,
102-
events);
86+
oldModel.getShape(newServiceShape.getId())
87+
.filter(Shape::isServiceShape)
88+
.map(s -> (ServiceShape) s)
89+
.ifPresent(oldServiceShape -> {
90+
OperationShape oldOperationShape = change.getOldShape();
91+
List<ShapeId> oldAuthSchemes = oldServiceIndex
92+
.getEffectiveAuthSchemes(oldServiceShape, oldOperationShape)
93+
.keySet()
94+
.stream()
95+
.collect(Collectors.toList());
96+
List<ShapeId> newAuthSchemes = newServiceIndex
97+
.getEffectiveAuthSchemes(newServiceShape, newOperationShape)
98+
.keySet()
99+
.stream()
100+
.collect(Collectors.toList());
101+
validateMigration(
102+
newOperationShape,
103+
oldAuthSchemes,
104+
newAuthSchemes,
105+
events);
106+
});
103107
}
104108
}
105109

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
$version: "2.0"
2+
3+
metadata suppressions = [
4+
{
5+
id: "ModifiedTrait.Update.smithy.api#auth"
6+
namespace: "ns.foo"
7+
}
8+
]
9+
10+
namespace ns.foo
11+
12+
@auth([])
13+
@httpBearerAuth
14+
service Service {
15+
operations: [
16+
Operation
17+
]
18+
}
19+
20+
@auth([])
21+
operation Operation {}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
$version: "2.0"
2+
3+
metadata suppressions = [
4+
{
5+
id: "ModifiedTrait.Update.smithy.api#auth"
6+
namespace: "ns.foo"
7+
}
8+
]
9+
10+
namespace ns.foo
11+
12+
@auth([httpBearerAuth])
13+
@httpBearerAuth
14+
service Service {
15+
operations: [
16+
Operation
17+
]
18+
}
19+
20+
@auth([httpBearerAuth])
21+
@httpBearerAuth
22+
service NewService {
23+
operations: [
24+
Operation
25+
]
26+
}
27+
28+
29+
@auth([httpBearerAuth])
30+
operation Operation {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[NOTE] ns.foo#NewService: Added service `ns.foo#NewService` | AddedShape

0 commit comments

Comments
 (0)