Skip to content

Commit

Permalink
Logging fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zkayyali812 committed Aug 15, 2024
1 parent b4b3456 commit 0cd4e34
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 217 deletions.
103 changes: 15 additions & 88 deletions src/aap_eda/api/views/activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,13 @@ def create(self, request):
process_parent_type=ProcessParentType.ACTIVATION,
process_parent_id=response.id,
)
logging_kwargs = {
"isEnabled": response.is_enabled,
"Project": logging_utils.get_project_name_from_id(
response.project_id
),
"Rulebook": logging_utils.get_rulebook_name_from_id(
response.rulebook_id
),
"DecisionEnvironment": logging_utils.get_de_name_from_id(
response.decision_environment_id
),
}

logger.info(
logging_utils.generate_simple_audit_log(
"Create",
resource_name,
response.name,
response.organization,
**logging_kwargs,
)
)

Expand All @@ -141,35 +129,22 @@ def destroy(self, request, *args, **kwargs):
"deleted.",
)

audit_log = logging_utils.generate_simple_audit_log(
"Delete",
resource_name,
activation.name,
activation.organization,
)

activation.status = ActivationStatus.DELETING
activation.save(update_fields=["status"])
logger.info(f"Now deleting {activation.name} ...")

delete_rulebook_process(
process_parent_type=ProcessParentType.ACTIVATION,
process_parent_id=activation.id,
)

logging_kwargs = {
"isEnabled": activation.is_enabled,
"Project": logging_utils.get_project_name_from_id(
activation.project_id
),
"Rulebook": logging_utils.get_rulebook_name_from_id(
activation.rulebook_id
),
"DecisionEnvironment": logging_utils.get_de_name_from_id(
activation.decision_environment_id
),
}
logger.info(
logging_utils.generate_simple_audit_log(
"Delete",
resource_name,
activation.name,
activation.organization,
**logging_kwargs,
)
)
logger.info(audit_log)

return Response(status=status.HTTP_204_NO_CONTENT)

Expand All @@ -179,25 +154,12 @@ def destroy(self, request, *args, **kwargs):
def retrieve(self, request, pk: int):
activation = self.get_object()

logging_kwargs = {
"isEnabled": activation.is_enabled,
"Project": logging_utils.get_project_name_from_id(
activation.project_id
),
"Rulebook": logging_utils.get_rulebook_name_from_id(
activation.rulebook_id
),
"DecisionEnvironment": logging_utils.get_de_name_from_id(
activation.decision_environment_id
),
}
# logger.info(
# logging_utils.generate_simple_audit_log(
# "Read",
# resource_name,
# activation.name,
# activation.organization,
# **logging_kwargs,
# )
# )

Expand All @@ -223,7 +185,10 @@ def list(self, request):

logger.info(
logging_utils.generate_simple_audit_log(
"ListActivations", resource_name, "*", "*", **{}
"ListActivations",
resource_name,
"*",
"*",
)
)
return self.get_paginated_response(result)
Expand Down Expand Up @@ -337,25 +302,12 @@ def enable(self, request, pk):
process_parent_id=pk,
)

logging_kwargs = {
"isEnabled": activation.is_enabled,
"Project": logging_utils.get_project_name_from_id(
activation.project_id
),
"Rulebook": logging_utils.get_rulebook_name_from_id(
activation.rulebook_id
),
"DecisionEnvironment": logging_utils.get_de_name_from_id(
activation.decision_environment_id
),
}
logger.info(
logging_utils.generate_simple_audit_log(
"Enable",
resource_name,
activation.name,
activation.organization,
**logging_kwargs,
)
)

Expand Down Expand Up @@ -387,25 +339,13 @@ def disable(self, request, pk):
process_parent_type=ProcessParentType.ACTIVATION,
process_parent_id=activation.id,
)
logging_kwargs = {
"isEnabled": activation.is_enabled,
"Project": logging_utils.get_project_name_from_id(
activation.project_id
),
"Rulebook": logging_utils.get_rulebook_name_from_id(
activation.rulebook_id
),
"DecisionEnvironment": logging_utils.get_de_name_from_id(
activation.decision_environment_id
),
}

logger.info(
logging_utils.generate_simple_audit_log(
"Disable",
resource_name,
activation.name,
activation.organization,
**logging_kwargs,
)
)
return Response(status=status.HTTP_204_NO_CONTENT)
Expand Down Expand Up @@ -451,25 +391,12 @@ def restart(self, request, pk):
process_parent_id=activation.id,
)

logging_kwargs = {
"isEnabled": activation.is_enabled,
"Project": logging_utils.get_project_name_from_id(
activation.project_id
),
"Rulebook": logging_utils.get_rulebook_name_from_id(
activation.rulebook_id
),
"DecisionEnvironment": logging_utils.get_de_name_from_id(
activation.decision_environment_id
),
}
logger.info(
logging_utils.generate_simple_audit_log(
"Restart",
resource_name,
activation.name,
activation.organization,
**logging_kwargs,
)
)
return Response(status=status.HTTP_204_NO_CONTENT)
Expand Down
100 changes: 32 additions & 68 deletions src/aap_eda/api/views/decision_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,52 +39,36 @@
resource_name = "DecisionEnvironment"


# class CreateDecisionEnvironmentMixin(CreateModelMixin):
# def create(self, request, *args, **kwargs):
# response = super().create(request, *args, **kwargs)

# logging_kwargs = {
# "Description": response.data["description"],
# "ImageURL": response.data["image_url"],
# "Credential": logging_utils.get_credential_name_from_data(
# response
# ),
# }
# logger.info(
# logging_utils.generate_simple_audit_log(
# "Create",
# resource_name,
# response.data["name"],
# logging_utils.get_organization_name_from_data(response),
# **logging_kwargs,
# )
# )

# return response


# class PartialUpdateOnlyDecisionEnvironmentMixin(PartialUpdateOnlyModelMixin):
# def partial_update(self, request, *args, **kwargs):
# response = super().partial_update(request, *args, **kwargs)

# logging_kwargs = {
# "Description": response.data["description"],
# "ImageURL": response.data["image_url"],
# "Credential": logging_utils.get_credential_name_from_data(
# response
# ),
# }
# logger.info(
# logging_utils.generate_simple_audit_log(
# "Update",
# resource_name,
# response.data["name"],
# logging_utils.get_organization_name_from_data(response),
# **logging_kwargs,
# )
# )

# return response
class CreateDecisionEnvironmentMixin(CreateModelMixin):
def create(self, request, *args, **kwargs):
response = super().create(request, *args, **kwargs)

logger.info(
logging_utils.generate_simple_audit_log(
"Create",
resource_name,
response.data["name"],
logging_utils.get_organization_name_from_data(response),
)
)

return response


class PartialUpdateOnlyDecisionEnvironmentMixin(PartialUpdateOnlyModelMixin):
def partial_update(self, request, *args, **kwargs):
response = super().partial_update(request, *args, **kwargs)

logger.info(
logging_utils.generate_simple_audit_log(
"Update",
resource_name,
response.data["name"],
logging_utils.get_organization_name_from_data(response),
)
)

return response


@extend_schema_view(
Expand Down Expand Up @@ -120,10 +104,8 @@
)
class DecisionEnvironmentViewSet(
ResponseSerializerMixin,
# CreateDecisionEnvironmentMixin,
# PartialUpdateOnlyDecisionEnvironmentMixin,
CreateModelMixin,
PartialUpdateOnlyModelMixin,
CreateDecisionEnvironmentMixin,
PartialUpdateOnlyDecisionEnvironmentMixin,
mixins.RetrieveModelMixin,
mixins.DestroyModelMixin,
mixins.ListModelMixin,
Expand Down Expand Up @@ -172,20 +154,12 @@ def retrieve(self, request, pk):
else None
)

logging_kwargs = {
"Description": decision_environment.data["description"],
"ImageURL": decision_environment.data["image_url"],
"Credential": logging_utils.get_credential_name_from_data(
decision_environment
),
}
# logger.info(
# logging_utils.generate_simple_audit_log(
# "Read",
# resource_name,
# decision_environment.data["name"],
# decision_environment.data["organization"],
# **logging_kwargs,
# )
# )

Expand Down Expand Up @@ -233,22 +207,12 @@ def destroy(self, request, *args, **kwargs):

self.perform_destroy(instance)

credential_name = instance.eda_credential
if instance.credential == "None":
credential_name = instance.eda_credential.name

logging_kwargs = {
"Description": instance.description,
"ImageURL": instance.image_url,
"Credential": credential_name,
}
logger.info(
logging_utils.generate_simple_audit_log(
"Delete",
resource_name,
instance.name,
instance.organization,
**logging_kwargs,
)
)
return Response(status=status.HTTP_204_NO_CONTENT)
9 changes: 4 additions & 5 deletions src/aap_eda/api/views/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def destroy(self, request, *args, **kwargs):
resource_name,
project.name,
project.organization,
**{},
)
)

Expand Down Expand Up @@ -142,7 +141,6 @@ def create(self, request):
resource_name,
project.name,
project.organization,
**{},
)
)

Expand Down Expand Up @@ -187,7 +185,6 @@ def retrieve(self, request, pk):
# resource_name,
# project.data["name"],
# project.data["organization"].name,
# **{},
# )
# )

Expand Down Expand Up @@ -239,7 +236,6 @@ def partial_update(self, request, pk):
resource_name,
project.name,
project.organization,
**{},
)
)

Expand Down Expand Up @@ -287,7 +283,10 @@ def sync(self, request, pk):

logger.info(
logging_utils.generate_simple_audit_log(
"Sync", resource_name, project.name, project.organization, **{}
"Sync",
resource_name,
project.name,
project.organization,
)
)

Expand Down
Loading

0 comments on commit 0cd4e34

Please sign in to comment.