|
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;
|
|
87 | 88 | public final class Entities {
|
88 | 89 | private static final Set<String> SUPPORTED_CLIENT_ENTITY_OPTIONS = new HashSet<>(
|
89 | 90 | asList(
|
90 |
| - "id", "uriOptions", "serverApi", "useMultipleMongoses", "observeEvents", |
91 |
| - "observeLogMessages", "observeSensitiveCommands", "ignoreCommandMonitoringEvents")); |
| 91 | + "id", "autoEncryptOpts", "uriOptions", "serverApi", "useMultipleMongoses", "storeEventsAsEntities", |
| 92 | + "observeEvents", "observeLogMessages", "observeSensitiveCommands", "ignoreCommandMonitoringEvents")); |
92 | 93 | private final Set<String> entityNames = new HashSet<>();
|
93 | 94 | private final Map<String, ExecutorService> threads = new HashMap<>();
|
94 | 95 | private final Map<String, ArrayList<Future<?>>> tasks = new HashMap<>();
|
@@ -499,6 +500,59 @@ private void initClient(final BsonDocument entity, final String id,
|
499 | 500 | }
|
500 | 501 | clientSettingsBuilder.serverApi(serverApiBuilder.build());
|
501 | 502 | }
|
| 503 | + if (entity.containsKey("autoEncryptOpts")) { |
| 504 | + AutoEncryptionSettings.Builder builder = AutoEncryptionSettings.builder(); |
| 505 | + for (Map.Entry<String, BsonValue> entry : entity.getDocument("autoEncryptOpts").entrySet()) { |
| 506 | + switch (entry.getKey()) { |
| 507 | + case "bypassAutoEncryption": |
| 508 | + builder.bypassAutoEncryption(entry.getValue().asBoolean().getValue()); |
| 509 | + break; |
| 510 | + case "bypassQueryAnalysis": |
| 511 | + builder.bypassQueryAnalysis(entry.getValue().asBoolean().getValue()); |
| 512 | + break; |
| 513 | + case "schemaMap": |
| 514 | + Map<String, BsonDocument> schemaMap = new HashMap<>(); |
| 515 | + for (Map.Entry<String, BsonValue> entries : entry.getValue().asDocument().entrySet()) { |
| 516 | + schemaMap.put(entries.getKey(), entries.getValue().asDocument()); |
| 517 | + } |
| 518 | + builder.schemaMap(schemaMap); |
| 519 | + break; |
| 520 | + case "encryptedFieldsMap": |
| 521 | + Map<String, BsonDocument> encryptedFieldsMap = new HashMap<>(); |
| 522 | + for (Map.Entry<String, BsonValue> entries : entry.getValue().asDocument().entrySet()) { |
| 523 | + encryptedFieldsMap.put(entries.getKey(), entries.getValue().asDocument()); |
| 524 | + } |
| 525 | + builder.encryptedFieldsMap(encryptedFieldsMap); |
| 526 | + break; |
| 527 | + case "extraOptions": |
| 528 | + Map<String, Object> extraOptions = new HashMap<>(); |
| 529 | + for (Map.Entry<String, BsonValue> extraOptionsEntry : entry.getValue().asDocument().entrySet()) { |
| 530 | + switch (extraOptionsEntry.getKey()) { |
| 531 | + case "mongocryptdBypassSpawn": |
| 532 | + extraOptions.put(extraOptionsEntry.getKey(), extraOptionsEntry.getValue().asBoolean().getValue()); |
| 533 | + break; |
| 534 | + default: |
| 535 | + throw new UnsupportedOperationException("Unsupported extra encryption option: " + extraOptionsEntry.getKey()); |
| 536 | + } |
| 537 | + } |
| 538 | + builder.extraOptions(extraOptions); |
| 539 | + break; |
| 540 | + case "keyVaultNamespace": |
| 541 | + builder.keyVaultNamespace(entry.getValue().asString().getValue()); |
| 542 | + break; |
| 543 | + case "kmsProviders": |
| 544 | + builder.kmsProviders(createKmsProvidersMap(entry.getValue().asDocument())); |
| 545 | + break; |
| 546 | + case "keyExpirationMS": |
| 547 | + builder.keyExpiration(entry.getValue().asNumber().longValue(), TimeUnit.MILLISECONDS); |
| 548 | + break; |
| 549 | + default: |
| 550 | + throw new UnsupportedOperationException("Unsupported client encryption option: " + entry.getKey()); |
| 551 | + } |
| 552 | + } |
| 553 | + clientSettingsBuilder.autoEncryptionSettings(builder.build()); |
| 554 | + } |
| 555 | + |
502 | 556 | MongoClientSettings clientSettings = clientSettingsBuilder.build();
|
503 | 557 |
|
504 | 558 | if (entity.containsKey("observeLogMessages")) {
|
|
0 commit comments