Exemplo n.º 1
0
def is_server_running(port):
    pid = daemonize.is_server_running(port)
    if pid is not None:
        logger.warning(f"Faraday Server is already running. PID: {pid}")
        return True
    else:
        return False
Exemplo n.º 2
0
def check_alembic_version():
    config = Config()
    config.set_main_option("script_location", "migrations")
    script = ScriptDirectory.from_config(config)

    head_revision = script.get_current_head()
    with get_app().app_context():
        try:
            conn = db.session.connection()
        except ImportError:
            if not faraday.server.config.database.connection_string:
                print("\n\nNo database configuration found. Did you execute \"faraday-manage initdb\"? \n\n")
                sys.exit(1)
        except sqlalchemy.exc.OperationalError:
            print("Bad Credentials, please check the .faraday/config/server.ini")
            sys.exit(1)

        context = MigrationContext.configure(conn)

        current_revision = context.get_current_revision()
        if head_revision != current_revision:
            version_path = faraday.server.config.FARADAY_BASE / 'migrations'\
                           / 'versions'
            if list(version_path.glob(f'{current_revision}_*.py')):
                print('--' * 20)
                print('Missing migrations, please execute: \n\n')
                print('faraday-manage migrate')
                sys.exit(1)
            else:
                logger.warning(
                    "You are using an unknown schema version. If you are a "
                    "developer, this probably happened because you used branch "
                    "with a schema migration not merged yet. If you are a "
                    "normal user, consider reporting this bug back to us"
                    )
Exemplo n.º 3
0
def check_alembic_version():
    config = Config()
    config.set_main_option("script_location", "migrations")
    script = ScriptDirectory.from_config(config)

    head_revision = script.get_current_head()
    with app.app_context():
        try:
            conn = db.session.connection()
        except ImportError as ex:
            if not faraday.server.config.database.connection_string:
                print(
                    "\n\nNo database configuration found. Did you execute \"faraday-manage initdb\"? \n\n"
                )
                sys.exit(1)

        context = MigrationContext.configure(conn)

        current_revision = context.get_current_revision()
        if head_revision != current_revision:
            if glob.glob(
                    os.path.join(FARADAY_BASE, 'migrations', 'versions',
                                 '{}_*.py'.format(current_revision))):
                print('--' * 20)
                print('Missing migrations, please execute: \n\n')
                print('faraday-manage migrate')
                sys.exit(1)
            else:
                logger.warning(
                    "You are using an unknown schema version. If you are a "
                    "developer, this probably happened because you used branch "
                    "with a schema migration not merged yet. If you are a "
                    "normal user, consider reporting this bug back to us")
Exemplo n.º 4
0
def check_postgresql():
    with get_app().app_context():
        try:
            if not db.session.query(Workspace).count():
                logger.warning('No workspaces found')
        except sqlalchemy.exc.ArgumentError:
            logger.error(
                f'\n{Fore.RED}Please check your PostgreSQL connection string in the file ~/.faraday/config/server.ini on your home directory.{Fore.WHITE} \n'
            )
            sys.exit(1)
        except sqlalchemy.exc.OperationalError:
            logger.error(
                    '\n\n{RED}Could not connect to PostgreSQL.\n{WHITE}Please check: \n{YELLOW}  * if database is running \n  * configuration settings are correct. \n\n{WHITE}For first time installations execute{WHITE}: \n\n {GREEN} faraday-manage initdb\n\n'.format(GREEN=Fore.GREEN, YELLOW=Fore.YELLOW, WHITE=Fore.WHITE, RED=Fore.RED))
            sys.exit(1)
        except sqlalchemy.exc.ProgrammingError:
            logger.error(
                    f'\n\nn{Fore.WHITE}Missing migrations, please execute: \n\nfaraday-manage migrate')
            sys.exit(1)
Exemplo n.º 5
0
 def onMessage(self, payload, is_binary):
     from faraday.server.web import app
     """
         We only support JOIN and LEAVE workspace messages.
         When authentication is implemented we need to verify
         that the user can join the selected workspace.
         When authentication is implemented we need to reply
         the client if the join failed.
     """
     if not is_binary:
         message = json.loads(payload)
         if message['action'] == 'JOIN_WORKSPACE':
             if 'workspace' not in message or 'token' not in message:
                 logger.warning('Invalid join workspace message: '
                                '{}'.format(message))
                 self.sendClose()
                 return
             signer = itsdangerous.TimestampSigner(app.config['SECRET_KEY'],
                                                   salt="websocket")
             try:
                 workspace_id = signer.unsign(message['token'], max_age=60)
             except itsdangerous.BadData as e:
                 self.sendClose()
                 logger.warning('Invalid websocket token for workspace '
                                '{}'.format(message['workspace']))
                 logger.exception(e)
             else:
                 with app.app_context():
                     workspace = Workspace.query.get(int(workspace_id))
                 if workspace.name != message['workspace']:
                     logger.warning(
                         'Trying to join workspace {} with token of '
                         'workspace {}. Rejecting.'.format(
                             message['workspace'], workspace.name))
                     self.sendClose()
                 else:
                     self.factory.join_workspace(self, message['workspace'])
         if message['action'] == 'LEAVE_WORKSPACE':
             self.factory.leave_workspace(self, message['workspace'])