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

GDB-5393 Refactor repository and server clients configuration #127

Merged
merged 6 commits into from
Feb 10, 2021

Conversation

teodossidossev
Copy link
Contributor

Provides configuration builder and unifies configuration creation.

@teodossidossev teodossidossev force-pushed the GDB-5393-refactor-server-client-configs branch 2 times, most recently from 38c4795 to 50f574f Compare January 25, 2021 13:57
* to all server requests
* @return {ServerClientConfig}
*/
static serverConfig(endpoint) {
Copy link
Contributor

@svilenvelikov svilenvelikov Jan 26, 2021

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

Copy link
Contributor

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

Copy link
Contributor Author

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.

* 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
Copy link
Contributor

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

@@ -62,6 +56,7 @@ class ClientConfig {
*/
setUsername(username) {
this.username = username;
this.useBasicAuthentication();
Copy link
Contributor

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.

Copy link
Contributor

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 */
Copy link
Contributor

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*/
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -1,5 +1,7 @@
/* eslint-disable max-len */
/* eslint "require-jsdoc": off*/
Copy link
Contributor

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

* to all server requests
* @return {RepositoryClientConfig}
*/
buildRepositoryClientConfig(endpoint) {
Copy link
Contributor

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

* @class
* @author Teodossi Dossev
*/
class ClientConfigBuilder {
Copy link
Contributor

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.

Copy link
Contributor

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?!

*/
setBasicAuthentication(basicAuth) {
enableBasicAuthentication(basicAuth) {
Copy link
Contributor

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?

if (this.basicAuth) {
const credentials = `${this.username}:${this.pass}`;
this.headers['Authorization'] = `Basic ${btoa(credentials)}`;
enableGdbTokenAuthentication(gdbTokenAuth) {
Copy link
Contributor

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);
Copy link
Contributor

@svilenvelikov svilenvelikov Feb 9, 2021

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() {
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

typo in conctrete

@@ -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())
Copy link
Contributor

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' +
Copy link
Contributor

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

svilenvelikov
svilenvelikov previously approved these changes Feb 9, 2021
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
@teodossidossev teodossidossev force-pushed the GDB-5393-refactor-server-client-configs branch from 6ee28ab to 9cdd7e0 Compare February 10, 2021 07:11
svilenvelikov
svilenvelikov previously approved these changes Feb 10, 2021
@sonarcloud
Copy link

sonarcloud bot commented Feb 10, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@teodossidossev teodossidossev merged commit ae13c41 into master Feb 10, 2021
@teodossidossev teodossidossev deleted the GDB-5393-refactor-server-client-configs branch February 10, 2021 08:03
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.

None yet

2 participants