Skip to content

Commit

Permalink
export/import domain capabilities (#1376)
Browse files Browse the repository at this point in the history
* Write serializers for exported models

* Add slug related fields to non-referential sluggable keys

* Add import/export serializer classes for Threat and ReferenceControl models

* Write unit tests for Vulnerability model

* Serialize models with their import/export serializer at dump time

* Add docstrings

* Remove filtering labels from export serializers


* Fix import order

* feat: add import endpoint and serializer validation

* feat: add topological sort for creation order

* Get objects to include in domain export

* Expose rudimentary domain export endpoint

* Serialize referential foreign keys using URN

* Serialize risk matrices and frameworks for export

* feat: order objects import with parent fields

* Hash primary keys on dump

* Serialize loaded libraries for export

* feat: move import to folders endpoint

* fix: self reference in dependency graph

* feat: start objecs creation

* feat: refactor object validation/creation

* feat: handle complete scenario creation

* Write serializers for exported models

* Add slug related fields to non-referential sluggable keys

* Add import/export serializer classes for Threat and ReferenceControl models

* Write unit tests for Vulnerability model

* Serialize dump

* Serialize models with their import/export serializer at dump time

* Add docstrings

* Remove filtering labels from export serializers

* Remove outdated comment

* Fix import order

* Get objects to include in domain export

* Expose rudimentary domain export endpoint

* Serialize referential foreign keys using URN

* Serialize risk matrices and frameworks for export

* Hash primary keys on dump

* Serialize loaded libraries for export

* Update vulnerability import export unit tests

* Serialize evidence attachment size for export

* remove folders from domain export

* Serialize evidence attachment hash for export

* Compress domain dump file

* chore: Remove unused imports

* feat: add ebios rm objects import

* Use HttpResponse for domain export dump file

* feat: remove attachment hash and size before evidence creation

* feat: process gzip

* feat: prepare frontend folder import

* Port domain export to the frontend

* Remove redundant serializer field

* Pass enctype to folder import form as props

* Validate that folder import file is a file

* Manage domain dump upload

* chore: format codebase

* feat: improve methods complexity

* chore: format

* chore: format with good version

* fix: change import button data-testid

* style: improve colors and labels

* feat: add slugified domain name in export file name

* chore: format file input component in FolderForm

* locale: add fr translations

* chore: use match cases instead of elifs

* feat: handle name check error on frontend

* feat: validate backup version on import

* feat: adding transaction to avoid object creation if failure

* Export attachments with evidence

* Write zipfile in memory and add some logging

* feat: improve error handling

* chore: ruff format

* Attachment upload PoC

* Fix domain import in enterprise frontend

* WIP

* fix attachment management

* ruff

* fix broken html/zip export of audit

* ruff

---------

Co-authored-by: Nassim Tabchiche <n.tabchiche2@gmail.com>
Co-authored-by: Mohamed-Hacene <mohamedhacene.b@gmail.com>
  • Loading branch information
3 people authored Jan 18, 2025
1 parent c140e1f commit 5353ebc
Show file tree
Hide file tree
Showing 26 changed files with 2,474 additions and 192 deletions.
7 changes: 7 additions & 0 deletions backend/core/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import re
import hashlib
from datetime import date, datetime
from pathlib import Path
from typing import Self, Type, Union
Expand Down Expand Up @@ -1729,6 +1730,12 @@ def get_size(self):
else:
return f"{size / 1024 / 1024:.1f} MB"

@property
def attachment_hash(self):
if not self.attachment:
return None
return hashlib.sha256(self.attachment.read()).hexdigest()


class AppliedControl(NameDescriptionMixin, FolderMixin, PublishInRootFolderMixin):
class Status(models.TextChoices):
Expand Down
16 changes: 16 additions & 0 deletions backend/core/serializer_fields.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
from hashlib import sha256
from typing import Any

from django.db import models
from rest_framework import serializers

from iam.models import Folder


class HashSlugRelatedField(serializers.SlugRelatedField):
"""
A custom SlugRelatedField that hashes the slug value during serialization.
"""

def to_representation(self, obj):
# Get the original slug value
value = super().to_representation(obj)
if value is None:
return None
# Hash the value
return sha256(str(value).encode()).hexdigest()[:12]


class FieldsRelatedField(serializers.RelatedField):
"""
Serializer relational field that represents the target of the relationship by a
Expand Down
Loading

0 comments on commit 5353ebc

Please sign in to comment.