Skip to content

Commit 9c3e159

Browse files
auto commit
1 parent 849f5da commit 9c3e159

File tree

12 files changed

+142
-79
lines changed

12 files changed

+142
-79
lines changed

Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/BasicPutGetExample.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
*/
3232
public class BasicPutGetExample {
3333

34-
public static void PutItemGetItem(String kmsKeyId, String ddbTableName, String PartitionKeyName) {
34+
public static void PutItemGetItem(
35+
String kmsKeyId,
36+
String ddbTableName,
37+
String PartitionKeyName
38+
) {
3539
// 1. Create a Keyring. This Keyring will be responsible for protecting the data keys that protect your data.
3640
// For this example, we will create a AWS KMS Keyring with the AWS KMS Key we want to use.
3741
// We will use the `CreateMrkMultiKeyring` method to create this keyring,

Examples/runtimes/java/Migration/PlaintextToAWSDBE/src/main/java/software/amazon/cryptography/examples/awsdbe/MigrationExampleStep1.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public class MigrationExampleStep1 {
4545
public static void MigrationStep1(
4646
String kmsKeyId,
4747
String ddbTableName,
48-
int sortReadValue
48+
int sortReadValue,
49+
String partitionKey
4950
) {
5051
// 1. Create a Keyring. This Keyring will be responsible for protecting the data keys that protect your data.
5152
// We will use the `CreateMrkMultiKeyring` method to create this keyring,
@@ -143,7 +144,7 @@ public static void MigrationStep1(
143144
// 7. Put an item into your table using the DynamoDb Enhanced Client.
144145
// This item will be stored in plaintext.
145146
final SimpleClass item = new SimpleClass();
146-
item.setPartitionKey("PlaintextMigrationExample");
147+
item.setPartitionKey(partitionKey);
147148
item.setSortKey(1);
148149
item.setAttribute1("this will be encrypted and signed");
149150
item.setAttribute3("this will never be encrypted nor signed");
@@ -158,13 +159,13 @@ public static void MigrationStep1(
158159
// during Step 2 or after), then the item will be decrypted client-side
159160
// and surfaced as a plaintext item.
160161
SimpleClass itemToGet = new SimpleClass();
161-
itemToGet.setPartitionKey("PlaintextMigrationExample");
162+
itemToGet.setPartitionKey(partitionKey);
162163
itemToGet.setSortKey(sortReadValue);
163164

164165
SimpleClass returnedItem = table.getItem(itemToGet);
165166

166167
// Demonstrate we get the expected item back
167-
assert returnedItem.getPartitionKey().equals("PlaintextMigrationExample");
168+
assert returnedItem.getPartitionKey().equals(partitionKey);
168169
assert returnedItem
169170
.getAttribute1()
170171
.equals("this will be encrypted and signed");
@@ -180,6 +181,7 @@ public static void main(final String[] args) {
180181
final String ddbTableName = args[1];
181182
// You can manipulate this value to demonstrate reading records written in other steps
182183
final int sortReadValue = Integer.parseInt(args[2]);
183-
MigrationStep1(kmsKeyId, ddbTableName, sortReadValue);
184+
final String partitionKey = args[3];
185+
MigrationStep1(kmsKeyId, ddbTableName, sortReadValue, partitionKey);
184186
}
185187
}

Examples/runtimes/java/Migration/PlaintextToAWSDBE/src/main/java/software/amazon/cryptography/examples/awsdbe/MigrationExampleStep2.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public class MigrationExampleStep2 {
4545
public static void MigrationStep2(
4646
String kmsKeyId,
4747
String ddbTableName,
48-
int sortReadValue
48+
int sortReadValue,
49+
String partitionKey
4950
) {
5051
// 1. Continue to configure your Keyring, Table Schema, legacy attribute actions,
5152
// and allowedUnsignedAttributes, and old DynamoDBEncryptor as you did in Step 1.
@@ -121,7 +122,7 @@ public static void MigrationStep2(
121122
// 5. Put an item into your table using the DynamoDb Enhanced Client.
122123
// This item will be encrypted.
123124
final SimpleClass item = new SimpleClass();
124-
item.setPartitionKey("PlaintextMigrationExample");
125+
item.setPartitionKey(partitionKey);
125126
item.setSortKey(2);
126127
item.setAttribute1("this will be encrypted and signed");
127128
item.setAttribute3("this will never be encrypted nor signed");
@@ -136,13 +137,13 @@ public static void MigrationStep2(
136137
// during Step 2 or after), then the DDB enhanced client will decrypt the
137138
// item client-sid and surface it in our code as a plaintext item.
138139
SimpleClass itemToGet = new SimpleClass();
139-
itemToGet.setPartitionKey("PlaintextMigrationExample");
140+
itemToGet.setPartitionKey(partitionKey);
140141
itemToGet.setSortKey(sortReadValue);
141142

142143
SimpleClass returnedItem = table.getItem(itemToGet);
143144

144145
// Demonstrate we get the expected item back
145-
assert returnedItem.getPartitionKey().equals("PlaintextMigrationExample");
146+
assert returnedItem.getPartitionKey().equals(partitionKey);
146147
assert returnedItem
147148
.getAttribute1()
148149
.equals("this will be encrypted and signed");
@@ -158,6 +159,7 @@ public static void main(final String[] args) {
158159
final String ddbTableName = args[1];
159160
// You can manipulate this value to demonstrate reading records written in other steps
160161
final int sortReadValue = Integer.parseInt(args[2]);
161-
MigrationStep2(kmsKeyId, ddbTableName, sortReadValue);
162+
final String partitionKey = args[3];
163+
MigrationStep2(kmsKeyId, ddbTableName, sortReadValue, partitionKey);
162164
}
163165
}

Examples/runtimes/java/Migration/PlaintextToAWSDBE/src/main/java/software/amazon/cryptography/examples/awsdbe/MigrationExampleStep3.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public class MigrationExampleStep3 {
4040
public static void MigrationStep3(
4141
String kmsKeyId,
4242
String ddbTableName,
43-
int sortReadValue
43+
int sortReadValue,
44+
String partitionKey
4445
) {
4546
// 1. Create a Keyring. This Keyring will be responsible for protecting the data keys that protect your data.
4647
// We will use the `CreateMrkMultiKeyring` method to create this keyring,
@@ -115,7 +116,7 @@ public static void MigrationStep3(
115116
// 7. Put an item into your table using the DynamoDb Enhanced Client.
116117
// This item will be encrypted.
117118
final SimpleClass item = new SimpleClass();
118-
item.setPartitionKey("PlaintextMigrationExample");
119+
item.setPartitionKey(partitionKey);
119120
item.setSortKey(3);
120121
item.setAttribute1("this will be encrypted and signed");
121122
item.setAttribute3("this will never be encrypted nor signed");
@@ -131,13 +132,13 @@ public static void MigrationStep3(
131132
// during Step 2 or after), then the item will be decrypted client-side
132133
// and surfaced as a plaintext item.
133134
SimpleClass itemToGet = new SimpleClass();
134-
itemToGet.setPartitionKey("PlaintextMigrationExample");
135+
itemToGet.setPartitionKey(partitionKey);
135136
itemToGet.setSortKey(sortReadValue);
136137

137138
SimpleClass returnedItem = table.getItem(itemToGet);
138139

139140
// Demonstrate we get the expected item back
140-
assert returnedItem.getPartitionKey().equals("PlaintextMigrationExample");
141+
assert returnedItem.getPartitionKey().equals(partitionKey);
141142
assert returnedItem
142143
.getAttribute1()
143144
.equals("this will be encrypted and signed");
@@ -153,6 +154,7 @@ public static void main(final String[] args) {
153154
final String ddbTableName = args[1];
154155
// You can manipulate this value to demonstrate reading records written in other steps
155156
final int sortReadValue = Integer.parseInt(args[2]);
156-
MigrationStep3(kmsKeyId, ddbTableName, sortReadValue);
157+
final String partitionKey = args[3];
158+
MigrationStep3(kmsKeyId, ddbTableName, sortReadValue, partitionKey);
157159
}
158160
}

Examples/runtimes/java/Migration/PlaintextToAWSDBE/src/main/java/software/amazon/cryptography/examples/plaintext/MigrationExampleStep0.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ write a plaintext record to a table and read that record.
2828
*/
2929
public class MigrationExampleStep0 {
3030

31-
public static void MigrationStep0(String ddbTableName, int sortReadValue) {
31+
public static void MigrationStep0(
32+
String ddbTableName,
33+
int sortReadValue,
34+
String partitionKey
35+
) {
3236
// 1. Create a Table Schema over your annotated class.
3337
// See SimpleClass.java in this directory for a sample annotated class
3438
// for a plaintext item.
@@ -56,7 +60,7 @@ public static void MigrationStep0(String ddbTableName, int sortReadValue) {
5660
// 3. Put an example item into our DynamoDb table.
5761
// This item will be stored in plaintext.
5862
SimpleClass itemToPut = new SimpleClass();
59-
itemToPut.setPartitionKey("PlaintextMigrationExample");
63+
itemToPut.setPartitionKey(partitionKey);
6064
itemToPut.setSortKey(0);
6165
itemToPut.setAttribute1("this will be encrypted and signed");
6266
itemToPut.setAttribute3("this will never be encrypted nor signed");
@@ -76,13 +80,13 @@ public static void MigrationStep0(String ddbTableName, int sortReadValue) {
7680
// client-side encrypted items, you will need to configure encrypted reads on
7781
// your enhanced client (this is configured from Step 1 onwards).
7882
SimpleClass itemToGet = new SimpleClass();
79-
itemToGet.setPartitionKey("PlaintextMigrationExample");
83+
itemToGet.setPartitionKey(partitionKey);
8084
itemToGet.setSortKey(sortReadValue);
8185

8286
SimpleClass returnedItem = table.getItem(itemToGet);
8387

8488
// Demonstrate we get the expected item back
85-
assert returnedItem.getPartitionKey().equals("PlaintextMigrationExample");
89+
assert returnedItem.getPartitionKey().equals(partitionKey);
8690
assert returnedItem
8791
.getAttribute1()
8892
.equals("this will be encrypted and signed");
@@ -97,6 +101,7 @@ public static void main(final String[] args) {
97101
final String ddbTableName = args[0];
98102
// You can manipulate this value to demonstrate reading records written in other steps
99103
final int sortReadValue = Integer.parseInt(args[1]);
100-
MigrationStep0(ddbTableName, sortReadValue);
104+
final String partitionKey = args[2];
105+
MigrationStep0(ddbTableName, sortReadValue, partitionKey);
101106
}
102107
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
package software.amazon.cryptography.examples.migration.awsdbe;
1+
package software.amazon.cryptography.examples.migration;
2+
3+
import java.util.UUID;
24

35
public class TestUtils {
46

@@ -9,4 +11,7 @@ public class TestUtils {
911
// Our tests require access to DDB Table with this name
1012
public static final String TEST_DDB_TABLE_NAME =
1113
"DynamoDbEncryptionInterceptorTestTable";
14+
15+
public static final String PARTITION_KEY =
16+
"PlaintextMigrationExample" + UUID.randomUUID();
1217
}

Examples/runtimes/java/Migration/PlaintextToAWSDBE/src/test/java/software/amazon/cryptography/examples/migration/awsdbe/TestMigrationExampleStep1.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import software.amazon.cryptography.examples.awsdbe.MigrationExampleStep1;
55
import software.amazon.cryptography.examples.awsdbe.MigrationExampleStep2;
66
import software.amazon.cryptography.examples.awsdbe.MigrationExampleStep3;
7+
import software.amazon.cryptography.examples.migration.TestUtils;
78
import software.amazon.cryptography.examples.plaintext.MigrationExampleStep0;
89

910
public class TestMigrationExampleStep1 {
@@ -14,42 +15,52 @@ public void TestMigrationStep1() {
1415
MigrationExampleStep1.MigrationStep1(
1516
TestUtils.TEST_KMS_KEY_ID,
1617
TestUtils.TEST_DDB_TABLE_NAME,
17-
1
18+
1,
19+
TestUtils.PARTITION_KEY
1820
);
1921

2022
// Given: Step 0 has succeeded
21-
MigrationExampleStep0.MigrationStep0(TestUtils.TEST_DDB_TABLE_NAME, 0);
23+
MigrationExampleStep0.MigrationStep0(
24+
TestUtils.TEST_DDB_TABLE_NAME,
25+
0,
26+
TestUtils.PARTITION_KEY
27+
);
2228
// When: Execute Step 1 with sortReadValue=0, Then: Success (i.e. can read plaintext values)
2329
MigrationExampleStep1.MigrationStep1(
2430
TestUtils.TEST_KMS_KEY_ID,
2531
TestUtils.TEST_DDB_TABLE_NAME,
26-
0
32+
0,
33+
TestUtils.PARTITION_KEY
2734
);
2835

2936
// Given: Step 2 has succeeded
3037
MigrationExampleStep2.MigrationStep2(
3138
TestUtils.TEST_KMS_KEY_ID,
3239
TestUtils.TEST_DDB_TABLE_NAME,
33-
2
40+
2,
41+
TestUtils.PARTITION_KEY
3442
);
3543
// When: Execute Step 1 with sortReadValue=2, Then: Success (i.e. can read encrypted values)
3644
MigrationExampleStep1.MigrationStep1(
3745
TestUtils.TEST_KMS_KEY_ID,
3846
TestUtils.TEST_DDB_TABLE_NAME,
39-
2
47+
2,
48+
TestUtils.PARTITION_KEY
4049
);
4150

4251
// Given: Step 3 has succeeded
4352
MigrationExampleStep3.MigrationStep3(
4453
TestUtils.TEST_KMS_KEY_ID,
4554
TestUtils.TEST_DDB_TABLE_NAME,
46-
3
55+
3,
56+
TestUtils.PARTITION_KEY
4757
);
4858
// When: Execute Step 1 with sortReadValue=3, Then: Success (i.e. can read encrypted values)
4959
MigrationExampleStep1.MigrationStep1(
5060
TestUtils.TEST_KMS_KEY_ID,
5161
TestUtils.TEST_DDB_TABLE_NAME,
52-
3
62+
3,
63+
TestUtils.PARTITION_KEY
5364
);
5465
}
5566
}

Examples/runtimes/java/Migration/PlaintextToAWSDBE/src/test/java/software/amazon/cryptography/examples/migration/awsdbe/TestMigrationExampleStep2.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import software.amazon.cryptography.examples.awsdbe.MigrationExampleStep1;
55
import software.amazon.cryptography.examples.awsdbe.MigrationExampleStep2;
66
import software.amazon.cryptography.examples.awsdbe.MigrationExampleStep3;
7+
import software.amazon.cryptography.examples.migration.TestUtils;
78
import software.amazon.cryptography.examples.plaintext.MigrationExampleStep0;
89

910
public class TestMigrationExampleStep2 {
@@ -14,42 +15,52 @@ public void TestMigrationStep2() {
1415
MigrationExampleStep2.MigrationStep2(
1516
TestUtils.TEST_KMS_KEY_ID,
1617
TestUtils.TEST_DDB_TABLE_NAME,
17-
2
18+
2,
19+
TestUtils.PARTITION_KEY
1820
);
1921

2022
// Given: Step 0 has succeeded
21-
MigrationExampleStep0.MigrationStep0(TestUtils.TEST_DDB_TABLE_NAME, 0);
23+
MigrationExampleStep0.MigrationStep0(
24+
TestUtils.TEST_DDB_TABLE_NAME,
25+
0,
26+
TestUtils.PARTITION_KEY
27+
);
2228
// When: Execute Step 2 with sortReadValue=0, Then: Success (i.e. can read plaintext values)
2329
MigrationExampleStep2.MigrationStep2(
2430
TestUtils.TEST_KMS_KEY_ID,
2531
TestUtils.TEST_DDB_TABLE_NAME,
26-
0
32+
0,
33+
TestUtils.PARTITION_KEY
2734
);
2835

2936
// Given: Step 1 has succeeded
3037
MigrationExampleStep1.MigrationStep1(
3138
TestUtils.TEST_KMS_KEY_ID,
3239
TestUtils.TEST_DDB_TABLE_NAME,
33-
1
40+
1,
41+
TestUtils.PARTITION_KEY
3442
);
3543
// When: Execute Step 2 with sortReadValue=1, Then: Success (i.e. can read encrypted values)
3644
MigrationExampleStep2.MigrationStep2(
3745
TestUtils.TEST_KMS_KEY_ID,
3846
TestUtils.TEST_DDB_TABLE_NAME,
39-
1
47+
1,
48+
TestUtils.PARTITION_KEY
4049
);
4150

4251
// Given: Step 3 has succeeded
4352
MigrationExampleStep3.MigrationStep3(
4453
TestUtils.TEST_KMS_KEY_ID,
4554
TestUtils.TEST_DDB_TABLE_NAME,
46-
3
55+
3,
56+
TestUtils.PARTITION_KEY
4757
);
4858
// When: Execute Step 2 with sortReadValue=3, Then: Success (i.e. can read encrypted values)
4959
MigrationExampleStep2.MigrationStep2(
5060
TestUtils.TEST_KMS_KEY_ID,
5161
TestUtils.TEST_DDB_TABLE_NAME,
52-
3
62+
3,
63+
TestUtils.PARTITION_KEY
5364
);
5465
}
5566
}

0 commit comments

Comments
 (0)