-
Notifications
You must be signed in to change notification settings - Fork 37
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
Conversation
There was a problem hiding this 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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)))) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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)) |
There was a problem hiding this comment.
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)))) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGMT!
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!