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

14.09.2023 issue-52: insert chat id, token, token alias into database if token is valid #65

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

iColdLight
Copy link

@iColdLight iColdLight commented Sep 14, 2023

Added dependency for json web token in the pom.xml file
Added validateToken method in the TokenController class
Modified registerToken method to include validation of token in the TokenController class


PR-Codex overview

Focus of the PR:

This PR focuses on adding token validation and insertion functionality to the codebase.

Detailed summary:

  • Added TokenValidation class in io.blamer.hub.pg package.
  • TokenValidation implements the Tokens interface.
  • Added validateAndInsertToken method in TokenValidation to validate and insert tokens.
  • Added validateToken method in TokenValidation to validate tokens.
  • Added checkIfTokenExists method in TokenValidation to check if a token already exists in the database.
  • Added SQL query to check if a token exists in the checkIfTokenExists method.
  • Added TokenAlreadyExists exception in io.blamer.hub.exceptions package.
  • Added TokenInsertion class in io.blamer.hub.pg package to handle token insertion.
  • TokenInsertion implements the Tokens interface.
  • Added add method in TokenInsertion to add tokens.
  • Modified TokenController class in io.blamer.hub.controller package.
  • Modified the TokenController constructor to accept a Tokens object with @Qualifier("tokenValidation").
  • Modified the registerToken method in TokenController to use the tokens object to add tokens.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@zoeself
Copy link

zoeself commented Sep 14, 2023

@iColdLight thank you for your Pull Request. I'll assign someone to review it soon.

If this PR solves a todo from the code, please don't forget to remove it.

@zoeself
Copy link

zoeself commented Sep 14, 2023

@h1alexbel please review this Pull Request. Deadline (when it should be merged or closed) is 2023-09-17T19:18:59.313614.

You should check if the requirements have been implemented (partially or in full), if there are unit tests covering the changes and if the CI build passes. Feel free to reject the PR or ask for changes if it's too big or not clear enough.

Estimation here is 30 minutes, that's how much you will be paid. You will be paid even if this PR gets rejected.

Copy link
Member

@h1alexbel h1alexbel left a comment

Choose a reason for hiding this comment

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

@iColdLight the ticket was to insert chat id, token, token alias and other stuff (can be just a placeholder for now) if the provided token is valid.
And this token is not JWT, it's a just simple GitHub token, simple string

WDYT?

pom.xml Outdated
@@ -159,6 +160,11 @@ SOFTWARE.
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Copy link
Member

Choose a reason for hiding this comment

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

@iColdLight sort your dependencies, compile/provided scope first,
and only then test one

Mono<Void> registerToken(@RequestBody final RequestToken request)
throws Exception {
return this.tokens.add(new TokenToAdd(request).value());
Mono<Void> registerToken(@RequestBody final RequestToken request) throws Exception {
Copy link
Member

Choose a reason for hiding this comment

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

@iColdLight I think, method should be public

throws Exception {
return this.tokens.add(new TokenToAdd(request).value());
Mono<Void> registerToken(@RequestBody final RequestToken request) throws Exception {
String token = request.getValue();
Copy link
Member

Choose a reason for hiding this comment

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

@iColdLight make all your variables final

Mono<Void> registerToken(@RequestBody final RequestToken request) throws Exception {
String token = request.getValue();
String secretKey = "your-secret-key";

Copy link
Member

Choose a reason for hiding this comment

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

@iColdLight empty lines mean code smell, read this

@zoeself
Copy link

zoeself commented Sep 16, 2023

@h1alexbel Don't forget to close this ticket before the deadline (2023-09-17T19:18:59). You are past the first half of the allowed period.

@iColdLight
Copy link
Author

Does it mean that I need to work on creating JWT TokenProvider, JWT TokenFIlter, JWT User, etc.?

@h1alexbel
Copy link
Member

@iColdLight we don't need JWTs. We are dealing with simple text token from GitHub

And this token is not JWT, it's a just simple GitHub token, simple string

@zoeself
Copy link

zoeself commented Sep 17, 2023

@h1alexbel Looks like you've missed the task deadline (2023-09-17T19:18:59). You are now resigned from this task.

Please stop working on it, you will not be paid. I will assign it to someone else soon.

@zoeself
Copy link

zoeself commented Sep 17, 2023

@h1alexbel I couldn't find any assignee for this task. This is either because there are no contributors with role REV available or because the project does not have enough funds.

Please, make sure there is at least one available contributor with the required role and the project can afford to pay them.

@iColdLight
Copy link
Author

Hi!
I made new changes. I wonder, if you can see them.
And sorry for 3 commits in a row...
made slight changes in the last two.

@l3r8yJ
Copy link
Contributor

l3r8yJ commented Sep 18, 2023

@iColdLight it's okay with commits, but you can read this

@l3r8yJ
Copy link
Contributor

l3r8yJ commented Sep 18, 2023

@h1alexbel reminder

Copy link
Member

@h1alexbel h1alexbel left a comment

Choose a reason for hiding this comment

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

@iColdLight check my comments, please

* Tokens.
*/
private final Tokens tokens;
/**
Copy link
Member

Choose a reason for hiding this comment

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

@iColdLight don't change the layout, please

@@ -0,0 +1,7 @@
package io.blamer.hub.exceptions;

public class TokenAlreadyExists extends RuntimeException{
Copy link
Member

Choose a reason for hiding this comment

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

@iColdLight class can be final

import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
@Component
public class TokenValidated implements Tokens {
Copy link
Member

Choose a reason for hiding this comment

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

@iColdLight It's better to name this class just like Validated, since your interface already saying that this is Tokens

Copy link
Author

Choose a reason for hiding this comment

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

I didn't name my class Validated because we already have a class with that name


@Override
public Mono<Void> add(final Token token) {
return validateToken(token)
Copy link
Member

Choose a reason for hiding this comment

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

@iColdLight
This logic can be decorated, presented as at least 2 classes: first where you just insert token, and the second one where you check token validity and integrity, and then insert into database (reuse first object)
What do you think?

Added TokenInsertion class
Reworked TokenValidation class
Made TokenAlreadyExists final
@l3r8yJ
Copy link
Contributor

l3r8yJ commented Sep 24, 2023

/codex Could there be a problem here in terms of non-blocking interaction?

@pr-codex
Copy link

pr-codex bot commented Sep 24, 2023

Could there be a problem here in terms of non-blocking interaction?

@l3r8yJ Yes, there could be a problem with non-blocking interaction in the code. The TokenValidation class implements the Tokens interface and overrides the add method. Inside the add method, there are multiple database interactions (validateToken, checkIfTokenExists, and this.tokenInsertion.add) that return Mono objects, indicating asynchronous operations.

However, the code does not utilize reactive operators like flatMap, map, or zip to chain these operations together and ensure non-blocking execution. Instead, it directly calls these methods synchronously, which may lead to blocking behavior and potential performance issues.

To ensure non-blocking interaction, the code should use reactive operators to compose the asynchronous operations and handle the results asynchronously.

@l3r8yJ
Copy link
Contributor

l3r8yJ commented Sep 24, 2023

@iColdLight take note of this comment

Could there be a problem here in terms of non-blocking interaction?

@l3r8yJ Yes, there could be a problem with non-blocking interaction in the code. The TokenValidation class implements the Tokens interface and overrides the add method. Inside the add method, there are multiple database interactions (validateToken, checkIfTokenExists, and this.tokenInsertion.add) that return Mono objects, indicating asynchronous operations.

However, the code does not utilize reactive operators like flatMap, map, or zip to chain these operations together and ensure non-blocking execution. Instead, it directly calls these methods synchronously, which may lead to blocking behavior and potential performance issues.

To ensure non-blocking interaction, the code should use reactive operators to compose the asynchronous operations and handle the results asynchronously.

it's an AI response, could be wrong

Reworked validateAndInsertToken method in TokenValidation class
@iColdLight
Copy link
Author

I made a change to my TokenValidation class to ensure non-blocking interaction. May you take a look?

Copy link
Member

@h1alexbel h1alexbel left a comment

Choose a reason for hiding this comment

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

@iColdLight core logic is fine, now is needed to pass the merge pipeline

@h1alexbel
Copy link
Member

@l3r8yJ take a look, please

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.

4 participants