fix sign snapshots
This commit is contained in:
parent
3a7eb0f97e
commit
4c07920a6a
|
@ -680,7 +680,7 @@ class VerificableCredential(models.Model):
|
|||
credential_subject = ujson.loads(data).get("credentialSubject", {})
|
||||
return credential_subject.items()
|
||||
|
||||
def issue(self, did, domain, encrypt=True):
|
||||
def issue(self, did, domain, save=True):
|
||||
if self.status == self.Status.ISSUED:
|
||||
return
|
||||
|
||||
|
@ -700,7 +700,7 @@ class VerificableCredential(models.Model):
|
|||
if not valid:
|
||||
return
|
||||
|
||||
if not encrypt:
|
||||
if not save:
|
||||
return vc_str
|
||||
|
||||
self.data = self.user.encrypt_data(vc_str)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"issuer": "{{ issuer_did }}",
|
||||
"issuanceDate": "{{ issuance_date }}",
|
||||
"credentialSubject": {
|
||||
"operatorId": "123456789011121314",
|
||||
"operatorId": "{{ operator_id }}",
|
||||
"uuid": "{{ uuid }}",
|
||||
"type": "hardwareList",
|
||||
"software": "workbench-script",
|
||||
|
@ -44,13 +44,13 @@
|
|||
{
|
||||
"type": "HardwareList",
|
||||
"operation": "smartctl",
|
||||
"output": "{{ smartctl }}",
|
||||
"output": {{ smartctl|default:'""'|safe }},
|
||||
"timestamp": "{{ issuance_date }}"
|
||||
},
|
||||
{
|
||||
"type": "HardwareList",
|
||||
"operation": "inxi",
|
||||
"output": "{{ inxi }}",
|
||||
"output": {{ inxi|default:'""'|safe }},
|
||||
"timestamp": "{{ issuance_date }}"
|
||||
}
|
||||
],
|
||||
|
|
|
@ -24,7 +24,7 @@ def webhook_verify(request):
|
|||
if not auth_header or not auth_header.startswith('Bearer '):
|
||||
return JsonResponse({'error': 'Invalid or missing token'}, status=401)
|
||||
|
||||
token = auth_header.split(' ')[1]
|
||||
token = auth_header.split(' ')[1].strip("'").strip('"')
|
||||
tk = Token.objects.filter(token=token).first()
|
||||
if not tk:
|
||||
return JsonResponse({'error': 'Invalid or missing token'}, status=401)
|
||||
|
@ -60,7 +60,7 @@ def webhook_issue(request):
|
|||
if not auth_header or not auth_header.startswith('Bearer '):
|
||||
return JsonResponse({'error': 'Invalid or missing token'}, status=401)
|
||||
|
||||
token = auth_header.split(' ')[1]
|
||||
token = auth_header.split(' ')[1].strip("'").strip('"')
|
||||
tk = Token.objects.filter(token=token).first()
|
||||
if not tk:
|
||||
return JsonResponse({'error': 'Invalid or missing token'}, status=401)
|
||||
|
@ -72,23 +72,24 @@ def webhook_issue(request):
|
|||
|
||||
typ = data.get("type")
|
||||
vc = data.get("data")
|
||||
save = data.get("save", True)
|
||||
try:
|
||||
vc = json.dumps(vc)
|
||||
except Exception:
|
||||
return JsonResponse({'error': 'Invalid JSON'}, status=400)
|
||||
|
||||
user = User.objects.filter(email=data.get("user")).first()
|
||||
if not typ or not vc or not user:
|
||||
if not typ or not vc:
|
||||
return JsonResponse({'error': 'Invalid JSON'}, status=400)
|
||||
|
||||
did = DID.objects.filter(user__isnull=True).first()
|
||||
if not did:
|
||||
return JsonResponse({'error': 'Invalid DID'}, status=400)
|
||||
|
||||
schema = Schemas.objects.filter(file_schema=typ).first()
|
||||
schema = Schemas.objects.filter(type=typ).first()
|
||||
if not schema:
|
||||
return JsonResponse({'error': 'Invalid credential'}, status=400)
|
||||
|
||||
user = User.objects.filter(is_admin=True).first()
|
||||
cred = VerificableCredential(
|
||||
csv_data=vc,
|
||||
issuer_did=did,
|
||||
|
@ -97,7 +98,7 @@ def webhook_issue(request):
|
|||
)
|
||||
|
||||
cred.set_type()
|
||||
vc_signed = cred.issue(did, domain=request.get_host(), encrypt=False)
|
||||
vc_signed = cred.issue(did, domain=request.get_host(), save=save)
|
||||
|
||||
return JsonResponse({'status': 'success', "data": vc_signed}, status=200)
|
||||
|
||||
|
|
Loading…
Reference in a new issue