2
0
mirror of https://github.com/xcat2/confluent.git synced 2026-05-01 04:47:45 +00:00

Correct firmware update through http api

This commit is contained in:
Jarrod Johnson
2026-04-28 15:33:18 -04:00
parent 6421097f32
commit 16c99efda7
2 changed files with 12 additions and 13 deletions

View File

@@ -1559,6 +1559,6 @@ async def handle_path(path, operation, configmanager, inputdata=None, autostrip=
return handle_discovery(pathcomponents[1:], operation, configmanager,
inputdata)
elif pathcomponents[0] == 'staging':
return await handle_staging(pathcomponents, operation, configmanager, inputdata)
return handle_staging(pathcomponents, operation, configmanager, inputdata)
else:
raise exc.NotFoundException()

View File

@@ -942,18 +942,17 @@ async def resourcehandler_backend(req, make_response):
file_directory = '/var/lib/confluent/client_assets/{}'.format(args.split('/')[-1])
filepath = '{0}/{1}'.format(file_directory, os.listdir(file_directory)[0]) # TODO find a way to validate that the file is found and its the expected one
args_dict = {'filename': filepath}
noderrs = {}
nodeurls = {}
hdlr = pluginapi.handle_path(reqpath, operation, cfgmgr, args_dict)
for res in hdlr:
async for res in pluginapi.iterate_responses(hdlr):
if isinstance(res, confluent.messages.CreatedResource):
watchurl = res.kvpairs['created']
currnode = watchurl.split('/')[1]
nodeurls[currnode] = '/' + watchurl
rsp = await make_response(mimetype, 200, 'OK')
await rsp.write(json.dumps({'data': nodeurls}))
return
await rsp.write(json.dumps({'data': nodeurls}).encode('utf8'))
return rsp
elif (operation == 'create' and ('/staging' in reqpath)):
url = reqpath
args_dict = {}
@@ -963,17 +962,17 @@ async def resourcehandler_backend(req, make_response):
if authorized['username'] == url.split('/')[2]:
args_dict.update({'filedata':req.content, 'content_length': content_length}) # TODO: replace env
hdlr = pluginapi.handle_path(url, operation, cfgmgr, args_dict)
for resp in hdlr:
async for resp in pluginapi.iterate_responses(hdlr):
if isinstance(resp, confluent.messages.FileUploadProgress):
if resp.kvpairs['progress']['value'] == 100:
progress = resp.kvpairs['progress']['value']
rsp = await make_response(mimetype, 200, 'OK')
await rsp.write(json.dumps({'data': 'done'}))
return
await rsp.write(json.dumps({'data': 'done'}).encode('utf8'))
return rsp
else:
rsp = await make_response(mimetype, 401, 'Unauthorized')
await rsp.write(json.dumps({'data': 'You do not have permission to write to file'}))
return
await rsp.write(json.dumps({'data': 'You do not have permission to write to file'}).encode('utf8'))
return rsp
elif len(url.split('/')) == 2:
reqbody = await req.read()
reqtype = req.content_type
@@ -987,12 +986,12 @@ async def resourcehandler_backend(req, make_response):
except KeyError:
pass
hdlr = pluginapi.handle_path(url, operation, cfgmgr, args_dict)
for res in hdlr:
async for res in pluginapi.iterate_responses(hdlr):
if isinstance(res, confluent.messages.CreatedResource):
stageurl = res.kvpairs['created']
rsp = await make_response(mimetype, 200, 'OK')
await rsp.write(json.dumps({'data': stageurl}))
return
await rsp.write(json.dumps({'data': stageurl}).encode('utf8'))
return rsp
else:
# normal request
url = reqpath