-
Notifications
You must be signed in to change notification settings - Fork 11
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
GDB-5393 Refactor repository and server clients configuration #127
GDB-5393 Refactor repository and server clients configuration #127
Conversation
38c4795
to
50f574f
Compare
src/http/client-config-builder.js
Outdated
* to all server requests | ||
* @return {ServerClientConfig} | ||
*/ | ||
static serverConfig(endpoint) { |
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.
Remove the static
in order to be consistent with other methods. And same for the repositoryConfig
method
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.
Or maybe make the other two private
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.
Both creator methods are static to be consistent with the other builders in the driver.
src/http/client-config.js
Outdated
* server is secured and username and passwords are provided. | ||
* @param {boolean} [useBasicAuth] if use Basic Auth when authenticating | ||
* Client configuration constructor. | ||
* Initializes [headers]{@link ClientConfig#headers} and |
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.
Well, this constructor doesn't do what you've described
src/http/client-config.js
Outdated
@@ -62,6 +56,7 @@ class ClientConfig { | |||
*/ | |||
setUsername(username) { | |||
this.username = username; | |||
this.useBasicAuthentication(); |
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.
Why? It's is quite unusual that you set this here in the username setter, and also in the password setter. Not to mention that if I do config.setUsername('me')
, it'll populate the Authorization
header with wrong data.
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.
Also setBasicAuthentication
does the same and I think it's not correct to have a setter which does something else underneath. IMO this basic auth configration should be made explicit and should not make the user wonder how to configure the client. Think if it wouldn't be better to remove the user/pass setters in favor of useBasicAuthentication
which should also require the user/pass as arguments and does all this explicit.
const {RepositoryClientConfig} = require('graphdb').repository; | ||
const {RDFMimeType} = require('graphdb').http; | ||
const {ServerClientConfig} = require('graphdb').server; | ||
/* eslint-disable max-len */ |
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.
Can't you just format the line instead?!
@@ -1,13 +1,16 @@ | |||
/* eslint "require-jsdoc": off*/ |
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.
Better just exclude the rule for the tests. See https://eslint.org/docs/user-guide/configuring#disabling-rules-only-for-a-group-of-files
@@ -1,5 +1,7 @@ | |||
/* eslint-disable max-len */ | |||
/* eslint "require-jsdoc": off*/ |
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.
remove these: format the long lines and disable the jsdoc rule for tests
src/http/client-config-builder.js
Outdated
* to all server requests | ||
* @return {RepositoryClientConfig} | ||
*/ | ||
buildRepositoryClientConfig(endpoint) { |
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.
private
maybe? And the same for the buildServerClientConfig
src/http/client-config-builder.js
Outdated
* @class | ||
* @author Teodossi Dossev | ||
*/ | ||
class ClientConfigBuilder { |
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.
I still can't get the purpose of this so called builder, which seems more like a factory to me. But lets assume we decide to leave it. In such a case shouldn't we need to hide the RepositoryClientConfig and ServerClientConfig constructors and force the client to get their instances only through the factory?! Otherwise would be more confusing and unclear to me as a client how should I get a client instance and what's the problem with the direct instantiation.
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.
And another question. As long as the server and repository configs are situated in their respective packages, why this is placed inside the http
package?!
src/http/client-config.js
Outdated
*/ | ||
setBasicAuthentication(basicAuth) { | ||
enableBasicAuthentication(basicAuth) { |
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.
This method is quite confusing. It sais enableBasicAuthentication
and yet it seems that it might not do it. Can you please clarify it?
src/http/client-config.js
Outdated
if (this.basicAuth) { | ||
const credentials = `${this.username}:${this.pass}`; | ||
this.headers['Authorization'] = `Basic ${btoa(credentials)}`; | ||
enableGdbTokenAuthentication(gdbTokenAuth) { |
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.
Same note as for enableBasicAuthentication
.then((user) => { | ||
this.setLoggedUser(user); |
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.
You execute a login with logged user and after that you set logged user... it's strange. Is the user logged in before login execution and what happens with it after the login?
* Logged user getter. | ||
* @return {User} user | ||
*/ | ||
getLoggedUser() { |
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.
Why not just getUser
and setUser
? Otherwise it's confusing.
* @return {AuthenticationService} | ||
* Authentication type getter | ||
* @param {ClientConfig} clientConfig concrete client configuration | ||
* @return {BasicAuthentication|GdbTokenAuthentication} conctrete |
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.
typo in conctrete
src/service/transaction-service.js
Outdated
@@ -79,7 +79,8 @@ class TransactionService extends Service { | |||
*/ | |||
getTransactionalClientConfig(locationUrl) { | |||
const config = this.repositoryClientConfig; | |||
return ClientConfigBuilder.repositoryConfig(config.getEndpoint()) | |||
return new ClientConfigBuilder() | |||
.repositoryConfig(config.getEndpoint()) |
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.
Here's an example of why the ClientConfigBuilder
is confusing. You get an instance of the RepositoryClientConfig
builder by just providing the only required parameter and then continue with its initialization. It's seems just redundant to me.
@@ -217,7 +215,8 @@ describe('RDFRepositoryClient - query', () => { | |||
.setOffset(0) | |||
.setTimeout(5); | |||
|
|||
const expectedData = 'query=select%20*%20where%20%7B%3Fs%20%3Fp%20%3Fo%7D&queryLn=sparql&infer=true&distinct=true&limit=100&offset=0&timeout=5'; | |||
const expectedData = 'query=select%20*%20where%20%7B%3Fs%20%3Fp%20%3Fo%7D' + |
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.
pff this formatting in the tests was quite unneeded IMO
Provides configuration builder and unifies configuration creation.
Provides authentication factory. Authentication service refactor to decouple user state Minor sonar bug fixes Test refactored according code changes New eslint rules for test files
update README.md
6ee28ab
to
9cdd7e0
Compare
9cdd7e0
to
3241953
Compare
Kudos, SonarCloud Quality Gate passed! |
Provides configuration builder and unifies configuration creation.