|
16 | 16 |
|
17 | 17 | package com.mongodb.client.unified;
|
18 | 18 |
|
| 19 | +import com.mongodb.AutoEncryptionSettings; |
19 | 20 | import com.mongodb.ClientEncryptionSettings;
|
20 | 21 | import com.mongodb.ClientSessionOptions;
|
21 | 22 | import com.mongodb.ConnectionString;
|
|
111 | 112 | public final class Entities {
|
112 | 113 | private static final Set<String> SUPPORTED_CLIENT_ENTITY_OPTIONS = new HashSet<>(
|
113 | 114 | asList(
|
114 |
| - "id", "uriOptions", "serverApi", "useMultipleMongoses", "storeEventsAsEntities", |
| 115 | + "id", "autoEncryptOpts", "uriOptions", "serverApi", "useMultipleMongoses", "storeEventsAsEntities", |
115 | 116 | "observeEvents", "observeLogMessages", "observeSensitiveCommands", "ignoreCommandMonitoringEvents"));
|
116 | 117 | private final Set<String> entityNames = new HashSet<>();
|
117 | 118 | private final Map<String, ExecutorService> threads = new HashMap<>();
|
@@ -604,6 +605,59 @@ private void initClient(final BsonDocument entity, final String id,
|
604 | 605 | }
|
605 | 606 | clientSettingsBuilder.serverApi(serverApiBuilder.build());
|
606 | 607 | }
|
| 608 | + if (entity.containsKey("autoEncryptOpts")) { |
| 609 | + AutoEncryptionSettings.Builder builder = AutoEncryptionSettings.builder(); |
| 610 | + for (Map.Entry<String, BsonValue> entry : entity.getDocument("autoEncryptOpts").entrySet()) { |
| 611 | + switch (entry.getKey()) { |
| 612 | + case "bypassAutoEncryption": |
| 613 | + builder.bypassAutoEncryption(entry.getValue().asBoolean().getValue()); |
| 614 | + break; |
| 615 | + case "bypassQueryAnalysis": |
| 616 | + builder.bypassQueryAnalysis(entry.getValue().asBoolean().getValue()); |
| 617 | + break; |
| 618 | + case "schemaMap": |
| 619 | + Map<String, BsonDocument> schemaMap = new HashMap<>(); |
| 620 | + for (Map.Entry<String, BsonValue> entries : entry.getValue().asDocument().entrySet()) { |
| 621 | + schemaMap.put(entries.getKey(), entries.getValue().asDocument()); |
| 622 | + } |
| 623 | + builder.schemaMap(schemaMap); |
| 624 | + break; |
| 625 | + case "encryptedFieldsMap": |
| 626 | + Map<String, BsonDocument> encryptedFieldsMap = new HashMap<>(); |
| 627 | + for (Map.Entry<String, BsonValue> entries : entry.getValue().asDocument().entrySet()) { |
| 628 | + encryptedFieldsMap.put(entries.getKey(), entries.getValue().asDocument()); |
| 629 | + } |
| 630 | + builder.encryptedFieldsMap(encryptedFieldsMap); |
| 631 | + break; |
| 632 | + case "extraOptions": |
| 633 | + Map<String, Object> extraOptions = new HashMap<>(); |
| 634 | + for (Map.Entry<String, BsonValue> extraOptionsEntry : entry.getValue().asDocument().entrySet()) { |
| 635 | + switch (extraOptionsEntry.getKey()) { |
| 636 | + case "mongocryptdBypassSpawn": |
| 637 | + extraOptions.put(extraOptionsEntry.getKey(), extraOptionsEntry.getValue().asBoolean().getValue()); |
| 638 | + break; |
| 639 | + default: |
| 640 | + throw new UnsupportedOperationException("Unsupported extra encryption option: " + extraOptionsEntry.getKey()); |
| 641 | + } |
| 642 | + } |
| 643 | + builder.extraOptions(extraOptions); |
| 644 | + break; |
| 645 | + case "keyVaultNamespace": |
| 646 | + builder.keyVaultNamespace(entry.getValue().asString().getValue()); |
| 647 | + break; |
| 648 | + case "kmsProviders": |
| 649 | + builder.kmsProviders(createKmsProvidersMap(entry.getValue().asDocument())); |
| 650 | + break; |
| 651 | + case "keyExpirationMS": |
| 652 | + builder.keyExpiration(entry.getValue().asNumber().longValue(), TimeUnit.MILLISECONDS); |
| 653 | + break; |
| 654 | + default: |
| 655 | + throw new UnsupportedOperationException("Unsupported client encryption option: " + entry.getKey()); |
| 656 | + } |
| 657 | + } |
| 658 | + clientSettingsBuilder.autoEncryptionSettings(builder.build()); |
| 659 | + } |
| 660 | + |
607 | 661 | MongoClientSettings clientSettings = clientSettingsBuilder.build();
|
608 | 662 |
|
609 | 663 | if (entity.containsKey("observeLogMessages")) {
|
|
0 commit comments