from flask_caching import Cache from flask_login import LoginManager from flask_migrate import Migrate from flask_sqlalchemy import SQLAlchemy from flask_wtf.csrf import CSRFProtect from flask_oauthlib.provider import OAuth2Provider from flask_jsonschema import JsonSchema from flask_gravatar import Gravatar from flask_mail import Mail from flask_babel import Babel from flask_jsglue import JSGlue bcrypt = Bcrypt() csrf_protect = CSRFProtect() login_manager = LoginManager() db = SQLAlchemy() migrate = Migrate() cache = Cache() oauth = OAuth2Provider() json_schema = JsonSchema() gravatar = Gravatar(size=300, rating='g', default='retro', use_ssl=True) mail = Mail() babel = Babel() jsglue = JSGlue() try: from flask_debugtoolbar import DebugToolbarExtension debug_toolbar = DebugToolbarExtension() except ImportError: debug_toolbar = None
from flasgger import Swagger,swag_from import bcrypt import database as db app = Flask(__name__, static_url_path="") #swagger documentation app.config['SWAGGER'] = { 'title': 'Testomania API', 'description': 'API for a quiz site' } swagger = Swagger(app) #json schema validation app.config['JSONSCHEMA_DIR'] = os.path.join(app.root_path, 'schemas') jsonschema = JsonSchema(app) #allow for connections from other domains CORS(app) @app.errorhandler(ValidationError) def on_validation_error(e): return make_response(jsonify({'error': 'Bad request'}),400) @app.errorhandler(400) def bad_request(error): return make_response(jsonify({'error': 'Bad request'}),400) @app.errorhandler(404) def not_found(error):
from flask_tinyclients.vxstream import VxStream from flask_tinyclients.fireeye import FireEye from app.core import FlaskApi, ApiException from app.utils import JSONEncoder from .utils.mixins import Anonymous version_ = (1, 8, 0) __version__ = '.'.join(map(str, version_[0:2])) __release__ = '.'.join(map(str, version_)) db = SQLAlchemy() mail = Mail() login_manager = LoginManager() celery = Celery(__name__, broker=Config.BROKER_URL) jsonschema = JsonSchema() gpg = GPG() ldap3_manager = LDAP3LoginManager() migrate = Migrate() vxstream = VxStream() nessus = Nessus() fireeye = FireEye() def create_app(config_name): app = FlaskApi(__name__) app.config.from_object(config[config_name]) if app.config['TESTING']: app.config.from_envvar('DO_TESTING_CONFIG', silent=True) else: app.config.from_envvar('DO_LOCAL_CONFIG', silent=True)
""" App register section """ APP = Flask(__name__) config_logs(APP) """ Cors middeware """ CORS(APP) """ JsonSchema configuration """ DIR_PATH = os.path.dirname(os.path.realpath(__file__)) APP.config['JSONSCHEMA_DIR'] = DIR_PATH + '/../schemas' JSON_SCHEMA = JsonSchema(APP) """ Patch section """ WSGIRequestHandler.log = werk_log """ Functions that returns configuration objects """ def get_app(): return APP def get_jsonschema(): return JSON_SCHEMA