changes
This commit is contained in:
parent
8c008bbb8e
commit
d8dcfd3e8e
13
Auth.py
Normal file
13
Auth.py
Normal 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()
|
11
Entries.py
11
Entries.py
@ -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
|
48
openapi.yaml
48
openapi.yaml
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user