Skip to content

Commit

Permalink
chore(Mutations): address feedback on #742
Browse files Browse the repository at this point in the history
See #742
  • Loading branch information
texastony committed Sep 28, 2024
1 parent a2a28ea commit 6b46a17
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,49 +39,51 @@ 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;

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--;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<KmsException> kmsExceptions = new ArrayList<>();
Expand All @@ -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;
Expand All @@ -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(
Expand Down

0 comments on commit 6b46a17

Please sign in to comment.