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

Allow username and password to be null in DatabaseConfig #201

Merged
merged 2 commits into from
May 20, 2021

Conversation

brfrn169
Copy link
Collaborator

Some databases might not need a username and a password, but they are currently required in DatabaseConfig. This PR will fix it. Please take a look at this!

@brfrn169 brfrn169 requested a review from feeblefakie May 17, 2021 14:32
@brfrn169 brfrn169 self-assigned this May 17, 2021
Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

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

Thank you!
Sorry for the late review.
I left some questions.

@@ -53,7 +53,7 @@ public Cosmos(DatabaseConfig config) {
this.client =
new CosmosClientBuilder()
.endpoint(config.getContactPoints().get(0))
.key(config.getPassword())
.key(config.getPassword().orElse(null))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any way it can work well without a password?
If there is no way, I'm wondering if it should check it here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The key method throws NullPointerException with an error message ("'key' cannot be null.") when the password is EMPTY. I thought it was okay because we basically delegate the configuration parameter check to the db client side (in this case CosmosClientBuilder). An invalid password (including null) will cause something error on CosmosClient side.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you! Ok, if it is delegating the check to the builder, then I think it is fine. (I want the builder to throw IllegalArgumentException though :( )

@@ -54,7 +54,8 @@ public Dynamo(DatabaseConfig config) {
DynamoDbClient.builder()
.credentialsProvider(
StaticCredentialsProvider.create(
AwsBasicCredentials.create(config.getUsername(), config.getPassword())))
AwsBasicCredentials.create(
config.getUsername().orElse(null), config.getPassword().orElse(null))))
Copy link
Contributor

Choose a reason for hiding this comment

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

If both are null, does it assume that the code uses credentials stored in a file (like ~/aws/config) implicitly?
I'm just wondering if there is a case where it works without a username and a password.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If any of them is null, the DynamoDbClient builder will throw NullPointerException with a message. I thought it was okay as the same reason above. BTW, the current implementation doesn't check username and password, so if username or password is empty, we will also face NullPointerException.

Copy link
Collaborator Author

@brfrn169 brfrn169 left a comment

Choose a reason for hiding this comment

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

@feeblefakie Thank you for reviewing this!

Left some comments for your review. Please check them!

@@ -53,7 +53,7 @@ public Cosmos(DatabaseConfig config) {
this.client =
new CosmosClientBuilder()
.endpoint(config.getContactPoints().get(0))
.key(config.getPassword())
.key(config.getPassword().orElse(null))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The key method throws NullPointerException with an error message ("'key' cannot be null.") when the password is EMPTY. I thought it was okay because we basically delegate the configuration parameter check to the db client side (in this case CosmosClientBuilder). An invalid password (including null) will cause something error on CosmosClient side.

@@ -54,7 +54,8 @@ public Dynamo(DatabaseConfig config) {
DynamoDbClient.builder()
.credentialsProvider(
StaticCredentialsProvider.create(
AwsBasicCredentials.create(config.getUsername(), config.getPassword())))
AwsBasicCredentials.create(
config.getUsername().orElse(null), config.getPassword().orElse(null))))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If any of them is null, the DynamoDbClient builder will throw NullPointerException with a message. I thought it was okay as the same reason above. BTW, the current implementation doesn't check username and password, so if username or password is empty, we will also face NullPointerException.

Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

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

LGMT!

@feeblefakie feeblefakie merged commit 2ff0ff3 into master May 20, 2021
@feeblefakie feeblefakie deleted the allow-username-password-to-be-null branch May 20, 2021 03:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants