- Notifications
You must be signed in to change notification settings - Fork673
chore: add authentication type to GitlabAuthenticationError#1793
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -96,6 +96,7 @@ def __init__( | ||
self.http_password = http_password | ||
self.oauth_token = oauth_token | ||
self.job_token = job_token | ||
self.auth_type = "" | ||
self._set_auth_info() | ||
#: Create a session object for requests | ||
@@ -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) | ||
self.auth_type = "private_token" | ||
if self.oauth_token: | ||
self.headers["Authorization"] = f"Bearer {self.oauth_token}" | ||
self.headers.pop("PRIVATE-TOKEN", None) | ||
self.headers.pop("JOB-TOKEN", None) | ||
self.auth_type = "oauth_token" | ||
if self.job_token: | ||
self.headers.pop("Authorization", None) | ||
self.headers.pop("PRIVATE-TOKEN", None) | ||
self.headers["JOB-TOKEN"] = self.job_token | ||
self.auth_type = "job_token" | ||
if self.http_username: | ||
self._http_auth = requests.auth.HTTPBasicAuth( | ||
self.http_username, self.http_password | ||
) | ||
self.auth_type = "password" | ||
def enable_debug(self) -> None: | ||
import logging | ||
@@ -722,6 +727,7 @@ def http_request( | ||
response_code=result.status_code, | ||
error_message=error_message, | ||
response_body=result.content, | ||
auth_type=self.auth_type, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I think we could actually reuse
| ||
) | ||
raise gitlab.exceptions.GitlabHttpError( | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -52,7 +52,24 @@ def __str__(self) -> str: | ||
class GitlabAuthenticationError(GitlabError): | ||
def __init__( | ||
self, | ||
error_message: Union[str, bytes] = "", | ||
response_code: Optional[int] = None, | ||
response_body: Optional[bytes] = None, | ||
auth_type: str = "", | ||
) -> None: | ||
super().__init__( | ||
error_message=error_message, | ||
response_code=response_code, | ||
response_body=response_body, | ||
) | ||
self.auth_type = auth_type | ||
Comment on lines +55 to +67 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Maybe we could add | ||
def __str__(self) -> str: | ||
if self.auth_type: | ||
return f"{super().__str__()}: authentication_type: {self.auth_type}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. If we decide to infer the auth type automatically I'd maybe reformulate this a bit. Not sure exactly how, just | ||
return super().__str__() | ||
class RedirectError(GitlabError): | ||