Skip to content

Commit

Permalink
Extract method for duplicated logic checking for whether mongocryptd …
Browse files Browse the repository at this point in the history
…is disabled

JAVA-4739
  • Loading branch information
jyemin committed Sep 29, 2022
1 parent 7d8d94d commit 7ea1f20
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ private static BsonDocument toBsonDocument(final Map<String, Object> optionsMap)
return new BsonDocumentWrapper<>(new Document(optionsMap), new DocumentCodec());
}

public static boolean isMongocryptdSpawningDisabled(@Nullable final String cryptSharedLibVersion,
final AutoEncryptionSettings settings) {
boolean cryptSharedLibIsAvailable = cryptSharedLibVersion != null && cryptSharedLibVersion.isEmpty();
boolean cryptSharedLibRequired = (boolean) settings.getExtraOptions().getOrDefault("cryptSharedLibRequired", false);
return settings.isBypassAutoEncryption() || settings.isBypassQueryAnalysis() || cryptSharedLibRequired || cryptSharedLibIsAvailable;
}

@SuppressWarnings("unchecked")
public static List<String> createMongocryptdSpawnArgs(final Map<String, Object> options) {
List<String> spawnArgs = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import static com.mongodb.assertions.Assertions.assertNotNull;
import static com.mongodb.internal.capi.MongoCryptHelper.createMongocryptdClientSettings;
import static com.mongodb.internal.capi.MongoCryptHelper.createProcessBuilder;
import static com.mongodb.internal.capi.MongoCryptHelper.isMongocryptdSpawningDisabled;
import static com.mongodb.internal.capi.MongoCryptHelper.startProcess;

@SuppressWarnings("UseOfProcessBuilder")
Expand Down Expand Up @@ -62,18 +63,12 @@ class CommandMarker implements Closeable {
CommandMarker(
final MongoCrypt mongoCrypt,
final AutoEncryptionSettings settings) {
Map<String, Object> extraOptions = settings.getExtraOptions();
String cryptSharedLibVersionString = mongoCrypt.getCryptSharedLibVersionString();

boolean bypassAutoEncryption = settings.isBypassAutoEncryption();
boolean isBypassQueryAnalysis = settings.isBypassQueryAnalysis();
boolean cryptSharedIsAvailable = cryptSharedLibVersionString != null && cryptSharedLibVersionString.isEmpty();
boolean cryptSharedLibRequired = (boolean) extraOptions.getOrDefault("cryptSharedLibRequired", false);

if (bypassAutoEncryption || isBypassQueryAnalysis || cryptSharedLibRequired || cryptSharedIsAvailable) {
if (isMongocryptdSpawningDisabled(mongoCrypt.getCryptSharedLibVersionString(), settings)) {
processBuilder = null;
client = null;
} else {
Map<String, Object> extraOptions = settings.getExtraOptions();
boolean mongocryptdBypassSpawn = (boolean) extraOptions.getOrDefault("mongocryptdBypassSpawn", false);
if (!mongocryptdBypassSpawn) {
processBuilder = createProcessBuilder(extraOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import static com.mongodb.assertions.Assertions.assertNotNull;
import static com.mongodb.internal.capi.MongoCryptHelper.createMongocryptdClientSettings;
import static com.mongodb.internal.capi.MongoCryptHelper.createProcessBuilder;
import static com.mongodb.internal.capi.MongoCryptHelper.isMongocryptdSpawningDisabled;
import static com.mongodb.internal.capi.MongoCryptHelper.startProcess;

@SuppressWarnings("UseOfProcessBuilder")
Expand Down Expand Up @@ -62,18 +63,12 @@ class CommandMarker implements Closeable {
CommandMarker(
final MongoCrypt mongoCrypt,
final AutoEncryptionSettings settings) {
Map<String, Object> extraOptions = settings.getExtraOptions();
String cryptSharedLibVersionString = mongoCrypt.getCryptSharedLibVersionString();

boolean bypassAutoEncryption = settings.isBypassAutoEncryption();
boolean isBypassQueryAnalysis = settings.isBypassQueryAnalysis();
boolean cryptSharedIsAvailable = cryptSharedLibVersionString != null && cryptSharedLibVersionString.isEmpty();
boolean cryptSharedLibRequired = (boolean) extraOptions.getOrDefault("cryptSharedLibRequired", false);

if (bypassAutoEncryption || isBypassQueryAnalysis || cryptSharedLibRequired || cryptSharedIsAvailable) {
if (isMongocryptdSpawningDisabled(mongoCrypt.getCryptSharedLibVersionString(), settings)) {
processBuilder = null;
client = null;
} else {
Map<String, Object> extraOptions = settings.getExtraOptions();
boolean mongocryptdBypassSpawn = (boolean) extraOptions.getOrDefault("mongocryptdBypassSpawn", false);
if (!mongocryptdBypassSpawn) {
processBuilder = createProcessBuilder(extraOptions);
Expand Down

0 comments on commit 7ea1f20

Please sign in to comment.