-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Source MongoDB Internal POC: Discover Operation (#28932)
* Implement discover operation * Formatting
- Loading branch information
1 parent
e66ce47
commit 9372bc5
Showing
4 changed files
with
325 additions
and
9 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...c/src/main/java/io/airbyte/integrations/source/mongodb/internal/MongoConnectionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.source.mongodb.internal; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.mongodb.ConnectionString; | ||
import com.mongodb.MongoClientSettings; | ||
import com.mongodb.MongoCredential; | ||
import com.mongodb.ReadPreference; | ||
import com.mongodb.client.MongoClient; | ||
import com.mongodb.client.MongoClients; | ||
|
||
/** | ||
* Helper utility for building a {@link MongoClient}. | ||
*/ | ||
public class MongoConnectionUtils { | ||
|
||
/** | ||
* Creates a new {@link MongoClient} from the source configuration. | ||
* | ||
* @param config The source's configuration. | ||
* @return The configured {@link MongoClient}. | ||
*/ | ||
public static MongoClient createMongoClient(final JsonNode config) { | ||
final String authSource = config.get("auth_source").asText(); | ||
final String connectionString = config.get("connection_string").asText(); | ||
final String replicaSet = config.get("replica_set").asText(); | ||
|
||
final ConnectionString mongoConnectionString = new ConnectionString(connectionString + "?replicaSet=" + | ||
replicaSet + "&retryWrites=false&provider=airbyte&tls=true"); | ||
|
||
final MongoClientSettings.Builder mongoClientSettingsBuilder = MongoClientSettings.builder() | ||
.applyConnectionString(mongoConnectionString) | ||
.readPreference(ReadPreference.secondaryPreferred()); | ||
|
||
if (config.has("user") && config.has("password")) { | ||
final String user = config.get("user").asText(); | ||
final String password = config.get("password").asText(); | ||
mongoClientSettingsBuilder.credential(MongoCredential.createCredential(user, authSource, password.toCharArray())); | ||
} | ||
|
||
return MongoClients.create(mongoClientSettingsBuilder.build()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.