From 6b46a17c874e0ce87ea2b59c38f6de9a9b794b72 Mon Sep 17 00:00:00 2001 From: texastony <5892063+texastony@users.noreply.github.com> Date: Sat, 28 Sep 2024 13:13:48 -0700 Subject: [PATCH] chore(Mutations): address feedback on #742 See https://github.com/aws/aws-cryptographic-material-providers-library/pull/742 --- .../example/hierarchy/AdminProvider.java | 2 +- .../example/hierarchy/CreateKeyExample.java | 8 ++--- .../example/hierarchy/MutationExample.java | 32 +++++++++-------- .../example/hierarchy/VersionKeyExample.java | 4 +-- .../amazon/cryptography/example/Fixtures.java | 4 +-- .../MutationKmsAccessInFlightTest.java | 34 +++++++++---------- 6 files changed, 43 insertions(+), 41 deletions(-) diff --git a/AwsCryptographicMaterialProviders/runtimes/java/src/examples/java/software/amazon/cryptography/example/hierarchy/AdminProvider.java b/AwsCryptographicMaterialProviders/runtimes/java/src/examples/java/software/amazon/cryptography/example/hierarchy/AdminProvider.java index 1facbb450..6bd822f53 100644 --- a/AwsCryptographicMaterialProviders/runtimes/java/src/examples/java/software/amazon/cryptography/example/hierarchy/AdminProvider.java +++ b/AwsCryptographicMaterialProviders/runtimes/java/src/examples/java/software/amazon/cryptography/example/hierarchy/AdminProvider.java @@ -69,7 +69,7 @@ public static String mutatedItemsToString( ) { return mutatedItems .stream() - .map(item -> String.format("%s : %s", item.itemType(), item.description()) + .map(item -> String.format("%s : %s", item.ItemType(), item.Description()) ) .collect(Collectors.joining(",\n")); } diff --git a/AwsCryptographicMaterialProviders/runtimes/java/src/examples/java/software/amazon/cryptography/example/hierarchy/CreateKeyExample.java b/AwsCryptographicMaterialProviders/runtimes/java/src/examples/java/software/amazon/cryptography/example/hierarchy/CreateKeyExample.java index 2bfc1966e..107bf5a24 100644 --- a/AwsCryptographicMaterialProviders/runtimes/java/src/examples/java/software/amazon/cryptography/example/hierarchy/CreateKeyExample.java +++ b/AwsCryptographicMaterialProviders/runtimes/java/src/examples/java/software/amazon/cryptography/example/hierarchy/CreateKeyExample.java @@ -71,16 +71,16 @@ public static String CreateKey( .builder() // This is the KMS ARN that will be used to protect the Branch Key. // It is a required argument. - .kmsArn(KMSIdentifier.builder().kmsKeyArn(kmsKeyArn).build()) + .KmsArn(KMSIdentifier.builder().KmsKeyArn(kmsKeyArn).build()) // If you need to specify the Identifier for a Branch Key, you may. // This is an optional argument. - .branchKeyIdentifier(branchKeyId) + .Identifier(branchKeyId) // If a branch key Identifier is provided, // custom encryption context MUST be provided as well. - .encryptionContext(encryptionContext) + .EncryptionContext(encryptionContext) .build() ) - .branchKeyIdentifier(); + .Identifier(); assert actualBranchKeyId.equals(branchKeyId); return branchKeyId; diff --git a/AwsCryptographicMaterialProviders/runtimes/java/src/examples/java/software/amazon/cryptography/example/hierarchy/MutationExample.java b/AwsCryptographicMaterialProviders/runtimes/java/src/examples/java/software/amazon/cryptography/example/hierarchy/MutationExample.java index 404cebb55..0d207a5b6 100644 --- a/AwsCryptographicMaterialProviders/runtimes/java/src/examples/java/software/amazon/cryptography/example/hierarchy/MutationExample.java +++ b/AwsCryptographicMaterialProviders/runtimes/java/src/examples/java/software/amazon/cryptography/example/hierarchy/MutationExample.java @@ -39,25 +39,25 @@ public static String End2End( terminalEC.put("Robbie", "is a dog."); Mutations mutations = Mutations .builder() - .terminalEncryptionContext(terminalEC) - .terminalKmsArn(kmsKeyArnTerminal) + .TerminalEncryptionContext(terminalEC) + .TerminalKmsArn(kmsKeyArnTerminal) .build(); InitializeMutationInput initInput = InitializeMutationInput .builder() - .mutations(mutations) - .branchKeyIdentifier(branchKeyId) - .strategy(strategy) + .Mutations(mutations) + .Identifier(branchKeyId) + .Strategy(strategy) .build(); InitializeMutationOutput initOutput = admin.InitializeMutation(initInput); - MutationToken token = initOutput.mutationToken(); + MutationToken token = initOutput.MutationToken(); System.out.println( "InitLogs: " + branchKeyId + " items: \n" + - AdminProvider.mutatedItemsToString(initOutput.mutatedBranchKeyItems()) + AdminProvider.mutatedItemsToString(initOutput.MutatedBranchKeyItems()) ); boolean done = false; int limitLoop = 10; @@ -65,23 +65,25 @@ public static String End2End( while (!done) { ApplyMutationInput applyInput = ApplyMutationInput .builder() - .mutationToken(token) - .pageSize(98) - .strategy(strategy) + .MutationToken(token) + .PageSize(98) + .Strategy(strategy) .build(); ApplyMutationOutput applyOutput = admin.ApplyMutation(applyInput); - ApplyMutationResult result = applyOutput.result(); + ApplyMutationResult result = applyOutput.MutationResult(); System.out.println( "ApplyLogs: " + branchKeyId + " items: \n" + - AdminProvider.mutatedItemsToString(applyOutput.mutatedBranchKeyItems()) + AdminProvider.mutatedItemsToString(applyOutput.MutatedBranchKeyItems()) ); - if (result.continueMutation() != null) token = result.continueMutation(); - if (result.completeMutation() != null) done = true; - if (limitLoop == 0) done = true; + if (result.ContinueMutation() != null) {token = result.ContinueMutation();} + if (result.CompleteMutation() != null) {done = true;} + if (limitLoop == 0) { + done = true; + } limitLoop--; } diff --git a/AwsCryptographicMaterialProviders/runtimes/java/src/examples/java/software/amazon/cryptography/example/hierarchy/VersionKeyExample.java b/AwsCryptographicMaterialProviders/runtimes/java/src/examples/java/software/amazon/cryptography/example/hierarchy/VersionKeyExample.java index 27c3c99ee..ea93ab050 100644 --- a/AwsCryptographicMaterialProviders/runtimes/java/src/examples/java/software/amazon/cryptography/example/hierarchy/VersionKeyExample.java +++ b/AwsCryptographicMaterialProviders/runtimes/java/src/examples/java/software/amazon/cryptography/example/hierarchy/VersionKeyExample.java @@ -63,9 +63,9 @@ public static String VersionKey( // This is the KMS ARN that will be used to protect the Branch Key. // It is a required argument. // This ARN MUST match the ARN that protects the Branch Key. - .kmsArn(KMSIdentifier.builder().kmsKeyArn(kmsKeyArn).build()) + .KmsArn(KMSIdentifier.builder().KmsKeyArn(kmsKeyArn).build()) // This the Identifier for the Branch Key that is being rotated/versioned. - .branchKeyIdentifier(branchKeyId) + .Identifier(branchKeyId) .build() ); diff --git a/AwsCryptographicMaterialProviders/runtimes/java/src/testExamples/java/software/amazon/cryptography/example/Fixtures.java b/AwsCryptographicMaterialProviders/runtimes/java/src/testExamples/java/software/amazon/cryptography/example/Fixtures.java index 736144c39..83b1d0efa 100644 --- a/AwsCryptographicMaterialProviders/runtimes/java/src/testExamples/java/software/amazon/cryptography/example/Fixtures.java +++ b/AwsCryptographicMaterialProviders/runtimes/java/src/testExamples/java/software/amazon/cryptography/example/Fixtures.java @@ -111,14 +111,14 @@ public static void cleanUpBranchKeyId( QueryForVersionsInput .builder() .Identifier(branchKeyId) - .pageSize(99) + .PageSize(99) .build() ); String physicalName = storage .GetKeyStorageInfo(GetKeyStorageInfoInput.builder().build()) .Name(); versions - .items() + .Items() .forEach(item -> deleteKeyStoreDdbItem( item.Identifier(), diff --git a/AwsCryptographicMaterialProviders/runtimes/java/src/testExamples/java/software/amazon/cryptography/example/hierarchy/MutationKmsAccessInFlightTest.java b/AwsCryptographicMaterialProviders/runtimes/java/src/testExamples/java/software/amazon/cryptography/example/hierarchy/MutationKmsAccessInFlightTest.java index cc2d42ef2..1c344186c 100644 --- a/AwsCryptographicMaterialProviders/runtimes/java/src/testExamples/java/software/amazon/cryptography/example/hierarchy/MutationKmsAccessInFlightTest.java +++ b/AwsCryptographicMaterialProviders/runtimes/java/src/testExamples/java/software/amazon/cryptography/example/hierarchy/MutationKmsAccessInFlightTest.java @@ -79,24 +79,24 @@ public void test() { Mutations mutations = Mutations .builder() - .terminalEncryptionContext(terminalEC) - .terminalKmsArn(MRK_ARN_WEST) + .TerminalEncryptionContext(terminalEC) + .TerminalKmsArn(MRK_ARN_WEST) .build(); InitializeMutationInput initInput = InitializeMutationInput .builder() - .mutations(mutations) - .branchKeyIdentifier(branchKeyId) - .strategy(strategyWest2) + .Mutations(mutations) + .Identifier(branchKeyId) + .Strategy(strategyWest2) .build(); InitializeMutationOutput initOutput = admin.InitializeMutation(initInput); - MutationToken token = initOutput.mutationToken(); + MutationToken token = initOutput.MutationToken(); System.out.println( "InitLogs: " + branchKeyId + " items: \n" + - AdminProvider.mutatedItemsToString(initOutput.mutatedBranchKeyItems()) + AdminProvider.mutatedItemsToString(initOutput.MutatedBranchKeyItems()) ); boolean done = false; List kmsExceptions = new ArrayList<>(); @@ -110,24 +110,24 @@ public void test() { if (limitLoop == 0) done = true; ApplyMutationInput applyInput = ApplyMutationInput .builder() - .mutationToken(token) - .pageSize(1) - .strategy(strategyDenyMrk) + .MutationToken(token) + .PageSize(1) + .Strategy(strategyDenyMrk) .build(); ApplyMutationOutput applyOutput = admin.ApplyMutation(applyInput); - ApplyMutationResult result = applyOutput.result(); + ApplyMutationResult result = applyOutput.MutationResult(); System.out.println( "ApplyLogs: " + branchKeyId + " items: \n" + AdminProvider.mutatedItemsToString( - applyOutput.mutatedBranchKeyItems() + applyOutput.MutatedBranchKeyItems() ) ); - if (result.continueMutation() != null) token = - result.continueMutation(); - if (result.completeMutation() != null) done = true; + if (result.ContinueMutation() != null) token = + result.ContinueMutation(); + if (result.CompleteMutation() != null) done = true; } catch (KmsException accessDenied) { boolean isFrom = accessDenied.getMessage().contains("ReEncryptFrom"); isFromThrown = isFromThrown || isFrom; @@ -146,11 +146,11 @@ public void test() { QueryForVersionsInput .builder() .Identifier(branchKeyId) - .pageSize(1) + .PageSize(1) .build() ); versions - .items() + .Items() .forEach(item -> { String typStr = item.EncryptionContext().get("type"); Fixtures.deleteKeyStoreDdbItem(