Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Username required in config.json while is optional while creating a Mongo cluster #159

Closed

Conversation

TheCoderAdi
Copy link

@TheCoderAdi TheCoderAdi commented Mar 17, 2025

Description

This pull request includes an important change to the drivers/mongodb/internal/config.go file, specifically to the func (c *Config) URI() string { function. The change ensures that the MongoDB URI only includes the username and password if they are set. This helps to avoid potential security issues and simplifies the connection string when authentication is not required.

Improvements to MongoDB URI construction:

  • drivers/mongodb/internal/config.go: Modified the URI method to conditionally include the username and password in the MongoDB connection string only if they are set. This prevents the inclusion of empty credentials in the URI.

Fixes #107

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  1. Use the following config.json without username/password:

    {
       "hosts": ["localhost:27017", "localhost:27018", "localhost:27019"],
       "replica_set": "rs0",
       "read_preference": "secondaryPreferred",
       "srv": false,
       "server_ram": 16,
       "database": "reddit",
       "max_threads": 50,
       "default_mode": "cdc",
       "backoff_retry_count": 2
    }
  2. Attempt to generate the catalog file using the command:
    https://olake.io/docs/getting-started/mongodb#step-2-generate-a-catalog-file
    Mentioned here

  3. Previously, it would throw an error requiring a username. After this fix, the connection should work as expected without authentication.

@TheCoderAdi
Copy link
Author

TheCoderAdi commented Mar 17, 2025

Hello @hash-data ,

Could you please review this pull request at your earliest convenience? Your feedback would be greatly appreciated.

Thank you.

@@ -46,9 +46,18 @@ func (c *Config) URI() string {
options = fmt.Sprintf("%s&replicaSet=%s&readPreference=%s", options, c.ReplicaSet, c.ReadPreference)
}

// Only include username and password if they are set
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheCoderAdi please try to use utils.Ternary(
So we can do it in even lesser code. Also do not fmt.sprintf only once and just pass username & password string into it.

Also need to check one more edge case, can Mongo have username but no password?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, MongoDB can have a username without a password.

I will do the changes

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @shubham19may ,

I have made the changes, please review it.

@shubham19may
Copy link
Contributor

@TheCoderAdi the commits are not verified.

Please follow the doc properly : https://olake.io/docs/community/contributing

@TheCoderAdi
Copy link
Author

Hello @shubham19may ,

I am commit is now verified,
image

@shubham19may
Copy link
Contributor

Hello @shubham19may ,

I am commit is now verified, image

@TheCoderAdi the older commits are not verified. Please rebase an squash them into 1 commit.

@TheCoderAdi
Copy link
Author

Hello @shubham19may ,
I am commit is now verified, image

@TheCoderAdi the older commits are not verified. Please rebase an squash them into 1 commit.

I have verified my commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Username required in config.json while is optional while creating a Mongo cluster
2 participants