Live-USB durch eigenständige Anwendung ersetzen
Some checks failed
Tests / test (push) Has been cancelled

This commit is contained in:
2026-10-15 10:26:33 +02:00
parent 692bbbb815
commit 1f91db25b5
23 changed files with 205 additions and 1228 deletions

View File

@@ -21,7 +21,13 @@ import urllib.error
import urllib.parse
import urllib.request
DEFAULT_DATA = Path('/mnt/intake-data')
def default_data_dir():
root = os.environ.get('XDG_DATA_HOME')
if root:
return Path(root) / 'csr-intake'
return Path.home() / '.local/share/csr-intake'
DEFAULT_DATA = default_data_dir()
def identity_value(value):
value = str(value or '').strip().casefold()
@@ -45,7 +51,7 @@ def hardware_id(report):
if serial and vendor:
payload = json.dumps([vendor, serial], ensure_ascii=True, separators=(',', ':'))
return 'dmi-serial-sha256:' + hashlib.sha256(payload.encode()).hexdigest()
raise ValueError('Keine zuverlässige Hardware-Kennung im Bericht. Mit der aktuellen USB-Version Hardware erneut erfassen; alte Berichte ohne Kennung werden nicht automatisch zugeordnet.')
raise ValueError('Keine zuverlässige Hardware-Kennung im Bericht. Mit der aktuellen Anwendung Hardware erneut erfassen; alte Berichte ohne Kennung werden nicht automatisch zugeordnet.')
def hardware_aliases(report):
primary = hardware_id(report)
@@ -105,7 +111,7 @@ def api_request(base, key, method, suffix, payload=None, timeout=12, ca_file=Non
'Authorization': 'Api-Key ' + key,
'Accept': 'application/json',
'Content-Type': 'application/json',
'User-Agent': 'pc-intake-usb/1.4',
'User-Agent': 'csr-intake/2.6',
})
context = ssl.create_default_context()
if ca_file:
@@ -127,7 +133,7 @@ def credentials(config):
raise ValueError('Inventory URL must be an HTTPS origin (e.g. https://inventory.example.org)')
key = os.environ.get('CSR_API_KEY', '')
if not key:
secret = Path(config.get('key_file', '/mnt/intake-data/config/inventory-api-key'))
secret = Path(config.get('key_file', DEFAULT_DATA / 'config/inventory-api-key'))
key = secret.read_text(encoding='utf-8').strip()
if not key:
raise ValueError('No API key configured')
@@ -304,7 +310,7 @@ def queue_inspection(root,path,phase):
ident=inspection['identity']
identity={'system_uuid':ident.get('uuid'),'serial_number':ident.get('serial'),
'manufacturer':ident.get('manufacturer'),'model':ident.get('model')}
# An immutable report provides chassis information, not the USB host's hardware.
# An immutable report provides the inspected computer's chassis information.
if inspection.get('report'): identity.update({k:inspection['report'].get(k,identity.get(k)) for k in ['system_uuid','serial_number','manufacturer','model','chassis_type','batteries']})
results={k:{'outcome':v['outcome'],'notes':v.get('notes',''),'history':v.get('history',[]),'evidence':v.get('evidence','')} for k,v in inspection['checks'].items()}
body={'hwid':hardware_id(identity),'phase':phase,'technician':inspection.get('technician',''),
@@ -328,7 +334,7 @@ def flush_inspections(root,config):
def run_station(root,action,report_path):
# Recover the last saved snapshot even if power was lost before a worker queued it.
# These files may belong to a different PC previously visited by this USB.
# These files may belong to a different PC inspected earlier on this workstation.
if action in ['boot','flush']:
for saved in sorted((root/'inspections').glob('*.json')):
inspection=json.loads(saved.read_text())