From 30efc95462142a8520bc91b548fddb98cd7b49b6 Mon Sep 17 00:00:00 2001 From: manuel83 Date: Mon, 5 Aug 2019 23:15:14 +0200 Subject: [PATCH] log http endpoint swagger doc added --- .idea/workspace.xml | 121 ++++++++++++------------- cbpi/controller/log_file_controller.py | 3 +- cbpi/http_endpoints/http_log.py | 120 +++++++++++++++++++++++- 3 files changed, 178 insertions(+), 66 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 51835e2..1ae6ef1 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,17 +2,8 @@ - - - - - - - - - - + - @@ -1314,22 +1308,6 @@ - - - - - - - - - - - - - - - - @@ -1348,13 +1326,6 @@ - - - - - - - @@ -1389,19 +1360,43 @@ - + - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1410,8 +1405,8 @@ - - + + @@ -1420,8 +1415,8 @@ - - + + diff --git a/cbpi/controller/log_file_controller.py b/cbpi/controller/log_file_controller.py index 831e816..e5cc10c 100644 --- a/cbpi/controller/log_file_controller.py +++ b/cbpi/controller/log_file_controller.py @@ -155,7 +155,6 @@ class LogController: for f in all_filenames: zip.write(os.path.join(f)) zip.close() - - return file_name + return os.path.basename(file_name) diff --git a/cbpi/http_endpoints/http_log.py b/cbpi/http_endpoints/http_log.py index c6b8a70..6ab4588 100644 --- a/cbpi/http_endpoints/http_log.py +++ b/cbpi/http_endpoints/http_log.py @@ -10,19 +10,71 @@ class LogHttpEndpoints: @request_mapping(path="/{name}/zip", method="POST", auth_required=False) async def create_zip_names(self, request): + """ + --- + description: Zip Log files for sensor + tags: + - Log + parameters: + - name: "name" + in: "path" + description: "Sensor ID" + required: true + type: "integer" + format: "int64" + produces: + - application/json + responses: + "204": + description: successful operation. Return "pong" text + """ + log_name = request.match_info['name'] data = self.cbpi.log.zip_log_data(log_name) - print(data) + return web.json_response(dict(filename=data), dumps=json_dumps) @request_mapping(path="/{name}/zip", method="DELETE", auth_required=False) async def clear_zip_names(self, request): + """ + --- + description: Delete all zip files for sensor + tags: + - Log + parameters: + - name: "name" + in: "path" + description: "Sensor ID" + required: true + type: "integer" + format: "int64" + responses: + "204": + description: successful operation. + """ log_name = request.match_info['name'] self.cbpi.log.clear_zip(log_name) return web.Response(status=204) @request_mapping(path="/zip/download/{name}", method="GET", auth_required=False) async def download_zip(self, request): + """ + --- + description: Download a sensor zip file + tags: + - Log + parameters: + - name: "name" + in: "path" + description: "Zip File name" + required: true + type: "integer" + format: "int64" + responses: + "204": + description: successful operation. + """ + response = web.StreamResponse( status=200, reason='OK', @@ -39,12 +91,49 @@ class LogHttpEndpoints: @request_mapping(path="/{name}/zip", method="GET", auth_required=False) async def get_zip_names(self, request): + """ + --- + description: Zip available zip file names for sensor + tags: + - Log + parameters: + - name: "name" + in: "path" + description: "Sensor ID" + required: true + type: "integer" + format: "int64" + produces: + - application/json + responses: + "200": + description: successful operation. + """ log_name = request.match_info['name'] data = self.cbpi.log.get_all_zip_file_names(log_name) return web.json_response(data, dumps=json_dumps) @request_mapping(path="/{name}/files", method="GET", auth_required=False) async def get_file_names(self, request): + """ + --- + description: Available log file names for sensor + tags: + - Log + parameters: + + - name: "name" + in: "path" + description: "Sensor ID" + required: true + type: "integer" + format: "int64" + produces: + - application/json + responses: + "200": + description: successful operation. + """ log_name = request.match_info['name'] print(log_name) data = self.cbpi.log.get_logfile_names(log_name) @@ -52,12 +141,41 @@ class LogHttpEndpoints: @request_mapping(path="/{name}", method="GET", auth_required=False) async def delete_log(self, request): + """ + --- + description: Get log data for sensor + tags: + - Log + parameters: + - name: "name" + in: "path" + description: "Sensor ID" + required: true + type: "integer" + format: "int64" + produces: + - application/json + responses: + "200": + description: successful operation. + """ log_name = request.match_info['name'] data = await self.cbpi.log.get_data(log_name) return web.json_response(data, dumps=json_dumps) @request_mapping(path="/{name}", method="DELETE", auth_required=False) async def delete_all_logs(self, request): + """ + --- + description: Get log data for sensor + tags: + - Log + parameters: + + responses: + "204": + description: successful operation. + """ log_name = request.match_info['name'] await self.cbpi.log.clear_logs(log_name) return web.Response(status=204) \ No newline at end of file