# API Authentication and Authorization auth_api = api.namespace('auth', description='Authentication') login_api_schema = api.schema('auth.login', { 'type': 'object', 'properties': { 'username': {'type': 'string'}, 'password': {'type': 'string'} }, 'required': ['username', 'password'], 'additionalProperties': False }) login_parser = api.parser() login_parser.add_argument('remember', type=inputs.boolean, required=False, default=False, help='Remember login (sets persistent session cookies)') @auth_api.route('/login/') class LoginAPI(APIResource): @api.validate(login_api_schema, description='Username and Password') @api.response(Unauthorized) @api.response(200, 'Login successful', model=base_message_schema) @api.doc(parser=login_parser) def post(self, session=None): """ Login with username and password """ data = request.json user_name = data.get('username') password = data.get('password')
args = tasks_parser.parse_args() include_execution = args.get('include_execution') st_task = task.to_dict() if include_execution: execution = task.executions.order_by( db.TaskExecution.start.desc()).first() st_task['last_execution'] = execution.to_dict( ) if execution else {} return jsonify(st_task) default_start_date = (datetime.now() - timedelta(weeks=1)).strftime('%Y-%m-%d') executions_parser = api.parser() executions_parser.add_argument('succeeded', type=inputs.boolean, default=True, help='Filter by success status') executions_parser.add_argument( 'produced', type=inputs.boolean, default=True, store_missing=False, help='Filter by tasks that produced entries', ) executions_parser.add_argument( 'start_date', type=inputs.datetime_from_iso8601, default=default_start_date,
except NoResultFound: raise NotFoundError('task status with id %d not found' % task_id) args = tasks_parser.parse_args() include_execution = args.get('include_execution') st_task = task.to_dict() if include_execution: execution = task.executions.order_by(TaskExecution.start.desc()).first() st_task['last_execution'] = execution.to_dict() if execution else {} return jsonify(st_task) default_start_date = (datetime.now() - timedelta(weeks=1)).strftime('%Y-%m-%d') executions_parser = api.parser() executions_parser.add_argument('succeeded', type=inputs.boolean, default=True, help='Filter by success status') executions_parser.add_argument('produced', type=inputs.boolean, default=True, store_missing=False, help='Filter by tasks that produced entries') executions_parser.add_argument('start_date', type=inputs.datetime_from_iso8601, default=default_start_date, help='Filter by minimal start date. Example: \'2012-01-01\'. Default is 1 week ago.') executions_parser.add_argument('end_date', type=inputs.datetime_from_iso8601, help='Filter by maximal end date. Example: \'2012-01-01\'') sort_choices = ('start', 'end', 'succeeded', 'produced', 'accepted', 'rejected', 'failed', 'abort_reason') executions_parser = api.pagination_parser(executions_parser, sort_choices=sort_choices) @tasks_api.route('/status/<int:task_id>/executions/') @status_api.route('/<int:task_id>/executions/') @api.doc(parser=executions_parser, params={'task_id': 'ID of the status task'})