inxi (take 2) #38

Merged
pedro merged 12 commits from inxi into main 2024-12-16 18:48:42 +00:00
3 changed files with 27 additions and 9 deletions
Showing only changes of commit abdefe885e - Show all commits

View file

@ -85,17 +85,21 @@ class NewSnapshotView(ApiMixing):
# except Exception:
# return JsonResponse({'error': 'Invalid Snapshot'}, status=400)
if not data.get("uuid"):
ev_uuid = data.get("uuid")
if data.get("credentialSubject"):
ev_uuid = data["credentialSubject"].get("uuid")
if not ev_uuid:
txt = "error: the snapshot not have uuid"
logger.error("%s", txt)
return JsonResponse({'status': txt}, status=500)
exist_annotation = Annotation.objects.filter(
uuid=data['uuid']
uuid=ev_uuid
).first()
if exist_annotation:
txt = "error: the snapshot {} exist".format(data['uuid'])
txt = "error: the snapshot {} exist".format(ev_uuid)
logger.warning("%s", txt)
return JsonResponse({'status': txt}, status=500)
@ -105,14 +109,14 @@ class NewSnapshotView(ApiMixing):
except Exception as err:
if settings.DEBUG:
logger.exception("%s", err)
snapshot_id = data.get("uuid", "")
snapshot_id = ev_uuid
txt = "It is not possible to parse snapshot: %s."
logger.error(txt, snapshot_id)
text = "fail: It is not possible to parse snapshot"
return JsonResponse({'status': text}, status=500)
annotation = Annotation.objects.filter(
uuid=data['uuid'],
uuid=ev_uuid,
type=Annotation.Type.SYSTEM,
# TODO this is hardcoded, it should select the user preferred algorithm
key="hidalgo1",
@ -121,7 +125,7 @@ class NewSnapshotView(ApiMixing):
if not annotation:
logger.error("Error: No annotation for uuid: %s", data["uuid"])
logger.error("Error: No annotation for uuid: %s", ev_uuid)
return JsonResponse({'status': 'fail'}, status=500)
url_args = reverse_lazy("device:details", args=(annotation.value,))

View file

@ -32,7 +32,18 @@ def get_mac(inxi):
class Build:
def __init__(self, evidence_json, user, check=False):
self.json = evidence_json
self.evidence = evidence_json.copy()
self.json = evidence_json.copy()
if evidence_json.get("credentialSubject"):
self.json.update(evidence_json["credentialSubject"])
if evidence_json.get("evidence"):
self.json["data"] = {}
for ev in evidence_json["evidence"]:
k = ev.get("operation")
if not k:
continue
self.json["data"][k] = ev.get("output")
self.uuid = self.json['uuid']
self.user = user
self.hid = None
@ -49,7 +60,7 @@ class Build:
self.register_device_dlt()
def index(self):
snap = json.dumps(self.json)
snap = json.dumps(self.evidence)
index(self.user.institution, self.uuid, snap)
def generate_chids(self):

View file

@ -19,7 +19,10 @@ def move_json(path_name, user, place="snapshots"):
def save_in_disk(data, user, place="snapshots"):
uuid = data.get('uuid', '')
uuid = data.get("uuid")
if data.get("credentialSubject"):
uuid = data["credentialSubject"].get("uuid")
now = datetime.now()
year = now.year
month = now.month