Example #1
0
def setupSessionTable():
    SessionTable.createTable(CONFIG_BROKER['local'], CONFIG_DB['dynamo_port'])
def setup_session_table():
    """Create Dynamo session table."""
    logger.info('Setting up DynamoDB session table')
    SessionTable.createTable(CONFIG_BROKER['local'], CONFIG_DB['dynamo_port'])
def setupSessionTable():
    """ Create Dynamo session table """
    SessionTable.createTable(CONFIG_BROKER['local'], CONFIG_DB['dynamo_port'])
def setupSessionTable():
    """ Create Dynamo session table """
    SessionTable.createTable(CONFIG_BROKER['local'], CONFIG_DB['dynamo_port'])
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)
        else:
            cors = CORS(app,
                        supports_credentials=True,
                        origins=CONFIG_SERVICES['cross_origin_url'])
        # 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)
        add_user_routes(app, app.config['SYSTEM_EMAIL'], bcrypt)

        SessionTable.LOCAL_PORT = CONFIG_DB['dynamo_port']

        SessionTable.setup(app, local)

        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 setupSessionTable():
    SessionTable.createTable(CONFIG_BROKER['local'], CONFIG_DB['dynamo_port'])
Example #7
0
def checkDynamo():
    """ Get information about the session table in Dynamo """
    SessionTable.getTable().describe()
Example #8
0
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