1
1
package software .amazon .cryptography .dbencryptionsdk .dynamodb .enhancedclient ;
2
2
3
+ import java .util .*;
4
+ import java .util .stream .Collectors ;
5
+
6
+ import software .amazon .awssdk .enhanced .dynamodb .IndexMetadata ;
7
+ import software .amazon .awssdk .enhanced .dynamodb .KeyAttributeMetadata ;
8
+ import software .amazon .awssdk .enhanced .dynamodb .TableMetadata ;
9
+
3
10
import software .amazon .cryptography .dbencryptionsdk .dynamodb .model .DynamoDbTablesEncryptionConfig ;
4
11
import software .amazon .cryptography .dbencryptionsdk .dynamodb .model .DynamoDbEncryptionException ;
5
12
import software .amazon .cryptography .dbencryptionsdk .dynamodb .model .DynamoDbTableEncryptionConfig ;
6
13
import software .amazon .cryptography .dbencryptionsdk .structuredencryption .model .CryptoAction ;
7
14
import software .amazon .cryptography .dbencryptionsdk .dynamodb .DynamoDbEncryptionInterceptor ;
8
15
9
- import java .util .*;
10
- import java .util .stream .Collectors ;
11
-
12
16
import static software .amazon .cryptography .dbencryptionsdk .dynamodb .enhancedclient .DoNothingTag .CUSTOM_DDB_ENCRYPTION_DO_NOTHING_PREFIX ;
13
17
import static software .amazon .cryptography .dbencryptionsdk .dynamodb .enhancedclient .SignOnlyTag .CUSTOM_DDB_ENCRYPTION_SIGN_ONLY_PREFIX ;
14
18
@@ -27,12 +31,33 @@ public static DynamoDbEncryptionInterceptor CreateDynamoDbEncryptionInterceptor(
27
31
.build ();
28
32
}
29
33
34
+ private static Set <String > attributeNamesUsedInIndices (
35
+ final TableMetadata tableMetadata
36
+ ) {
37
+ Set <String > partitionAttributeNames = tableMetadata .indices ().stream ()
38
+ .map (IndexMetadata ::partitionKey )
39
+ .filter (Optional ::isPresent )
40
+ .map (Optional ::get )
41
+ .map (KeyAttributeMetadata ::name )
42
+ .collect (Collectors .toSet ());
43
+ Set <String > sortAttributeNames = tableMetadata .indices ().stream ()
44
+ .map (IndexMetadata ::sortKey )
45
+ .filter (Optional ::isPresent )
46
+ .map (Optional ::get )
47
+ .map (KeyAttributeMetadata ::name )
48
+ .collect (Collectors .toSet ());
49
+ Set <String > allIndexAttributes = new HashSet <>();
50
+ allIndexAttributes .addAll (partitionAttributeNames );
51
+ allIndexAttributes .addAll (sortAttributeNames );
52
+ return allIndexAttributes ;
53
+ }
54
+
30
55
private static DynamoDbTableEncryptionConfig getTableConfig (DynamoDbEnhancedTableEncryptionConfig configWithSchema ) {
31
56
Map <String , CryptoAction > actions = new HashMap <>();
32
57
33
58
Set <String > signOnlyAttributes = configWithSchema .schemaOnEncrypt ().tableMetadata ().customMetadataObject (CUSTOM_DDB_ENCRYPTION_SIGN_ONLY_PREFIX , Set .class ).orElseGet (HashSet ::new );
34
59
Set <String > doNothingAttributes = configWithSchema .schemaOnEncrypt ().tableMetadata ().customMetadataObject (CUSTOM_DDB_ENCRYPTION_DO_NOTHING_PREFIX , Set .class ).orElseGet (HashSet ::new );
35
- Set <String > keyAttributes = configWithSchema .schemaOnEncrypt ().tableMetadata (). keyAttributes (). stream (). map ( val -> val . name ()). collect ( Collectors . toSet ());
60
+ Set <String > keyAttributes = attributeNamesUsedInIndices ( configWithSchema .schemaOnEncrypt ().tableMetadata ());
36
61
37
62
if (!Collections .disjoint (keyAttributes , doNothingAttributes )) {
38
63
throw DynamoDbEncryptionException .builder ()
0 commit comments