From bc244f3891f59ff5893d0b86c52a69f494631a6d Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 31 Oct 2024 16:30:45 +0100 Subject: [PATCH] issue 100 new url in qr for evidence instead of device --- workbench-script.py | 39 +-------------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/workbench-script.py b/workbench-script.py index ae54da8..6a4c537 100644 --- a/workbench-script.py +++ b/workbench-script.py @@ -329,7 +329,7 @@ def send_to_sign_credential(snapshot, token, url): request = urllib.request.Request(url, data=data, headers=headers) with urllib.request.urlopen(request) as response: status_code = response.getcode() - response_text = response.read().decode('utf-8') + #response_text = response.read().decode('utf-8') if 200 <= status_code < 300: logger.info(_("Credential successfully signed")) @@ -341,43 +341,6 @@ def send_to_sign_credential(snapshot, token, url): logger.error(_("Credential cannot signed in '%s'"), url) return snapshot - except Exception as e: - logger.error(_("Credential not remotely builded to URL '%s'. Do you have internet? Is your server up & running? Is the url token authorized?\n %s"), url, e) - return json.dumps(snapshot) - - - -# TODO sanitize url, if url is like this, it fails -# url = 'http://127.0.0.1:8000/api/snapshot/' -def send_snapshot_to_devicehub(snapshot, token, url, ev_uuid): - url_components = urllib.parse.urlparse(url) - ev_path = f"evidence/{ev_uuid}" - components = (url_components.scheme, url_components.netloc, ev_path, '', '', '') - ev_url = urllib.parse.urlunparse(components) - # apt install qrencode - qr = "echo {} | qrencode -t ANSI".format(ev_url) - print(exec_cmd(qr)) - print(ev_url) - - headers = { - "Authorization": f"Bearer {token}", - "Content-Type": "application/json" - } - try: - data = snapshot.encode('utf-8') - request = urllib.request.Request(url, data=data, headers=headers) - with urllib.request.urlopen(request) as response: - status_code = response.getcode() - #response_text = response.read().decode('utf-8') - - if 200 <= status_code < 300: - logger.info(_("Snapshot successfully sent to '%s'"), url) - else: - logger.error(_("Snapshot cannot sent to '%s'"), url) - - except Exception as e: - logger.error(_("Snapshot not remotely sent to URL '%s'. Do you have internet? Is your server up & running? Is the url token authorized?\n %s"), url, e) - def load_config(config_file="settings.ini"): """