This commit is contained in:
@@ -111,7 +111,12 @@ def api_request(base, key, method, suffix, payload=None, timeout=12, ca_file=Non
|
||||
if ca_file:
|
||||
context.load_verify_locations(cafile=str(ca_file))
|
||||
with urllib.request.urlopen(request, timeout=timeout, context=context) as res:
|
||||
return json.loads(res.read(1024 * 1024).decode('utf-8'))
|
||||
result = json.loads(res.read(1024 * 1024).decode('utf-8'))
|
||||
if method == 'POST' and suffix.strip('/') == 'devices/resolve':
|
||||
status = getattr(res, 'status', None)
|
||||
if status in (200, 201):
|
||||
result['_registration'] = 'NEW' if status == 201 else 'EXISTING'
|
||||
return result
|
||||
|
||||
def credentials(config):
|
||||
base = config.get('url', '')
|
||||
@@ -346,9 +351,12 @@ def run_station(root,action,report_path):
|
||||
else:
|
||||
report=json.loads(report_path.read_text()) if report_path else station_identity()
|
||||
device=station_resolve(config,report)
|
||||
registration=device.get('_registration')
|
||||
if action=='intake' and device['stage']=='INTAKE':
|
||||
device=station_api(config,'POST',f"devices/{device['number']}/intake/",{
|
||||
'hwid':hardware_id(report),'expected_revision':device['revision'],'specifications':map_fields(report)})
|
||||
if registration:
|
||||
device['_registration']=registration
|
||||
if action == 'intake' and report_path:
|
||||
raw=report_path.read_bytes(); sha=hashlib.sha256(raw).hexdigest()
|
||||
with contextlib.closing(sqlite3.connect(root/'database/intake.sqlite3')) as db, db:
|
||||
|
||||
Reference in New Issue
Block a user