def execute(command): data = request.json response, email = DB.validate_token(data) if response['errors']: return jsonify(response) if response['errors']: return jsonify(response) args = {**request.args, **BARRY_CONFIG, **DB.list_config(email)} try: message, details, action = execute_command(command, args) response['message'] = message response['details'] = details response['action'] = action except Exception as err: response['message'] = BARRY_CONFIG['default_response'] response['errors'].append(str(err)) if response['errors']: return jsonify(response) response['status'] = 'success' return jsonify(response)
def set_config(): data = request.json response, email = DB.validate_token(data) if response['errors']: return jsonify(response) args = request.args if 'key' not in args: response['errors'].append('Incorrect query. Missing argument "key"') if 'value' not in args: response['errors'].append('Incorrect query. Missing argument "value"') if response['errors']: return jsonify(response) try: DB.set_config(email, args['key'], args['value']) except Exception as err: response['errors'] if response['errors']: return jsonify(response) response['status'] = 'success' return jsonify(response)
def get_config(): data = request.json response, email = DB.validate_token(data) if response['errors']: return jsonify(response) args = request.args if 'key' not in args: response['errors'].append('Incorrect query. Missing argument "key"') if response['errors']: return jsonify(response) key = args['key'] try: response['user config'] = {key: DB.get_config(email, key)} except Exception as err: response['errors'].append(str(err)) if key in BARRY_CONFIG: response['default config'] = {key: BARRY_CONFIG[key]} else: response['errors'].append('No such key in default configs') if response['errors']: return jsonify(response) response['status'] = 'success' return jsonify(response)
def logout(): data = request.json response, email = DB.validate_token(data) if response['errors']: return jsonify(response) # TODO black lists? response['errors'].append('Not implemented') response['status'] = 'fail' return jsonify(response)
def list_config(): data = request.json response, email = DB.validate_token(data) if response['errors']: return jsonify(response) try: response['user config'] = DB.list_config(email) except Exception as err: response['errors'].append(str(err)) if response['errors']: return jsonify(response) response['default config'] = BARRY_CONFIG response['status'] = 'success' return jsonify(response)