Skip to content

Commit 9cedf08

Browse files
committed
Update AWS SDK and remaining examples to use PUT instead of CLOBBER
Update the AWS SDK to latest in order to get access to SaveBehavior.PUT for examples. Update tests to use the more general Function<T, T> instead of UnaryOperator<T>. Make it so EncryptionContextOperators can't be instantiated by adding a private constructor.
1 parent 7ab7fd9 commit 9cedf08

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

examples/com/amazonaws/examples/AwsKmsEncryptedObject.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public static void encryptRecord(final String cmkArn, final String region) {
5252
// Encryptor creation
5353
final DynamoDBEncryptor encryptor = DynamoDBEncryptor.getInstance(cmp);
5454
// Mapper Creation
55-
// Please note the use of SaveBehavior.CLOBBER (SaveBehavior.PUT works as well).
55+
// Please note the use of SaveBehavior.PUT (SaveBehavior.CLOBBER works as well).
5656
// Omitting this can result in data-corruption.
57-
DynamoDBMapperConfig mapperConfig = DynamoDBMapperConfig.builder().withSaveBehavior(SaveBehavior.CLOBBER).build();
57+
DynamoDBMapperConfig mapperConfig = DynamoDBMapperConfig.builder().withSaveBehavior(SaveBehavior.PUT).build();
5858
DynamoDBMapper mapper = new DynamoDBMapper(ddb, mapperConfig, new AttributeEncryptor(encryptor));
5959

6060
System.out.println("Plaintext Record: " + record);

examples/com/amazonaws/examples/EncryptionContextOverridesWithDynamoDBMapper.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ public static void encryptRecord(final String cmkArn,
7171
);
7272

7373
// Mapper Creation
74-
// Please note the use of SaveBehavior.CLOBBER (SaveBehavior.PUT works as well).
74+
// Please note the use of SaveBehavior.PUT (SaveBehavior.CLOBBER works as well).
7575
// Omitting this can result in data-corruption.
7676
DynamoDBMapperConfig mapperConfig = DynamoDBMapperConfig.builder()
77-
.withSaveBehavior(DynamoDBMapperConfig.SaveBehavior.CLOBBER).build();
77+
.withSaveBehavior(DynamoDBMapperConfig.SaveBehavior.PUT).build();
7878
DynamoDBMapper mapper = new DynamoDBMapper(ddb, mapperConfig, new AttributeEncryptor(encryptor));
7979

8080
System.out.println("Plaintext Record: " + record.toString());

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<dependency>
4444
<groupId>com.amazonaws</groupId>
4545
<artifactId>aws-java-sdk-bom</artifactId>
46-
<version>1.11.434</version>
46+
<version>1.11.460</version>
4747
<type>pom</type>
4848
<scope>import</scope>
4949
</dependency>

src/main/java/com/amazonaws/services/dynamodbv2/datamodeling/encryption/utils/EncryptionContextOperators.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
* Implementations of common operators for overriding the EncryptionContext
1010
*/
1111
public class EncryptionContextOperators {
12+
13+
// Prevent instantiation
14+
private EncryptionContextOperators() {
15+
}
16+
1217
/**
1318
* An operator for overriding EncryptionContext's table name for a specific DynamoDBEncryptor. If any table names or
1419
* the encryption context itself is null, then it returns the original EncryptionContext.
@@ -35,7 +40,6 @@ public static UnaryOperator<EncryptionContext> overrideEncryptionContextTableNam
3540
};
3641
}
3742

38-
3943
/**
4044
* An operator for mapping multiple table names in the Encryption Context to a new table name. If the table name for
4145
* a given EncryptionContext is missing, then it returns the original EncryptionContext. Similarly, it returns the
@@ -60,6 +64,4 @@ public static UnaryOperator<EncryptionContext> overrideEncryptionContextTableNam
6064
}
6165
};
6266
}
63-
64-
6567
}

src/test/java/com/amazonaws/services/dynamodbv2/datamodeling/encryption/utils/EncryptionContextOperatorsTest.java

+7-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import java.util.HashMap;
77
import java.util.Map;
8-
import java.util.function.UnaryOperator;
8+
import java.util.function.Function;
99

1010
import static com.amazonaws.services.dynamodbv2.datamodeling.encryption.utils.EncryptionContextOperators.overrideEncryptionContextTableName;
1111
import static com.amazonaws.services.dynamodbv2.datamodeling.encryption.utils.EncryptionContextOperators.overrideEncryptionContextTableNameUsingMap;
@@ -15,7 +15,7 @@ public class EncryptionContextOperatorsTest {
1515

1616
@Test
1717
public void testCreateEncryptionContextTableNameOverride_expectedOverride() {
18-
UnaryOperator<EncryptionContext> myNewTableName = overrideEncryptionContextTableName("OriginalTableName", "MyNewTableName");
18+
Function<EncryptionContext, EncryptionContext> myNewTableName = overrideEncryptionContextTableName("OriginalTableName", "MyNewTableName");
1919

2020
EncryptionContext context = new EncryptionContext.Builder().withTableName("OriginalTableName").build();
2121

@@ -56,7 +56,7 @@ public void testCreateEncryptionContextTableNameOverrideMap_expectedOverride() {
5656
tableNameOverrides.put("OriginalTableName", "MyNewTableName");
5757

5858

59-
UnaryOperator<EncryptionContext> nameOverrideMap =
59+
Function<EncryptionContext, EncryptionContext> nameOverrideMap =
6060
overrideEncryptionContextTableNameUsingMap(tableNameOverrides);
6161

6262
EncryptionContext context = new EncryptionContext.Builder().withTableName("OriginalTableName").build();
@@ -74,7 +74,7 @@ public void testCreateEncryptionContextTableNameOverrideMap_multipleOverrides()
7474
tableNameOverrides.put("OriginalTableName2", "MyNewTableName2");
7575

7676

77-
UnaryOperator<EncryptionContext> overrideOperator =
77+
Function<EncryptionContext, EncryptionContext> overrideOperator =
7878
overrideEncryptionContextTableNameUsingMap(tableNameOverrides);
7979

8080
EncryptionContext context = new EncryptionContext.Builder().withTableName("OriginalTableName1").build();
@@ -136,17 +136,15 @@ public void testNullCasesCreateEncryptionContextTableNameOverrideFromMap_nullMap
136136

137137

138138
private void assertEncryptionContextUnchanged(EncryptionContext encryptionContext, String originalTableName, String newTableName) {
139-
UnaryOperator<EncryptionContext> encryptionContextTableNameOverride = overrideEncryptionContextTableName(originalTableName, newTableName);
139+
Function<EncryptionContext, EncryptionContext> encryptionContextTableNameOverride = overrideEncryptionContextTableName(originalTableName, newTableName);
140140
EncryptionContext newEncryptionContext = encryptionContextTableNameOverride.apply(encryptionContext);
141141
assertEquals(encryptionContext, newEncryptionContext);
142142
}
143143

144144

145145
private void assertEncryptionContextUnchangedFromMap(EncryptionContext encryptionContext, Map<String, String> overrideMap) {
146-
UnaryOperator<EncryptionContext> encryptionContextTableNameOverrideFromMap = overrideEncryptionContextTableNameUsingMap(overrideMap);
146+
Function<EncryptionContext, EncryptionContext> encryptionContextTableNameOverrideFromMap = overrideEncryptionContextTableNameUsingMap(overrideMap);
147147
EncryptionContext newEncryptionContext = encryptionContextTableNameOverrideFromMap.apply(encryptionContext);
148148
assertEquals(encryptionContext, newEncryptionContext);
149149
}
150-
151-
152-
}
150+
}

0 commit comments

Comments
 (0)