This commit is contained in:
Wolfgang Hottgenroth 2021-05-06 17:19:08 +02:00
parent 8c008bbb8e
commit d8dcfd3e8e
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F
3 changed files with 72 additions and 0 deletions

13
Auth.py Normal file
View File

@ -0,0 +1,13 @@
from jose import JWTError, jwt
import os
import werkzeug
JWT_SECRET = os.environ['JWT_SECRET']
def decodeToken(token):
try:
return jwt.decode(token, JWT_SECRET)
except JWTError as e:
print("ERROR: decodeToken: {}".format(e))
raise werkzeug.exceptions.Unauthorized()

View File

@ -2,6 +2,7 @@ import logging
import werkzeug import werkzeug
from flask import request, Response from flask import request, Response
import json import json
import datetime
class Entry(object): class Entry(object):
def __init__(self, d): def __init__(self, d):
@ -23,3 +24,13 @@ def insert(**args):
raise werkzeug.exceptions.InternalServerError("Key Error: {}".format(e)) raise werkzeug.exceptions.InternalServerError("Key Error: {}".format(e))
def get(start, stop, token_info=None, location=None):
if 'read/mainscnt/entries' not in token_info['x-scope']:
raise werkzeug.exceptions.Forbidden()
res = [
{
'timestamp': datetime.datetime.now(),
'frequency': 50.0
}
]
return res

View File

@ -25,8 +25,56 @@ paths:
description: Unauthorized description: Unauthorized
404: 404:
description: Not found description: Not found
/sc2/v1/entries:
get:
tags: [ "entry" ]
operationId: Entries.get
summary: Get entries from the database using a defined filter
parameters:
- name: start
in: query
required: true
schema:
type: string
format: date-time
- name: stop
in: query
required: true
schema:
type: string
format: date-time
- name: location
in: query
required: false
schema:
type: string
responses:
200:
description: List on selected entries
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/entry"
401:
description: Unauthorized
403:
description: Access denied
404:
description: Not found
security:
- jwt: ['secret']
components: components:
securitySchemes:
jwt:
type: http
scheme: bearer
bearerFormat: JWT
x-bearerInfoFunc: Auth.decodeToken
schemas: schemas:
entry: entry:
description: Entry with timestamp and frequency description: Entry with timestamp and frequency