Skip to content
This repository was archived by the owner on Nov 2, 2024. It is now read-only.

Commit 266c75b

Browse files
cristinaascariMichalsus
authored andcommitted
* added bi document * update bi interface * update bi interface * fix bi serializer * update certego-saas version
1 parent 85f26a6 commit 266c75b

File tree

4 files changed

+8
-17
lines changed

4 files changed

+8
-17
lines changed

api_app/serializers/__init__.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
from django.conf import settings
2-
from django.utils.timezone import now
32
from rest_framework import serializers as rfs
43
from rest_framework.exceptions import ValidationError
54
from rest_framework.fields import Field
6-
from rest_framework.serializers import ModelSerializer
75

86
from api_app.interfaces import OwnershipAbstractModel
97
from certego_saas.apps.organization.organization import Organization
8+
from certego_saas.ext.upload.elastic import BISerializer
109

1110

12-
class AbstractBIInterface(ModelSerializer):
11+
class AbstractBIInterface(BISerializer):
1312
application = rfs.CharField(read_only=True, default="IntelOwl")
1413
environment = rfs.SerializerMethodField(method_name="get_environment")
15-
timestamp: Field
1614
username: Field
1715
name: Field
1816
class_instance = rfs.SerializerMethodField(
@@ -23,10 +21,7 @@ class AbstractBIInterface(ModelSerializer):
2321
end_time: Field
2422

2523
class Meta:
26-
fields = [
27-
"application",
28-
"environment",
29-
"timestamp",
24+
fields = BISerializer.Meta.fields + [
3025
"username",
3126
"name",
3227
"class_instance",
@@ -48,12 +43,8 @@ def get_environment(instance):
4843
return "test"
4944

5045
@staticmethod
51-
def to_elastic_dict(data):
52-
return {
53-
"_source": data,
54-
"_index": settings.ELASTICSEARCH_BI_INDEX + "-" + now().strftime("%Y.%m"),
55-
"_op_type": "index",
56-
}
46+
def get_index():
47+
return settings.ELASTICSEARCH_BI_INDEX
5748

5849

5950
class ModelWithOwnershipSerializer(rfs.ModelSerializer):

api_app/serializers/job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ class Meta:
10791079

10801080
def to_representation(self, instance: Job):
10811081
data = super().to_representation(instance)
1082-
return self.to_elastic_dict(data)
1082+
return self.to_elastic_dict(data, self.get_index())
10831083

10841084
@staticmethod
10851085
def get_playbook(instance: Job):

api_app/serializers/report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Meta:
3232

3333
def to_representation(self, instance: AbstractReport):
3434
data = super().to_representation(instance)
35-
return self.to_elastic_dict(data)
35+
return self.to_elastic_dict(data, self.get_index())
3636

3737
def get_class_instance(self, instance: AbstractReport):
3838
return super().get_class_instance(instance).split("report")[0]

requirements/certego-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
certego-saas==0.7.7
1+
certego-saas==0.7.10
22
# While developing for certego-saas, comment the previous line.
33
# Then, add a line like the one below to your forked repo and your most recent commit
44
# In this way you can test your changes directly in IntelOwl with the complete application

0 commit comments

Comments
 (0)