def create_app(): """Set up the application.""" flask_app = Flask(__name__.split('.')[0]) local = CONFIG_BROKER['local'] flask_app.config.from_object(__name__) flask_app.config['LOCAL'] = local flask_app.debug = CONFIG_SERVICES['debug'] flask_app.config['SYSTEM_EMAIL'] = CONFIG_BROKER['reply_to_email'] # Future: Override config w/ environment variable, if set flask_app.config.from_envvar('BROKER_SETTINGS', silent=True) # Set parameters broker_file_path = CONFIG_BROKER['broker_files'] AccountHandler.FRONT_END = CONFIG_BROKER['full_url'] SesEmail.SIGNING_KEY = CONFIG_BROKER['email_token_key'] SesEmail.isLocal = local if SesEmail.isLocal: SesEmail.emailLog = os.path.join(broker_file_path, 'email.log') # If local, make the email directory if needed if local and not os.path.exists(broker_file_path): os.makedirs(broker_file_path) JsonResponse.debugMode = flask_app.debug if CONFIG_SERVICES['cross_origin_url'] == "*": CORS(flask_app, supports_credentials=False, allow_headers="*", expose_headers="X-Session-Id") else: CORS(flask_app, supports_credentials=False, origins=CONFIG_SERVICES['cross_origin_url'], allow_headers="*", expose_headers="X-Session-Id") # Enable DB session table handling flask_app.session_interface = UserSessionInterface() # Set up bcrypt bcrypt = Bcrypt(flask_app) @flask_app.teardown_appcontext def teardown_appcontext(exception): GlobalDB.close() @flask_app.before_request def before_request(): # Set global value for local g.is_local = local sess = GlobalDB.db().session # setup user g.user = None if session.get('name') is not None: g.user = sess.query(User).filter_by(user_id=session['name']).one_or_none() # Root will point to index.html @flask_app.route("/", methods=["GET"]) def root(): return "Broker is running" @flask_app.errorhandler(ResponseException) def handle_response_exception(exception): return JsonResponse.error(exception, exception.status) @flask_app.errorhandler(Exception) def handle_exception(exception): wrapped = ResponseException(str(exception), StatusCode.INTERNAL_ERROR, type(exception)) return JsonResponse.error(wrapped, wrapped.status) # Add routes for modules here add_login_routes(flask_app, bcrypt) add_file_routes(flask_app, CONFIG_BROKER['aws_create_temp_credentials'], local, broker_file_path) add_user_routes(flask_app, flask_app.config['SYSTEM_EMAIL'], bcrypt) add_domain_routes(flask_app) add_exception_handlers(flask_app) return flask_app
def create_app(): """Set up the application.""" flask_app = Flask(__name__.split('.')[0]) local = CONFIG_BROKER['local'] flask_app.config.from_object(__name__) flask_app.config['LOCAL'] = local flask_app.debug = CONFIG_SERVICES['debug'] flask_app.config['SYSTEM_EMAIL'] = CONFIG_BROKER['reply_to_email'] # Future: Override config w/ environment variable, if set flask_app.config.from_envvar('BROKER_SETTINGS', silent=True) # Set parameters broker_file_path = CONFIG_BROKER['broker_files'] AccountHandler.FRONT_END = CONFIG_BROKER['full_url'] SesEmail.SIGNING_KEY = CONFIG_BROKER['email_token_key'] SesEmail.isLocal = local if SesEmail.isLocal: SesEmail.emailLog = os.path.join(broker_file_path, 'email.log') # If local, make the email directory if needed if local and not os.path.exists(broker_file_path): os.makedirs(broker_file_path) JsonResponse.debugMode = flask_app.debug if CONFIG_SERVICES['cross_origin_url'] == "*": CORS(flask_app, supports_credentials=False, allow_headers="*", expose_headers="X-Session-Id") else: CORS(flask_app, supports_credentials=False, origins=CONFIG_SERVICES['cross_origin_url'], allow_headers="*", expose_headers="X-Session-Id") # Enable DB session table handling flask_app.session_interface = UserSessionInterface() # Set up bcrypt bcrypt = Bcrypt(flask_app) @flask_app.teardown_appcontext def teardown_appcontext(exception): GlobalDB.close() @flask_app.before_request def before_request(): # Set global value for local g.is_local = local sess = GlobalDB.db().session # setup user g.user = None if session.get('name') is not None: g.user = sess.query(User).filter_by( user_id=session['name']).one_or_none() # Root will point to index.html @flask_app.route("/", methods=["GET"]) def root(): return "Broker is running" @flask_app.errorhandler(ResponseException) def handle_response_exception(exception): return JsonResponse.error(exception, exception.status) @flask_app.errorhandler(Exception) def handle_exception(exception): wrapped = ResponseException(str(exception), StatusCode.INTERNAL_ERROR, type(exception)) return JsonResponse.error(wrapped, wrapped.status) # Add routes for modules here add_login_routes(flask_app, bcrypt) add_file_routes(flask_app, CONFIG_BROKER['aws_create_temp_credentials'], local, broker_file_path) add_user_routes(flask_app, flask_app.config['SYSTEM_EMAIL'], bcrypt) add_domain_routes(flask_app) add_exception_handlers(flask_app) return flask_app
def createApp(): """Set up the application.""" try : # Create application app = Flask(__name__, instance_path=CONFIG_PATH) local = CONFIG_BROKER['local'] app.config.from_object(__name__) app.config['LOCAL'] = local app.config['REST_TRACE'] = CONFIG_SERVICES['rest_trace'] app.config['SYSTEM_EMAIL'] = CONFIG_BROKER['reply_to_email'] # Future: Override config w/ environment variable, if set app.config.from_envvar('BROKER_SETTINGS', silent=True) # Set parameters broker_file_path = CONFIG_BROKER['broker_files'] AccountHandler.FRONT_END = CONFIG_BROKER['full_url'] sesEmail.SIGNING_KEY = CONFIG_BROKER['email_token_key'] sesEmail.isLocal = local if sesEmail.isLocal: sesEmail.emailLog = os.path.join(broker_file_path, 'email.log') # If local, make the email directory if needed if local and not os.path.exists(broker_file_path): os.makedirs(broker_file_path) # When runlocal is true, assume Dynamo is on the same server # (should be false for prod) JsonResponse.debugMode = app.config['REST_TRACE'] if CONFIG_SERVICES['cross_origin_url'] == "*": cors = CORS(app, supports_credentials=True, allow_headers = "*", expose_headers = "X-Session-Id") else: cors = CORS(app, supports_credentials=True, origins=CONFIG_SERVICES['cross_origin_url'], allow_headers = "*", expose_headers = "X-Session-Id") # Enable AWS Sessions app.session_interface = DynamoInterface() # Set up bcrypt bcrypt = Bcrypt(app) # Root will point to index.html @app.route("/", methods=["GET"]) def root(): return "Broker is running" if local: localFiles = os.path.join(broker_file_path, "<path:filename>") # Only define this route when running locally @app.route(localFiles) def sendFile(filename): if(config["local"]) : return send_from_directory(broker_file_path, filename) else: # For non-local installs, set Dynamo Region SessionTable.DYNAMO_REGION = CONFIG_BROKER['aws_region'] # Add routes for modules here add_login_routes(app, bcrypt) add_file_routes(app, CONFIG_BROKER['aws_create_temp_credentials'], local, broker_file_path, bcrypt) add_user_routes(app, app.config['SYSTEM_EMAIL'], bcrypt) add_domain_routes(app, local, bcrypt) SessionTable.LOCAL_PORT = CONFIG_DB['dynamo_port'] SessionTable.setup(app, local) if local: checkDynamo() return app except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() trace = traceback.extract_tb(exc_tb, 10) CloudLogger.logError('Broker App Level Error: ', e, trace) del exc_tb raise
def domain_app(test_app): domainRoutes.add_domain_routes(test_app.application) yield test_app
def createApp(): """Set up the application.""" app = Flask(__name__.split('.')[0]) local = CONFIG_BROKER['local'] app.config.from_object(__name__) app.config['LOCAL'] = local app.debug = CONFIG_SERVICES['server_debug'] app.config['REST_TRACE'] = CONFIG_SERVICES['rest_trace'] app.config['SYSTEM_EMAIL'] = CONFIG_BROKER['reply_to_email'] # Future: Override config w/ environment variable, if set app.config.from_envvar('BROKER_SETTINGS', silent=True) # Set parameters broker_file_path = CONFIG_BROKER['broker_files'] AccountHandler.FRONT_END = CONFIG_BROKER['full_url'] sesEmail.SIGNING_KEY = CONFIG_BROKER['email_token_key'] sesEmail.isLocal = local if sesEmail.isLocal: sesEmail.emailLog = os.path.join(broker_file_path, 'email.log') # If local, make the email directory if needed if local and not os.path.exists(broker_file_path): os.makedirs(broker_file_path) # When runlocal is true, assume Dynamo is on the same server # (should be false for prod) JsonResponse.debugMode = app.config['REST_TRACE'] if CONFIG_SERVICES['cross_origin_url'] == "*": cors = CORS(app, supports_credentials=False, allow_headers = "*", expose_headers = "X-Session-Id") else: cors = CORS(app, supports_credentials=False, origins=CONFIG_SERVICES['cross_origin_url'], allow_headers = "*", expose_headers = "X-Session-Id") # Enable AWS Sessions app.session_interface = DynamoInterface() # Set up bcrypt bcrypt = Bcrypt(app) @app.teardown_appcontext def teardown_appcontext(exception): GlobalDB.close() @app.before_request def before_request(): GlobalDB.db() # Root will point to index.html @app.route("/", methods=["GET"]) def root(): return "Broker is running" # Add routes for modules here add_login_routes(app, bcrypt) add_file_routes(app, CONFIG_BROKER['aws_create_temp_credentials'], local, broker_file_path, bcrypt) add_user_routes(app, app.config['SYSTEM_EMAIL'], bcrypt) add_domain_routes(app, local, bcrypt) SessionTable.LOCAL_PORT = CONFIG_DB['dynamo_port'] SessionTable.setup(app, local) if local: checkDynamo() else: SessionTable.DYNAMO_REGION = CONFIG_BROKER['aws_region'] return app