◐ Shell
reader mode source ↗
Skip to content
Draft
Show file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
6 changes: 6 additions & 0 deletions gitlab/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def __init__(
self.http_password = http_password
self.oauth_token = oauth_token
self.job_token = job_token
self._set_auth_info()

#: Create a session object for requests
Expand Up @@ -487,21 +488,25 @@ def _set_auth_info(self) -> None:
self.headers.pop("Authorization", None)
self.headers["PRIVATE-TOKEN"] = self.private_token
self.headers.pop("JOB-TOKEN", None)

if self.oauth_token:
self.headers["Authorization"] = f"Bearer {self.oauth_token}"
self.headers.pop("PRIVATE-TOKEN", None)
self.headers.pop("JOB-TOKEN", None)

if self.job_token:
self.headers.pop("Authorization", None)
self.headers.pop("PRIVATE-TOKEN", None)
self.headers["JOB-TOKEN"] = self.job_token

if self.http_username:
self._http_auth = requests.auth.HTTPBasicAuth(
self.http_username, self.http_password
)

def enable_debug(self) -> None:
import logging
Expand Down Expand Up @@ -722,6 +727,7 @@ def http_request(
response_code=result.status_code,
error_message=error_message,
response_body=result.content,
)

raise gitlab.exceptions.GitlabHttpError(
Expand Down
19 changes: 18 additions & 1 deletion gitlab/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,24 @@ def __str__(self) -> str:


class GitlabAuthenticationError(GitlabError):
pass


class RedirectError(GitlabError):
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,27 @@ def raise_error_from_http_error():
with pytest.raises(TestError) as context:
raise_error_from_http_error()
assert isinstance(context.value.__cause__, exceptions.GitlabHttpError)
Toggle all file notes Toggle all file annotations