create credential from snapshot

This commit is contained in:
Cayo Puigdefabregas 2024-11-06 14:10:02 +01:00
parent bc244f3891
commit 017ad52eee
2 changed files with 11 additions and 8 deletions

View file

@ -3,8 +3,11 @@ url = http://localhost:8000/api/snapshot/
#url = https://demo.ereuse.org/api/v1/snapshot/ #url = https://demo.ereuse.org/api/v1/snapshot/
# sample token that works with default deployment such as the previous two urls # sample token that works with default deployment such as the previous two urls
token = 5018dd65-9abd-4a62-8896-80f34ac66150 token = 5018dd65-9abd-4a62-8896-80f34ac66150
# Idhub
# wb_sign_token = "27de6ad7-cee2-4fe8-84d4-c7eea9c969c8" # wb_sign_token = "27de6ad7-cee2-4fe8-84d4-c7eea9c969c8"
# url_wallet = "http://localhost" # url_wallet = "http://localhost"
# path = /path/to/save # path = /path/to/save
# device = your_device_name # device = your_device_name
# # erase = basic # # erase = basic

View file

@ -13,6 +13,8 @@ import gettext
import locale import locale
import logging import logging
from pathlib import Path
from string import Template
from datetime import datetime from datetime import datetime
@ -445,22 +447,20 @@ def main():
elif config['erase'] and not config.get("legacy"): elif config['erase'] and not config.get("legacy"):
snapshot['erase'] = gen_erase(all_disks, config['erase']) snapshot['erase'] = gen_erase(all_disks, config['erase'])
if config.get("wb_sign_token"):
tk = config.get("wb_sign_token").encode("utf8")
snapshot["token_hash"] = hashlib.hash256(tk).hexdigest()
if config.get("legacy"): if legacy:
convert_to_legacy_snapshot(snapshot) convert_to_legacy_snapshot(snapshot)
snapshot = json.dumps(snapshot) snapshot = json.dumps(snapshot)
else: else:
snapshot = convert_to_credential(snapshot)
url_wallet = config.get("url_wallet") url_wallet = config.get("url_wallet")
wb_sign_token = config.get("wb_sign_token") wb_sign_token = config.get("wb_sign_token")
if wb_sign_token:
tk = wb_sign_token.encode("utf8")
snapshot["operator_id"] = hashlib.sha3_256(tk).hexdigest()
if url_wallet and wb_sign_token: if url_wallet and wb_sign_token:
snapshot = send_to_sign_credential(snapshot, wb_sign_token, url_wallet) snapshot = send_to_sign_credential(snapshot, wb_sign_token, url_wallet)
else:
snapshot = json.dumps(snapshot)
save_snapshot_in_disk(snapshot, config['path'], snap_uuid) save_snapshot_in_disk(snapshot, config['path'], snap_uuid)