changes
This commit is contained in:
		
							
								
								
									
										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
 | 
			
		||||
from flask import request, Response
 | 
			
		||||
import json
 | 
			
		||||
import datetime
 | 
			
		||||
 | 
			
		||||
class Entry(object):
 | 
			
		||||
    def __init__(self, d):
 | 
			
		||||
@@ -23,3 +24,13 @@ def insert(**args):
 | 
			
		||||
        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
 | 
			
		||||
        404:
 | 
			
		||||
          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:
 | 
			
		||||
  securitySchemes:
 | 
			
		||||
    jwt:
 | 
			
		||||
      type: http
 | 
			
		||||
      scheme: bearer
 | 
			
		||||
      bearerFormat: JWT
 | 
			
		||||
      x-bearerInfoFunc: Auth.decodeToken
 | 
			
		||||
  schemas:
 | 
			
		||||
    entry:
 | 
			
		||||
      description: Entry with timestamp and frequency
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user