Skip to content

Commit a8969e2

Browse files
committed
prettier fix
1 parent 3ce6a0a commit a8969e2

File tree

2 files changed

+62
-73
lines changed

2 files changed

+62
-73
lines changed

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

+52-63
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.util.HashMap;
44
import java.util.Map;
5-
65
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
76
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
87
import software.amazon.awssdk.services.dynamodb.model.*;
@@ -107,31 +106,28 @@ public static void SharedCacheAcrossHierarchicalKeyringsGetItemPutItem(
107106
// using the Material Providers Library
108107
// This CMC takes in:
109108
// - CacheType
110-
final MaterialProviders matProv =
111-
MaterialProviders.builder()
112-
.MaterialProvidersConfig(MaterialProvidersConfig.builder().build())
113-
.build();
109+
final MaterialProviders matProv = MaterialProviders.builder()
110+
.MaterialProvidersConfig(MaterialProvidersConfig.builder().build())
111+
.build();
114112

115-
final CacheType cache =
116-
CacheType.builder()
117-
.Default(DefaultCache.builder().entryCapacity(100).build())
118-
.build();
113+
final CacheType cache = CacheType.builder()
114+
.Default(DefaultCache.builder().entryCapacity(100).build())
115+
.build();
119116

120117
final CreateCryptographicMaterialsCacheInput cryptographicMaterialsCacheInput =
121-
CreateCryptographicMaterialsCacheInput.builder()
122-
.cache(cache)
123-
.build();
118+
CreateCryptographicMaterialsCacheInput.builder().cache(cache).build();
124119

125120
final ICryptographicMaterialsCache sharedCryptographicMaterialsCache =
126-
matProv.CreateCryptographicMaterialsCache(cryptographicMaterialsCacheInput);
121+
matProv.CreateCryptographicMaterialsCache(
122+
cryptographicMaterialsCacheInput
123+
);
127124

128125
// 2. Create a CacheType object for the sharedCryptographicMaterialsCache
129126
// Note that the `cache` parameter in the Hierarchical Keyring Input takes a `CacheType` as input
130-
final CacheType sharedCache =
131-
CacheType.builder()
132-
// This is the `Shared` CacheType that passes an already initialized shared cache
133-
.Shared(sharedCryptographicMaterialsCache)
134-
.build();
127+
final CacheType sharedCache = CacheType.builder()
128+
// This is the `Shared` CacheType that passes an already initialized shared cache
129+
.Shared(sharedCryptographicMaterialsCache)
130+
.build();
135131

136132
// Initial KeyStore Setup: This example requires that you have already
137133
// created your KeyStore, and have populated it with a new branch key.
@@ -141,11 +137,9 @@ public static void SharedCacheAcrossHierarchicalKeyringsGetItemPutItem(
141137
// to initially create and populate your KeyStore.
142138
// Note that keyStoreTableName is the physical Key Store,
143139
// and keystore1 is instances of this physical Key Store.
144-
final KeyStore keystore1 = KeyStore
145-
.builder()
140+
final KeyStore keystore1 = KeyStore.builder()
146141
.KeyStoreConfig(
147-
KeyStoreConfig
148-
.builder()
142+
KeyStoreConfig.builder()
149143
.ddbClient(DynamoDbClient.create())
150144
.ddbTableName(keyStoreTableName)
151145
.logicalKeyStoreName(logicalKeyStoreName)
@@ -161,7 +155,7 @@ public static void SharedCacheAcrossHierarchicalKeyringsGetItemPutItem(
161155
// the shared Cache and the BranchKeyId.
162156
// Note that we are now providing an already initialized shared cache instead of just mentioning
163157
// the cache type and the Hierarchical Keyring initializing a cache at initialization.
164-
158+
165159
// This example creates a Hierarchical Keyring for a single BranchKeyId. You can, however, use a
166160
// BranchKeyIdSupplier as per your use-case. See the HierarchicalKeyringsExample.java for more
167161
// information.
@@ -170,8 +164,7 @@ public static void SharedCacheAcrossHierarchicalKeyringsGetItemPutItem(
170164
// Branch Key ID at the top of this example before creating Hierarchical Keyrings with a Shared Cache.
171165
// partitionId for this example is a random UUID
172166
final CreateAwsKmsHierarchicalKeyringInput keyringInput1 =
173-
CreateAwsKmsHierarchicalKeyringInput
174-
.builder()
167+
CreateAwsKmsHierarchicalKeyringInput.builder()
175168
.keyStore(keystore1)
176169
.branchKeyId(branchKeyId)
177170
.ttlSeconds(600) // This dictates how often we call back to KMS to authorize use of the branch keys
@@ -180,7 +173,7 @@ public static void SharedCacheAcrossHierarchicalKeyringsGetItemPutItem(
180173
.build();
181174
final IKeyring hierarchicalKeyring1 =
182175
matProv.CreateAwsKmsHierarchicalKeyring(keyringInput1);
183-
176+
184177
// 4. Configure which attributes are encrypted and/or signed when writing new items.
185178
// For each attribute that may exist on the items we plan to write to our DynamoDbTable,
186179
// we must explicitly configure how they should be treated during item encryption:
@@ -196,23 +189,27 @@ public static void SharedCacheAcrossHierarchicalKeyringsGetItemPutItem(
196189
);
197190

198191
// 5. Get the DDB Client for Hierarchical Keyring 1.
199-
final DynamoDbClient ddbClient1 = GetDDBClient(ddbTableName, hierarchicalKeyring1, attributeActionsOnEncrypt);
192+
final DynamoDbClient ddbClient1 = GetDDBClient(
193+
ddbTableName,
194+
hierarchicalKeyring1,
195+
attributeActionsOnEncrypt
196+
);
200197

201198
// 6. Encrypt Decrypt roundtrip with ddbClient1
202199
PutGetItems(ddbTableName, ddbClient1);
203200

204201
// Through the above encrypt and decrypt roundtrip, the cache will be populated and
205202
// the cache entries can be used by another Hierarchical Keyring with the
206203
// - Same Partition ID
207-
// - Same Logical Key Store Name of the Key Store for the Hierarchical Keyring
204+
// - Same Logical Key Store Name of the Key Store for the Hierarchical Keyring
208205
// - Same Branch Key ID
209206

210207
// 7. Configure your KeyStore resource keystore2.
211208
// This SHOULD be the same configuration that you used
212209
// to initially create and populate your physical KeyStore.
213210
// Note that keyStoreTableName is the physical Key Store,
214211
// and keystore2 is instances of this physical Key Store.
215-
212+
216213
// Note that for this example, keystore2 is identical to keystore1.
217214
// You can optionally change configurations like KMS Client or KMS Key ID based
218215
// on your use-case.
@@ -224,11 +221,9 @@ public static void SharedCacheAcrossHierarchicalKeyringsGetItemPutItem(
224221
// - If you set the Logical Key Store Names for K1 and K2 to be different,
225222
// HK1 (which uses Key Store instance K1) and HK2 (which uses Key Store
226223
// instance K2) will NOT be able to share cache entries.
227-
final KeyStore keystore2 = KeyStore
228-
.builder()
224+
final KeyStore keystore2 = KeyStore.builder()
229225
.KeyStoreConfig(
230-
KeyStoreConfig
231-
.builder()
226+
KeyStoreConfig.builder()
232227
.ddbClient(DynamoDbClient.create())
233228
.ddbTableName(keyStoreTableName)
234229
.logicalKeyStoreName(logicalKeyStoreName)
@@ -248,8 +243,7 @@ public static void SharedCacheAcrossHierarchicalKeyringsGetItemPutItem(
248243
// Branch Key ID at the top of this example before creating Hierarchical Keyrings with a Shared Cache.
249244
// partitionId for this example is a random UUID
250245
final CreateAwsKmsHierarchicalKeyringInput keyringInput2 =
251-
CreateAwsKmsHierarchicalKeyringInput
252-
.builder()
246+
CreateAwsKmsHierarchicalKeyringInput.builder()
253247
.keyStore(keystore2)
254248
.branchKeyId(branchKeyId)
255249
.ttlSeconds(600) // This dictates how often we call back to KMS to authorize use of the branch keys
@@ -260,7 +254,11 @@ public static void SharedCacheAcrossHierarchicalKeyringsGetItemPutItem(
260254
matProv.CreateAwsKmsHierarchicalKeyring(keyringInput2);
261255

262256
// 9. Get the DDB Client for Hierarchical Keyring 2.
263-
final DynamoDbClient ddbClient2 = GetDDBClient(ddbTableName, hierarchicalKeyring2, attributeActionsOnEncrypt);
257+
final DynamoDbClient ddbClient2 = GetDDBClient(
258+
ddbTableName,
259+
hierarchicalKeyring2,
260+
attributeActionsOnEncrypt
261+
);
264262

265263
// 10. Encrypt Decrypt roundtrip with ddbClient2
266264
PutGetItems(ddbTableName, ddbClient2);
@@ -304,41 +302,37 @@ public static DynamoDbClient GetDDBClient(
304302
// Create the DynamoDb Encryption configuration for the table we will be writing to.
305303
final Map<String, DynamoDbTableEncryptionConfig> tableConfigs =
306304
new HashMap<>();
307-
final DynamoDbTableEncryptionConfig config = DynamoDbTableEncryptionConfig
308-
.builder()
309-
.logicalTableName(ddbTableName)
310-
.partitionKeyName("partition_key")
311-
.sortKeyName("sort_key")
312-
.attributeActionsOnEncrypt(attributeActionsOnEncrypt)
313-
.keyring(hierarchicalKeyring)
314-
.allowedUnsignedAttributePrefix(unsignAttrPrefix)
315-
.build();
305+
final DynamoDbTableEncryptionConfig config =
306+
DynamoDbTableEncryptionConfig.builder()
307+
.logicalTableName(ddbTableName)
308+
.partitionKeyName("partition_key")
309+
.sortKeyName("sort_key")
310+
.attributeActionsOnEncrypt(attributeActionsOnEncrypt)
311+
.keyring(hierarchicalKeyring)
312+
.allowedUnsignedAttributePrefix(unsignAttrPrefix)
313+
.build();
316314
tableConfigs.put(ddbTableName, config);
317315

318316
// Create the DynamoDb Encryption Interceptor
319317
DynamoDbEncryptionInterceptor encryptionInterceptor =
320-
DynamoDbEncryptionInterceptor
321-
.builder()
318+
DynamoDbEncryptionInterceptor.builder()
322319
.config(
323-
DynamoDbTablesEncryptionConfig
324-
.builder()
320+
DynamoDbTablesEncryptionConfig.builder()
325321
.tableEncryptionConfigs(tableConfigs)
326322
.build()
327323
)
328324
.build();
329325

330326
// Create a new AWS SDK DynamoDb client using the DynamoDb Encryption Interceptor above
331-
final DynamoDbClient ddbClient = DynamoDbClient
332-
.builder()
327+
final DynamoDbClient ddbClient = DynamoDbClient.builder()
333328
.overrideConfiguration(
334-
ClientOverrideConfiguration
335-
.builder()
329+
ClientOverrideConfiguration.builder()
336330
.addExecutionInterceptor(encryptionInterceptor)
337331
.build()
338332
)
339333
.build();
340-
341-
return ddbClient;
334+
335+
return ddbClient;
342336
}
343337

344338
public static void PutGetItems(
@@ -359,8 +353,7 @@ public static void PutGetItems(
359353
AttributeValue.builder().s("encrypt and sign me!").build()
360354
);
361355

362-
final PutItemRequest putRequest = PutItemRequest
363-
.builder()
356+
final PutItemRequest putRequest = PutItemRequest.builder()
364357
.tableName(ddbTableName)
365358
.item(item)
366359
.build();
@@ -377,14 +370,10 @@ public static void PutGetItems(
377370
// BranchKeyIdSupplier as per your use-case. See the HierarchicalKeyringsExample.java for more
378371
// information.
379372
final HashMap<String, AttributeValue> keyToGet = new HashMap<>();
380-
keyToGet.put(
381-
"partition_key",
382-
AttributeValue.builder().s("id").build()
383-
);
373+
keyToGet.put("partition_key", AttributeValue.builder().s("id").build());
384374
keyToGet.put("sort_key", AttributeValue.builder().n("0").build());
385375

386-
final GetItemRequest getRequest = GetItemRequest
387-
.builder()
376+
final GetItemRequest getRequest = GetItemRequest.builder()
388377
.key(keyToGet)
389378
.tableName(ddbTableName)
390379
.build();

Examples/runtimes/java/DynamoDbEncryption/src/test/java/software/amazon/cryptography/examples/keyring/TestSharedCacheAcrossHierarchicalKeyringsExample.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
public class TestSharedCacheAcrossHierarchicalKeyringsExample {
88

99
@Test
10-
public void TestSharedCacheAcrossHierarchicalKeyringsExample() throws InterruptedException {
10+
public void TestSharedCacheAcrossHierarchicalKeyringsExample()
11+
throws InterruptedException {
1112
// Create new branch key for test
1213
String keyId = CreateKeyStoreKeyExample.KeyStoreCreateKey(
1314
TestUtils.TEST_KEYSTORE_NAME,
@@ -19,14 +20,13 @@ public void TestSharedCacheAcrossHierarchicalKeyringsExample() throws Interrupte
1920
// our test fails due to eventual consistency issues.
2021
Thread.sleep(5000);
2122

22-
SharedCacheAcrossHierarchicalKeyringsExample
23-
.SharedCacheAcrossHierarchicalKeyringsGetItemPutItem(
24-
TestUtils.TEST_DDB_TABLE_NAME,
25-
keyId,
26-
TestUtils.TEST_KEYSTORE_NAME,
27-
TestUtils.TEST_LOGICAL_KEYSTORE_NAME,
28-
TestUtils.TEST_PARTITION_ID,
29-
TestUtils.TEST_KEYSTORE_KMS_KEY_ID
30-
);
23+
SharedCacheAcrossHierarchicalKeyringsExample.SharedCacheAcrossHierarchicalKeyringsGetItemPutItem(
24+
TestUtils.TEST_DDB_TABLE_NAME,
25+
keyId,
26+
TestUtils.TEST_KEYSTORE_NAME,
27+
TestUtils.TEST_LOGICAL_KEYSTORE_NAME,
28+
TestUtils.TEST_PARTITION_ID,
29+
TestUtils.TEST_KEYSTORE_KMS_KEY_ID
30+
);
3131
}
3232
}

0 commit comments

Comments
 (0)