From c98243d39b211b9b6006f78ad09d978c67be0986 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Wed, 5 May 2021 18:02:45 +0200 Subject: [PATCH] initial --- .gitignore | 6 ++++++ Entries.py | 20 ++++++++++++++++++++ openapi.yaml | 43 +++++++++++++++++++++++++++++++++++++++++++ server.py | 8 ++++++++ 4 files changed, 77 insertions(+) create mode 100644 .gitignore create mode 100644 Entries.py create mode 100644 openapi.yaml create mode 100644 server.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c55fa45 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +__pycache__ +*~ +.*.sw? +.*~ +ENV + diff --git a/Entries.py b/Entries.py new file mode 100644 index 0000000..722e9cf --- /dev/null +++ b/Entries.py @@ -0,0 +1,20 @@ +import _typeshed +import logging +import werkzeug +from flask import request +import json + +class Entry(object): + def __init__(self, ts, freq): + self.ts = ts + self.freq = freq + +def insert(**args): + try: + body = request.json + logging.info("JSON Body: {}".format(body)) + return "200" + except KeyError as e: + raise werkzeug.exceptions.InternalServerError("Key Error: {}".format(e)) + + diff --git a/openapi.yaml b/openapi.yaml new file mode 100644 index 0000000..111b787 --- /dev/null +++ b/openapi.yaml @@ -0,0 +1,43 @@ +openapi: 3.0.3 + +info: + title: SinkConvert2 + version: "0.0.1" + +paths: + /sc2/v1/entry: + post: + tags: [ "entry" ] + operationId: Entries.insert + summary: Insert one or more entries into the database + requestBody: + description: List of entries + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/entry" + responses: + 201: + description: One or more entries has been inserted + 401: + description: Unauthorized + 404: + description: Not found + +components: + schemas: + entry: + description: Entry with timestamp and frequency + type: object + properties: + timestamp: + description: Synchronized timestamp in RFC3339 format in timezone UTC + type: string + format: date-time + frequency: + description: Frequency in mHz + type: integer + + diff --git a/server.py b/server.py new file mode 100644 index 0000000..af309e0 --- /dev/null +++ b/server.py @@ -0,0 +1,8 @@ +import connexion +import logging + +logging.basicConfig(level=logging.INFO) + +app = connexion.App('SinkConvert2') +app.add_api('./openapi.yaml') +app.run(port=8080)