From b3f32eb8056fccec73d5b2889c240b5ddb62ad1b Mon Sep 17 00:00:00 2001 From: tkucherera Date: Fri, 6 Oct 2023 08:32:47 -0400 Subject: [PATCH] "firmware update on the server side" --- confluent_server/confluent/httpapi.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/confluent_server/confluent/httpapi.py b/confluent_server/confluent/httpapi.py index baf40606..2386d90d 100644 --- a/confluent_server/confluent/httpapi.py +++ b/confluent_server/confluent/httpapi.py @@ -888,6 +888,28 @@ def resourcehandler_backend(env, start_response): yield rsp return + elif (operation == 'create' and ('/firmware/updates/active' in env['PATH_INFO'])): + url = env['PATH_INFO'] + if 'application/json' in reqtype: + if not isinstance(reqbody, str): + reqbody = reqbody.decode('utf8') + pbody = json.loads(reqbody) + args = pbody['args'] + 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(url, operation, cfgmgr, args_dict) + for res in hdlr: + if isinstance(res, confluent.messages.CreatedResource): + watchurl = res.kvpairs['created'] + currnode = watchurl.split('/')[1] + nodeurls[currnode] = '/' + watchurl + yield json.dumps({'data': nodeurls}) + start_response('200 OK', headers) + return + elif (operation == 'create' and ('/staging' in env['PATH_INFO'])): url = env['PATH_INFO'] args_dict = {}