Skip to content

Commit

Permalink
[AAP-18790] Remove Audit Events endpoints (#561)
Browse files Browse the repository at this point in the history
  * Remove /audit-events/ endpoints as they are not used by the UI

Solves: AAP-18790

Co-authored-by: Alex <[email protected]>
  • Loading branch information
Dostonbek1 and Alex-Izquierdo authored Dec 11, 2023
1 parent ad2b227 commit fa20e53
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 137 deletions.
1 change: 0 additions & 1 deletion src/aap_eda/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
router.register("activations", views.ActivationViewSet)
router.register("activation-instances", views.ActivationInstanceViewSet)
router.register("audit-rules", views.AuditRuleViewSet)
router.register("audit-events", views.AuditEventViewSet)
router.register("users", views.UserViewSet)
router.register(
"users/me/awx-tokens",
Expand Down
2 changes: 0 additions & 2 deletions src/aap_eda/api/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from .decision_environment import DecisionEnvironmentViewSet
from .project import ExtraVarViewSet, ProjectViewSet
from .rulebook import (
AuditEventViewSet,
AuditRuleViewSet,
RulebookViewSet,
RulesetViewSet,
Expand All @@ -35,7 +34,6 @@
# project
"ExtraVarViewSet",
"ProjectViewSet",
"AuditEventViewSet",
"AuditRuleViewSet",
"RulebookViewSet",
"RulesetViewSet",
Expand Down
38 changes: 0 additions & 38 deletions src/aap_eda/api/views/rulebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,44 +321,6 @@ def events(self, _request, id):
return self.get_paginated_response(serializer.data)


@extend_schema_view(
retrieve=extend_schema(
description="Get the audit event by its id",
responses={
status.HTTP_200_OK: OpenApiResponse(
serializers.AuditEventSerializer,
description="Return the audit event by its id.",
),
},
),
list=extend_schema(
description="List all audit events",
responses={
status.HTTP_200_OK: OpenApiResponse(
serializers.AuditEventSerializer,
description="Return a list of audit events.",
),
},
),
)
class AuditEventViewSet(
viewsets.ReadOnlyModelViewSet,
):
queryset = models.AuditEvent.objects.all()
serializer_class = serializers.AuditEventSerializer
filter_backends = (defaultfilters.DjangoFilterBackend, OrderingFilter)
filterset_class = filters.AuditRuleEventFilter
ordering_fields = [
"id",
"source_name",
"source_type",
"received_at",
"rule_fired_at",
]

rbac_resource_type = ResourceType.AUDIT_EVENT


class RuleViewSet(
viewsets.ReadOnlyModelViewSet,
):
Expand Down
96 changes: 0 additions & 96 deletions tests/integration/api/test_rulebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,102 +580,6 @@ def test_list_events_from_audit_rule_ordering(
)


# ------------------------------------------
# Test Audit Event:
# ------------------------------------------
@pytest.mark.django_db
def test_list_audit_events(client: APIClient, init_db):
response = client.get(f"{api_url_v1}/audit-events/")
assert response.status_code == status.HTTP_200_OK
audit_events = response.data["results"]

assert len(audit_events) == 4
assert audit_events[0]["received_at"] > audit_events[1]["received_at"]


@pytest.mark.django_db
def test_list_audit_events_filter_name(client: APIClient, init_db):
filter_name = "event-1"

response = client.get(
f"{api_url_v1}/audit-events/?source_name={filter_name}"
)
assert response.status_code == status.HTTP_200_OK
filtered_audit_events = response.data["results"]

assert len(filtered_audit_events) == 1
assert filtered_audit_events[0]["source_name"] == "event-1"
assert list(filtered_audit_events[0]) == [
"id",
"source_name",
"source_type",
"received_at",
"payload",
"rule_fired_at",
"audit_actions",
]


@pytest.mark.django_db
def test_list_audit_events_filter_name_non_existent(
client: APIClient, init_db
):
filter_name = "doesn't exist"

response = client.get(
f"{api_url_v1}/audit-events/?source_name={filter_name}"
)
assert response.status_code == status.HTTP_200_OK
data = response.json()["results"]
assert data == []


@pytest.mark.parametrize(
"ordering_field",
["source_name", "source_type", "received_at", "rule_fired_at"],
)
@pytest.mark.django_db
def test_list_events_ordering(client: APIClient, init_db, ordering_field):
audit_rule_id = init_db.audit_rule_1.id
response = client.get(
f"{api_url_v1}/audit-rules/{audit_rule_id}/events/?ordering="
f"{ordering_field}"
)
assert response.status_code == status.HTTP_200_OK
events = response.data["results"]
assert len(events) == 4
assert events[0][ordering_field] == getattr(
init_db.audit_event_1, ordering_field
)

response = client.get(
f"{api_url_v1}/audit-rules/{audit_rule_id}/events/?ordering="
f"-{ordering_field}"
)
assert response.status_code == status.HTTP_200_OK
events = response.data["results"]
assert len(events) == 4
assert events[0][ordering_field] == getattr(
init_db.audit_event_4, ordering_field
)


@pytest.mark.django_db
def test_retrieve_audit_event(client: APIClient, init_db):
audit_event_id = init_db.audit_event_1.id

response = client.get(f"{api_url_v1}/audit-events/{audit_event_id}/")

assert response.status_code == status.HTTP_200_OK
assert response.data["source_name"] == "event-1"


@pytest.mark.django_db
def test_retrieve_audit_event_not_exist(client: APIClient):
response = client.get(f"{api_url_v1}/audit-events/42/")
assert response.status_code == status.HTTP_404_NOT_FOUND


@pytest.mark.django_db
def test_delete_project_and_rulebooks(client: APIClient, init_db):
project_id = init_db.project.id
Expand Down

0 comments on commit fa20e53

Please sign in to comment.