2024-12-11 01:33:07 +00:00
|
|
|
from typing import Optional
|
2024-12-11 02:35:17 +00:00
|
|
|
from typing import Any
|
2024-12-11 01:33:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
class KanidmQueryError(Exception):
|
|
|
|
"""Error occurred during kanidm query"""
|
|
|
|
|
2024-12-13 13:51:40 +00:00
|
|
|
def __init__(
|
2024-12-19 01:16:41 +00:00
|
|
|
self,
|
|
|
|
error_text: Optional[Any] = None,
|
|
|
|
endpoint: Optional[str] = None,
|
|
|
|
method: Optional[str] = None,
|
2024-12-13 13:51:40 +00:00
|
|
|
) -> None:
|
|
|
|
self.error_text = str(error_text)
|
|
|
|
self.endpoint = endpoint
|
2024-12-19 01:16:41 +00:00
|
|
|
self.method = method
|
2024-12-11 01:33:07 +00:00
|
|
|
|
|
|
|
def get_error_message(self) -> str:
|
2024-12-13 13:51:40 +00:00
|
|
|
message = "An error occurred during the Kanidm query."
|
2024-12-19 01:16:41 +00:00
|
|
|
if self.method:
|
|
|
|
message += f" Method: {self.method}"
|
2024-12-13 13:51:40 +00:00
|
|
|
if self.endpoint:
|
|
|
|
message += f" Endpoint: {self.endpoint}"
|
|
|
|
if self.error_text:
|
|
|
|
message += f" Error: {self.error_text}"
|
|
|
|
return message
|
2024-12-11 01:33:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
class KanidmReturnEmptyResponse(Exception):
|
|
|
|
"""Kanidm returned a blank response"""
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_error_message() -> str:
|
|
|
|
return "Kanidm returned an empty response."
|
|
|
|
|
|
|
|
|
|
|
|
class KanidmReturnUnknownResponseType(Exception):
|
|
|
|
"""Kanidm returned a blank response"""
|
|
|
|
|
2024-12-11 02:35:17 +00:00
|
|
|
def __init__(self, response_data: Optional[Any] = None) -> None:
|
|
|
|
self.response_data = str(response_data)
|
2024-12-11 01:41:44 +00:00
|
|
|
|
|
|
|
def get_error_message(self) -> str:
|
|
|
|
return (
|
|
|
|
f"Kanidm returned unknown type response. Response: {self.response_data}"
|
|
|
|
if self.response_data
|
|
|
|
else "Kanidm returned unknown type response."
|
|
|
|
)
|
2024-12-11 01:33:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
class KanidmDidNotReturnAdminPassword(Exception):
|
|
|
|
"""Kanidm didn't return the admin password"""
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_error_message() -> str:
|
|
|
|
return "Kanidm didn't return the admin password."
|
2024-12-11 11:16:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class KanidmCliSubprocessError(Exception):
|
|
|
|
"""An error occurred when using Kanidm cli"""
|
|
|
|
|
|
|
|
def __init__(self, error: Optional[str] = None) -> None:
|
|
|
|
self.error = error
|
|
|
|
|
|
|
|
def get_error_message(self) -> str:
|
|
|
|
return (
|
|
|
|
f"An error occurred when using Kanidm cli. Error: {self.error}"
|
|
|
|
if self.error
|
2024-12-18 02:20:50 +00:00
|
|
|
else "An error occurred when using Kanidm cli"
|
2024-12-11 11:16:14 +00:00
|
|
|
)
|
2024-12-12 12:00:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
class FailedToGetValidKanidmToken(Exception):
|
|
|
|
"""Kanidm failed to return a valid token"""
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_error_message() -> str:
|
|
|
|
return "Failed to get valid Kanidm token."
|