From 57572c777eec1846273f9418e1029568194ecf07 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Mon, 15 Apr 2024 19:07:37 +0200 Subject: [PATCH] add check for logtime parameter in http_system endpoint as first test to address issue #132 --- cbpi/__init__.py | 2 +- cbpi/http_endpoints/http_system.py | 50 ++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 92c0b96..77ce4f9 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.4.0" +__version__ = "4.4.1.a1" __codename__ = "Yeast Starter" diff --git a/cbpi/http_endpoints/http_system.py b/cbpi/http_endpoints/http_system.py index 8de8af2..39b43b0 100644 --- a/cbpi/http_endpoints/http_system.py +++ b/cbpi/http_endpoints/http_system.py @@ -165,31 +165,49 @@ class SystemHttpEndpoints: description: Zip and download craftbeerpi.service log tags: - System + parameters: + - name: "logtime" + in: "path" + description: "Logtime in hours" + required: true + type: "integer" + format: "int64" responses: "200": description: successful operation content: # Response body application/zip: # Media type """ - logtime = request.match_info['logtime'] - await self.controller.downloadlog(logtime) - filename = "cbpi4_log.zip" - file_name = pathlib.Path(os.path.join(".", filename)) + checklogtime = False + logtime = request.match_info['logtime'] + + try: + test=int(logtime) + checklogtime = True + except: + if logtime == "b": + checklogtime = True - response = web.StreamResponse( - status=200, - reason='OK', - headers={'Content-Type': 'application/zip'}, - ) - await response.prepare(request) - with open(file_name, 'rb') as file: - for line in file.readlines(): - await response.write(line) + if checklogtime: + await self.controller.downloadlog(logtime) + filename = "cbpi4_log.zip" + file_name = pathlib.Path(os.path.join(".", filename)) - await response.write_eof() - os.remove(file_name) - return response + response = web.StreamResponse( + status=200, + reason='OK', + headers={'Content-Type': 'application/zip'}, + ) + await response.prepare(request) + with open(file_name, 'rb') as file: + for line in file.readlines(): + await response.write(line) + await response.write_eof() + os.remove(file_name) + return response + else: + return web.Response(status=400, text='Need integer or "b" for logtime.') @request_mapping("/restore", method="POST", name="RestoreConfig", auth_required=False) async def restore(self, request):