working on control
This commit is contained in:
@@ -33,6 +33,8 @@ api_virtual_command = Namespace('virtual_command', description="Virtual command
|
||||
authorizations=api_authorizations)
|
||||
api_cron_job = Namespace('cron_job', description="Cron job namespace",
|
||||
authorizations=api_authorizations)
|
||||
api_control = Namespace('control', description="Control namespace",
|
||||
authorizations=api_authorizations)
|
||||
|
||||
api_v1.add_namespace(api_user)
|
||||
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_virtual_command)
|
||||
api_v1.add_namespace(api_cron_job)
|
||||
api_v1.add_namespace(api_control)
|
||||
|
||||
auth_api_bp = Blueprint('auth_api', __name__, url_prefix='/api/auth')
|
||||
# user_api_bp = Blueprint('user_api', __name__, url_prefix='/api/user')
|
||||
@@ -51,6 +54,8 @@ from .user_api import *
|
||||
from .group_api import *
|
||||
from .room_api import *
|
||||
from .recorder_api import *
|
||||
from .control_api import *
|
||||
from .virtual_command_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'),
|
||||
'description': fields.String(required=False, description='The recorder\'s description'),
|
||||
|
||||
'parent_virtual_command': fields.Nested('virtual_command_model',
|
||||
required=False,
|
||||
allow_null=True,
|
||||
skip_none=False,
|
||||
description='Parent virtual command.'),
|
||||
'parent_virtual_command': fields.Nested(api_virtual_command.model('VirtualCommandParent',
|
||||
{
|
||||
'id': fields.String(required=False,
|
||||
description='The recorder\'s identifier'),
|
||||
'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',
|
||||
{'id': fields.Integer(), 'name': fields.String(),
|
||||
'number': fields.String(), 'alternate_name': fields.String()}),
|
||||
|
||||
Reference in New Issue
Block a user