From 5d190d07a37afdf82f4f7e3cb3fcd6a4cca624ff Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 12 Dec 2024 17:11:05 +0100 Subject: [PATCH] fix rebase from main --- evidence/forms.py | 12 ++++++------ evidence/models.py | 11 +++++++---- evidence/parse.py | 16 ++-------------- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/evidence/forms.py b/evidence/forms.py index 83d9e6b..8be2887 100644 --- a/evidence/forms.py +++ b/evidence/forms.py @@ -29,17 +29,17 @@ class UploadForm(forms.Form): try: file_json = json.loads(file_data) - Build(file_json, None, check=True) + snap = Build(file_json, None, check=True) exist_annotation = Annotation.objects.filter( - uuid=file_json['uuid'] + uuid=snap.uuid ).first() - + if exist_annotation: - raise ValidationError( + raise ValidationError( _("The snapshot already exists"), code="duplicate_snapshot", ) - + #Catch any error and display it as Validation Error so the Form handles it except Exception as e: raise ValidationError( @@ -221,7 +221,7 @@ class EraseServerForm(forms.Form): if self.instance: return - + Annotation.objects.create( uuid=self.uuid, type=Annotation.Type.ERASE_SERVER, diff --git a/evidence/models.py b/evidence/models.py index 6b6069c..a10de01 100644 --- a/evidence/models.py +++ b/evidence/models.py @@ -68,8 +68,11 @@ class Evidence: def get_doc(self): self.doc = {} + self.inxi = None + if not self.owner: self.get_owner() + qry = 'uuid:"{}"'.format(self.uuid) matches = search(self.owner, qry, limit=1) if matches and matches.size() < 0: @@ -93,6 +96,10 @@ class Evidence: self.dmi = DMIParse(dmidecode_raw) try: self.inxi = json.loads(inxi_raw) + except Exception: + pass + if self.inxi: + try: machine = get_inxi_key(self.inxi, 'Machine') for m in machine: system = get_inxi(m, "System") @@ -102,7 +109,6 @@ class Evidence: self.device_serial_number = get_inxi(m, "serial") self.device_chassis = get_inxi(m, "Type") self.device_version = get_inxi(m, "v") - except Exception: return @@ -157,9 +163,6 @@ class Evidence: if self.inxi: return self.device_chassis - if self.inxi: - return self.device_chassis - chassis = self.dmi.get("Chassis")[0].get("Type", '_virtual') lower_type = chassis.lower() diff --git a/evidence/parse.py b/evidence/parse.py index 8e52a09..db2d32d 100644 --- a/evidence/parse.py +++ b/evidence/parse.py @@ -7,7 +7,6 @@ from evidence.parse_details import ParseSnapshot from evidence.models import Annotation from evidence.xapian import index -from dpp.api_dlt import register_device_dlt, register_passport_dlt from evidence.parse_details import get_inxi_key, get_inxi from django.conf import settings @@ -78,27 +77,16 @@ class Build: sku = device.get("sku", '') hid = f"{manufacturer}{model}{chassis}{serial_number}{sku}" - self.chid = hashlib.sha3_256(hid.encode()).hexdigest() return self.chid def get_chid_dpp(self): if self.json.get("software") == "workbench-script": - dmidecode_raw = self.json["data"]["dmidecode"] - dmi = DMIParse(dmidecode_raw) - - manufacturer = dmi.manufacturer().strip() - model = dmi.model().strip() - chassis = self.get_chassis_dh() - serial_number = dmi.serial_number() - sku = self.get_sku() - typ = chassis - version = self.get_version() - hid = f"{manufacturer}{model}{chassis}{serial_number}{sku}{typ}{version}" + device = ParseSnapshot(self.json).device else: device = self.json['device'] - hid = self.get_id_hw_dpp(device) + hid = self.get_id_hw_dpp(device) self.chid = hashlib.sha3_256(hid.encode("utf-8")).hexdigest() return self.chid