From 1358ca5bbab292f72eab6a7ab19d4b5619c59613 Mon Sep 17 00:00:00 2001 From: ghostbuster91 Date: Wed, 25 Sep 2024 17:10:56 +0200 Subject: [PATCH 1/3] fix: Don't assume that all service bindings existed before --- .../aws/traits/auth/diff/SigV4Migration.java | 38 ++++++++++--------- .../diffs/no-old-sigv4-new-service.a.smithy | 21 ++++++++++ .../diffs/no-old-sigv4-new-service.b.smithy | 30 +++++++++++++++ .../diffs/no-old-sigv4-new-service.events | 1 + 4 files changed, 73 insertions(+), 17 deletions(-) create mode 100644 smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.a.smithy create mode 100644 smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.b.smithy create mode 100644 smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.events diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java index 890c9fda867..4875160a340 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java @@ -83,23 +83,27 @@ public List evaluate(Differences differences) { } // Validate Operation effective auth schemes for (ServiceShape newServiceShape : newOperationServiceBindings) { - ServiceShape oldServiceShape = oldModel.expectShape(newServiceShape.getId(), ServiceShape.class); - OperationShape oldOperationShape = change.getOldShape(); - List oldAuthSchemes = oldServiceIndex - .getEffectiveAuthSchemes(oldServiceShape, oldOperationShape) - .keySet() - .stream() - .collect(Collectors.toList()); - List newAuthSchemes = newServiceIndex - .getEffectiveAuthSchemes(newServiceShape, newOperationShape) - .keySet() - .stream() - .collect(Collectors.toList()); - validateMigration( - newOperationShape, - oldAuthSchemes, - newAuthSchemes, - events); + oldModel.getShape(newServiceShape.getId()) + .filter(ServiceShape.class::isInstance) + .map(s -> (ServiceShape) s) + .ifPresent(oldServiceShape -> { + OperationShape oldOperationShape = change.getOldShape(); + List oldAuthSchemes = oldServiceIndex + .getEffectiveAuthSchemes(oldServiceShape, oldOperationShape) + .keySet() + .stream() + .collect(Collectors.toList()); + List newAuthSchemes = newServiceIndex + .getEffectiveAuthSchemes(newServiceShape, newOperationShape) + .keySet() + .stream() + .collect(Collectors.toList()); + validateMigration( + newOperationShape, + oldAuthSchemes, + newAuthSchemes, + events); + }); } } diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.a.smithy b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.a.smithy new file mode 100644 index 00000000000..e75d0177d05 --- /dev/null +++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.a.smithy @@ -0,0 +1,21 @@ +$version: "2.0" + +metadata suppressions = [ + { + id: "ModifiedTrait.Update.smithy.api#auth" + namespace: "ns.foo" + } +] + +namespace ns.foo + +@auth([]) +@httpBearerAuth +service Service { + operations: [ + Operation + ] +} + +@auth([]) +operation Operation {} diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.b.smithy b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.b.smithy new file mode 100644 index 00000000000..44870b7e793 --- /dev/null +++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.b.smithy @@ -0,0 +1,30 @@ +$version: "2.0" + +metadata suppressions = [ + { + id: "ModifiedTrait.Update.smithy.api#auth" + namespace: "ns.foo" + } +] + +namespace ns.foo + +@auth([httpBearerAuth]) +@httpBearerAuth +service Service { + operations: [ + Operation + ] +} + +@auth([httpBearerAuth]) +@httpBearerAuth +service NewService { + operations: [ + Operation + ] +} + + +@auth([httpBearerAuth]) +operation Operation {} diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.events b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.events new file mode 100644 index 00000000000..5c19fc68de5 --- /dev/null +++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.events @@ -0,0 +1 @@ +[NOTE] ns.foo#NewService: Added service `ns.foo#NewService` | AddedShape \ No newline at end of file From 18b7f1fcf514df2f8d36c313de1e4dd74893832a Mon Sep 17 00:00:00 2001 From: Jaykumar Gosar <5666661+gosar@users.noreply.github.com> Date: Thu, 26 Sep 2024 14:29:35 -0700 Subject: [PATCH 2/3] Update smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jakub Kozłowski --- .../amazon/smithy/aws/traits/auth/diff/SigV4Migration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java index 4875160a340..87e91abf114 100644 --- a/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java +++ b/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/auth/diff/SigV4Migration.java @@ -84,7 +84,7 @@ public List evaluate(Differences differences) { // Validate Operation effective auth schemes for (ServiceShape newServiceShape : newOperationServiceBindings) { oldModel.getShape(newServiceShape.getId()) - .filter(ServiceShape.class::isInstance) + .filter(Shape::isServiceShape) .map(s -> (ServiceShape) s) .ifPresent(oldServiceShape -> { OperationShape oldOperationShape = change.getOldShape(); From c8319ee00ae9e97bb77b4e461509ab05875919ef Mon Sep 17 00:00:00 2001 From: Jaykumar Gosar <5666661+gosar@users.noreply.github.com> Date: Thu, 26 Sep 2024 14:32:33 -0700 Subject: [PATCH 3/3] Update smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.events --- .../smithy/aws/traits/diffs/no-old-sigv4-new-service.events | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.events b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.events index 5c19fc68de5..7ebdd3d2dc3 100644 --- a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.events +++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/diffs/no-old-sigv4-new-service.events @@ -1 +1 @@ -[NOTE] ns.foo#NewService: Added service `ns.foo#NewService` | AddedShape \ No newline at end of file +[NOTE] ns.foo#NewService: Added service `ns.foo#NewService` | AddedShape