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

refactor(gitlab): move all GitLab requests to dedicated client (#685) #685

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mdonadoni
Copy link
Member

Closes #676

Depends on #684

mdonadoni added a commit to mdonadoni/reana-server that referenced this pull request Apr 9, 2024
Copy link

codecov bot commented Apr 9, 2024

Codecov Report

Attention: Patch coverage is 69.93464% with 46 lines in your changes are missing coverage. Please review.

Project coverage is 60.68%. Comparing base (4d23c62) to head (664f683).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #685      +/-   ##
==========================================
+ Coverage   60.06%   60.68%   +0.61%     
==========================================
  Files          32       33       +1     
  Lines        3308     3416     +108     
==========================================
+ Hits         1987     2073      +86     
- Misses       1321     1343      +22     
Files Coverage Δ
reana_server/rest/workflows.py 53.49% <50.00%> (-0.05%) ⬇️
reana_server/utils.py 59.40% <44.44%> (+0.87%) ⬆️
reana_server/gitlab_client.py 85.85% <85.85%> (ø)
reana_server/rest/gitlab.py 42.45% <36.66%> (-5.51%) ⬇️

@mdonadoni mdonadoni changed the title refactor gitlab client refactor(gitlab): move all GitLab requests to dedicated client (#685) Apr 9, 2024
@mdonadoni
Copy link
Member Author

Tested locally by copying valid token from DEV and by accessing the cluster through my CERN hostname.
Tested also on QA.

from reana_server.config import REANA_GITLAB_HOST


class GitLabException(Exception):
Copy link
Member

Choose a reason for hiding this comment

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

Cosmetics: since GitLabClient is our own, perhaps we can name all exceptions starting with this prefix, to better associate them together and make sure that the exceptions are not "generic" or coming from some other library:

  • GitLabClientException
  • GitLabClientRequestError
  • GitLabClientInvalidToken
  • ...

super().__init__(message)


class GitLabClient:
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, is there some existing GitLab client library which we could perhaps adopt, such as python-gitlab? We don't need much, so we can go with our own. Just wondering for future maintainability purposes, possible versioning when GitLab upgrades, etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess both approaches are fine. python-gitlab only needs requests and requests-toolbelt, so it shouldn't be too difficult to keep it up to date and integrated with the rest of REANA. One plus of using an external library would be that it can be used also in r-w-controller, and not only in r-server (even though r-server and r-w-controller might be merged at some point, see all the discussions we have had on the topic).

Copy link
Member Author

Choose a reason for hiding this comment

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

In any case, we would probably still need to wrap the library to use our custom errors, or we would need to change the rest of the code to check for the library's errors.

).content

# request access token
client = GitLabClient()
Copy link
Member

Choose a reason for hiding this comment

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

Cosmetics: since we may have a REANA client in the module, it may be good to be more specific and instead of client use gitlab_client everywhere as the symbol name? Currently some lines have shorter name, some longer:

reana_server/rest/gitlab.py:177:            client = GitLabClient()
reana_server/rest/gitlab.py:182:            authenticated_client = GitLabClient(access_token=access_token)
reana_server/rest/gitlab.py:318:        client = GitLabClient.from_k8s_secret(user.id_)
reana_server/rest/gitlab.py:476:        client = GitLabClient.from_k8s_secret(user.id_)
reana_server/utils.py:447:    client = GitLabClient.from_k8s_secret(user_id)
reana_server/utils.py:467:        client = GitLabClient.from_k8s_secret(user.id_)
tests/test_gitlab_client.py:40:     gitlab_client = GitLabClient.from_k8s_secret(user_id, host="gitlab.example.org")
tests/test_gitlab_client.py:70:     gitlab_client = GitLabClient(
tests/test_gitlab_client.py:92:     gitlab_client = GitLabClient(
tests/test_gitlab_client.py:113:    gitlab_client = GitLabClient(
tests/test_gitlab_client.py:133:    gitlab_client = GitLabClient(
tests/test_gitlab_client.py:166:    gitlab_client = GitLabClient(
tests/test_gitlab_client.py:188:    gitlab_client = GitLabClient(
tests/test_gitlab_client.py:210:    gitlab_client = GitLabClient(
tests/test_gitlab_client.py:235:    gitlab_client = GitLabClient(
tests/test_gitlab_client.py:261:    gitlab_client = GitLabClient(

Just cosmetics, since the context is usually very clear...

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.

gitlab: triggering workflow fails with KeyError: 'workflow'
2 participants