working on control
This commit is contained in:
@@ -33,6 +33,8 @@ api_virtual_command = Namespace('virtual_command', description="Virtual command
|
|||||||
authorizations=api_authorizations)
|
authorizations=api_authorizations)
|
||||||
api_cron_job = Namespace('cron_job', description="Cron job namespace",
|
api_cron_job = Namespace('cron_job', description="Cron job namespace",
|
||||||
authorizations=api_authorizations)
|
authorizations=api_authorizations)
|
||||||
|
api_control = Namespace('control', description="Control namespace",
|
||||||
|
authorizations=api_authorizations)
|
||||||
|
|
||||||
api_v1.add_namespace(api_user)
|
api_v1.add_namespace(api_user)
|
||||||
api_v1.add_namespace(api_group)
|
api_v1.add_namespace(api_group)
|
||||||
@@ -40,6 +42,7 @@ api_v1.add_namespace(api_room)
|
|||||||
api_v1.add_namespace(api_recorder)
|
api_v1.add_namespace(api_recorder)
|
||||||
api_v1.add_namespace(api_virtual_command)
|
api_v1.add_namespace(api_virtual_command)
|
||||||
api_v1.add_namespace(api_cron_job)
|
api_v1.add_namespace(api_cron_job)
|
||||||
|
api_v1.add_namespace(api_control)
|
||||||
|
|
||||||
auth_api_bp = Blueprint('auth_api', __name__, url_prefix='/api/auth')
|
auth_api_bp = Blueprint('auth_api', __name__, url_prefix='/api/auth')
|
||||||
# user_api_bp = Blueprint('user_api', __name__, url_prefix='/api/user')
|
# user_api_bp = Blueprint('user_api', __name__, url_prefix='/api/user')
|
||||||
@@ -51,6 +54,8 @@ from .user_api import *
|
|||||||
from .group_api import *
|
from .group_api import *
|
||||||
from .room_api import *
|
from .room_api import *
|
||||||
from .recorder_api import *
|
from .recorder_api import *
|
||||||
|
from .control_api import *
|
||||||
|
from .virtual_command_api import *
|
||||||
|
|
||||||
|
|
||||||
# from .group_api import *
|
# from .group_api import *
|
||||||
|
|||||||
40
api/control_api.py
Normal file
40
api/control_api.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# Copyright (c) 2019. Tobias Kurze
|
||||||
|
"""
|
||||||
|
This module provides functions related to authentication through the API.
|
||||||
|
For example: listing of available auth providers or registration of users.
|
||||||
|
|
||||||
|
Login through API does not start a new session, but instead returns JWT.
|
||||||
|
"""
|
||||||
|
import json
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from flask_jwt_extended import jwt_required
|
||||||
|
from flask_restplus import fields, Resource
|
||||||
|
|
||||||
|
from backend import db
|
||||||
|
from backend.api import api_control, get_jwt_identity
|
||||||
|
|
||||||
|
control_command_response_model = api_control.model('Control Command Response', {
|
||||||
|
'time': fields.DateTime(required=False, description='Creation date of the recorder'),
|
||||||
|
'state': fields.String(min_length=3, required=True, description='The recorder\'s name'),
|
||||||
|
'output': fields.String(required=False, description='The recorder\'s description'),
|
||||||
|
'error': fields.String(required=False, description='The recorder\'s description'),
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@api_control.route('')
|
||||||
|
class ControlCommand(Resource):
|
||||||
|
control_command_parser = api_control.parser()
|
||||||
|
control_command_parser.add_argument('recorder_id', type=int, default=1, required=True)
|
||||||
|
control_command_parser.add_argument('command_id', type=int, default=1, required=True)
|
||||||
|
control_command_parser.add_argument('parameters', default=json.dumps({'p1': 'v1'}), type=dict, required=False,
|
||||||
|
location='json')
|
||||||
|
|
||||||
|
@jwt_required
|
||||||
|
@api_control.doc('run_command')
|
||||||
|
@api_control.expect(control_command_parser)
|
||||||
|
@api_control.marshal_with(control_command_response_model, skip_none=False, code=201)
|
||||||
|
def post(self):
|
||||||
|
current_user = {'identity': get_jwt_identity(), 'type': type(get_jwt_identity())}
|
||||||
|
args = self.control_command_parser.parse_args()
|
||||||
|
return {'time': datetime.utcnow(), 'output': args, 'state': current_user}
|
||||||
@@ -24,11 +24,18 @@ virtual_command_model = api_virtual_command.model('VirtualCommand', {
|
|||||||
'name': fields.String(min_length=3, required=True, description='The recorder\'s name'),
|
'name': fields.String(min_length=3, required=True, description='The recorder\'s name'),
|
||||||
'description': fields.String(required=False, description='The recorder\'s description'),
|
'description': fields.String(required=False, description='The recorder\'s description'),
|
||||||
|
|
||||||
'parent_virtual_command': fields.Nested('virtual_command_model',
|
'parent_virtual_command': fields.Nested(api_virtual_command.model('VirtualCommandParent',
|
||||||
required=False,
|
{
|
||||||
allow_null=True,
|
'id': fields.String(required=False,
|
||||||
skip_none=False,
|
description='The recorder\'s identifier'),
|
||||||
description='Parent virtual command.'),
|
'name': fields.String(min_length=3,
|
||||||
|
required=True,
|
||||||
|
description='The recorder\'s name'),
|
||||||
|
},
|
||||||
|
required=False,
|
||||||
|
allow_null=True,
|
||||||
|
skip_none=False,
|
||||||
|
description='Parent virtual command.')),
|
||||||
'room': fields.Nested(api_virtual_command.model('recorder_room',
|
'room': fields.Nested(api_virtual_command.model('recorder_room',
|
||||||
{'id': fields.Integer(), 'name': fields.String(),
|
{'id': fields.Integer(), 'name': fields.String(),
|
||||||
'number': fields.String(), 'alternate_name': fields.String()}),
|
'number': fields.String(), 'alternate_name': fields.String()}),
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ def has_no_empty_params(rule):
|
|||||||
|
|
||||||
@fe_bp.route("/site-map")
|
@fe_bp.route("/site-map")
|
||||||
def site_map():
|
def site_map():
|
||||||
|
print("# serving site-map!!")
|
||||||
links = []
|
links = []
|
||||||
for rule in app.url_map.iter_rules():
|
for rule in app.url_map.iter_rules():
|
||||||
# Filter out rules we can't navigate to in a browser
|
# Filter out rules we can't navigate to in a browser
|
||||||
|
|||||||
Reference in New Issue
Block a user