Skip to content

Commit

Permalink
Formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
GGP1 committed Aug 6, 2024
1 parent 2b94bc1 commit e479d32
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apis/comms_api/middlewares/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from comms_api.middlewares.logging import LoggingMiddleware, log_request


@freeze_time(datetime(1970, 1, 1, 0, 0, 0))
async def test_log_request():
"""Test log request calls."""
Expand Down Expand Up @@ -46,6 +47,7 @@ async def test_log_request():
log_info_mock.info.has_calls([call(log_info, {'log_type': 'log'}),
call(json_info, {'log_type': 'json'})])


@pytest.mark.asyncio
@freeze_time(datetime(1970, 1, 1, 0, 0, 0))
async def test_logging_middleware():
Expand Down
2 changes: 2 additions & 0 deletions apis/comms_api/middlewares/test/test_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from comms_api.middlewares.timeout import DEFAULT_TIMEOUT, TimeoutMiddleware


@pytest.mark.asyncio
@pytest.mark.parametrize("endpoint,expected_timeout", [
('/authentication', 20),
Expand All @@ -29,6 +30,7 @@ async def test_timeout_middleware(endpoint, expected_timeout):
_ = await middleware.dispatch(request=mock_req, call_next=call_next_mock)
wait_for_mock.assert_called_once_with(call_next_mock(mock_req), timeout=expected_timeout)


@pytest.mark.asyncio
async def test_timeout_middleware_ko():
"""Test timeout middleware exception handling."""
Expand Down
1 change: 1 addition & 0 deletions apis/comms_api/middlewares/timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'/files': 15
}


class TimeoutMiddleware(BaseHTTPMiddleware):
"""Middleware to set endpoint-specific timeouts."""

Expand Down
1 change: 1 addition & 0 deletions apis/comms_api/models/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from fastapi.responses import JSONResponse


class ErrorResponse(JSONResponse):
"""Error response model."""

Expand Down
2 changes: 2 additions & 0 deletions apis/comms_api/models/test/error_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from comms_api.models.error import ErrorResponse


@pytest.mark.parametrize('message,code,status_code,expected', [
('value1', 1001, 500, '{"message": "value1", "code": 1001}'),
('value2', None, 2, '{"message": "value2", "code": 2}'),
Expand All @@ -15,6 +16,7 @@ def test_error_response_render(message: str, code: int, status_code: int, expect
assert isinstance(actual, str)
assert expected == actual


def test_error_response_render_none():
"""Test Error class `render` method with empty parameters."""
message = 'value'
Expand Down
1 change: 1 addition & 0 deletions apis/comms_api/routers/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

router = APIRouter(prefix='/api/v1')


@router.get("/")
async def home():
return Response(status_code=status.HTTP_200_OK)
7 changes: 7 additions & 0 deletions apis/comms_api/scripts/wazuh_comms_apid.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

MAIN_PROCESS = 'wazuh-comms-apid'


def setup_logging(foreground_mode: bool) -> dict:
"""Sets up the logging module and returns the configuration used.
Expand All @@ -50,6 +51,7 @@ def setup_logging(foreground_mode: bool) -> dict:

return log_config_dict


def configure_ssl(keyfile: str, certfile: str) -> None:
"""Generate SSL key file and self-siged certificate if they do not exist.
Expand Down Expand Up @@ -77,6 +79,7 @@ def configure_ssl(keyfile: str, certfile: str) -> None:
else:
raise WazuhCommsAPIError(2703, extra_message=str(exc))


def ssl_context(conf, default_ssl_context_factory) -> ssl.SSLContext:
"""Returns the default SSL context with a custom minimum version.
Expand All @@ -89,6 +92,7 @@ def ssl_context(conf, default_ssl_context_factory) -> ssl.SSLContext:
context.minimum_version = ssl.TLSVersion.MINIMUM_SUPPORTED
return context


def get_gunicorn_options(pid: int, foreground_mode: bool, log_config_dict: dict) -> dict:
"""Get the gunicorn app configuration options.
Expand Down Expand Up @@ -130,6 +134,7 @@ def get_gunicorn_options(pid: int, foreground_mode: bool, log_config_dict: dict)
'user': os.getuid()
}


def get_script_arguments() -> Namespace:
"""Get script arguments.
Expand All @@ -147,6 +152,7 @@ def get_script_arguments() -> Namespace:

return parser.parse_args()


class StandaloneApplication(BaseApplication):
def __init__(self, app: Callable, options: Dict[str, Any] = None):
self.options = options or {}
Expand All @@ -165,6 +171,7 @@ def load_config(self):
def load(self):
return self.app


if __name__ == '__main__':
args = get_script_arguments()

Expand Down

0 comments on commit e479d32

Please sign in to comment.