Ejemplo n.º 1
0
def load_app_apis(apps_path=None):
    """Loads App APIs
    
    Args:
        apps_path (str, optional): Optional path to specify for the apps. Defaults to None, but will be set to the
            apps_path variable in Config object
    """
    from walkoff.helpers import list_apps, format_exception_message
    global app_apis
    if apps_path is None:
        apps_path = Config.APPS_PATH
    try:
        with open(join(Config.WALKOFF_SCHEMA_PATH), 'r') as schema_file:
            json.loads(schema_file.read())
    except Exception as e:
        logger.fatal(
            'Could not load JSON schema for apps. Shutting down...: ' + str(e))
        sys.exit(1)
    else:
        for app in list_apps(apps_path):
            try:
                url = join(apps_path, app, 'api.yaml')
                with open(url) as function_file:
                    api = yaml.load(function_file.read())
                    from walkoff.appgateway.validator import validate_app_spec
                    validate_app_spec(api, app, Config.WALKOFF_SCHEMA_PATH)
                    app_apis[app] = api
            except Exception as e:
                logger.error(
                    'Cannot load apps api for app {0}: Error {1}'.format(
                        app, str(format_exception_message(e))))
Ejemplo n.º 2
0
def create_user():
    db.create_all()

    # Setup admin and guest roles
    initialize_default_resources_admin()
    initialize_default_resources_guest()

    # Setup admin user
    admin_role = Role.query.filter_by(id=1).first()
    admin_user = User.query.filter_by(username="******").first()
    if not admin_user:
        add_user(username='******', password='******', roles=[1])
    elif admin_role not in admin_user.roles:
        admin_user.roles.append(admin_role)

    db.session.commit()

    apps = set(helpers.list_apps()) - set(
        [_app.name for _app in device_db.session.query(App).all()])
    app.logger.debug('Found apps: {0}'.format(apps))
    for app_name in apps:
        device_db.session.add(App(name=app_name, devices=[]))
    db.session.commit()
    device_db.session.commit()
    CaseSubscription.sync_to_subscriptions()

    app.logger.handlers = logging.getLogger('server').handlers
Ejemplo n.º 3
0
def create_user():
    from walkoff.serverdb import add_user, User, Role, initialize_default_resources_admin, \
        initialize_default_resources_guest
    db.create_all()

    # Setup admin and guest roles
    initialize_default_resources_admin()
    initialize_default_resources_guest()

    # Setup admin user
    admin_role = Role.query.filter_by(id=1).first()
    admin_user = User.query.filter_by(username="******").first()
    if not admin_user:
        add_user(username='******', password='******', roles=[1])
    elif admin_role not in admin_user.roles:
        admin_user.roles.append(admin_role)

    db.session.commit()

    apps = set(helpers.list_apps(walkoff.config.Config.APPS_PATH)) - set([
        _app.name for _app in
        current_app.running_context.execution_db.session.query(App).all()
    ])
    current_app.logger.debug('Found new apps: {0}'.format(apps))
    for app_name in apps:
        current_app.running_context.execution_db.session.add(
            App(name=app_name, devices=[]))
    db.session.commit()
    current_app.running_context.execution_db.session.commit()
    send_all_cases_to_workers()
    current_app.logger.handlers = logging.getLogger('server').handlers
Ejemplo n.º 4
0
def load_app_apis(apps_path=None):
    """Loads App APIs
    
    Args:
        apps_path (str, optional): Optional path to specify for the apps. Defaults to None, but will be set to the
            apps_path variable in Config object
    """
    from walkoff.helpers import list_apps, format_exception_message
    global app_apis
    if apps_path is None:
        apps_path = Config.APPS_PATH
    try:
        with open(join(Config.WALKOFF_SCHEMA_PATH), 'r') as schema_file:
            json.loads(schema_file.read())
    except Exception as e:
        logger.fatal('Could not load JSON schema for apps. Shutting down...: ' + str(e))
        sys.exit(1)
    else:
        for app in list_apps(apps_path):
            try:
                url = join(apps_path, app, 'api.yaml')
                with open(url) as function_file:
                    api = yaml.load(function_file.read())
                    from walkoff.appgateway.validator import validate_app_spec
                    validate_app_spec(api, app, Config.WALKOFF_SCHEMA_PATH)
                    app_apis[app] = api
            except Exception as e:
                logger.error(
                    'Cannot load apps api for app {0}: Error {1}'.format(app, str(format_exception_message(e))))
Ejemplo n.º 5
0
def load_app_apis(apps_path=None):
    from walkoff.helpers import list_apps, format_exception_message
    global app_apis
    if apps_path is None:
        apps_path = walkoff.config.paths.apps_path
    try:
        with open(join(walkoff.config.paths.walkoff_schema_path),
                  'r') as schema_file:
            json.loads(schema_file.read())
    except Exception as e:
        __logger.fatal(
            'Could not load JSON schema for apps. Shutting down...: ' + str(e))
        sys.exit(1)
    else:
        for app in list_apps(apps_path):
            try:
                url = join(apps_path, app, 'api.yaml')
                with open(url) as function_file:
                    api = yaml.load(function_file.read())
                    from walkoff.appgateway.validator import validate_app_spec
                    validate_app_spec(api, app)
                    app_apis[app] = api
            except Exception as e:
                __logger.error(
                    'Cannot load apps api for app {0}: Error {1}'.format(
                        app, str(format_exception_message(e))))
Ejemplo n.º 6
0
def create_user():
    from walkoff.serverdb import add_user, User, Role, initialize_default_resources_admin, \
        initialize_default_resources_guest
    from sqlalchemy_utils import database_exists, create_database

    if not database_exists(db.engine.url):
        create_database(db.engine.url)
    db.create_all()

    alembic_cfg = Config(walkoff.config.Config.ALEMBIC_CONFIG,
                         ini_section="walkoff",
                         attributes={'configure_logger': False})

    # This is necessary for a flask database
    connection = db.engine.connect()
    context = MigrationContext.configure(connection)
    script = ScriptDirectory.from_config(alembic_cfg)
    context.stamp(script, "head")

    # Setup admin and guest roles
    initialize_default_resources_admin()
    initialize_default_resources_guest()

    # Setup admin user
    admin_role = Role.query.filter_by(id=1).first()
    admin_user = User.query.filter_by(username="******").first()
    if not admin_user:
        add_user(username='******', password='******', roles=[1])
    elif admin_role not in admin_user.roles:
        admin_user.roles.append(admin_role)

    db.session.commit()

    apps = set(helpers.list_apps(walkoff.config.Config.APPS_PATH)) - set([
        _app.name for _app in
        current_app.running_context.execution_db.session.query(App).all()
    ])
    current_app.logger.debug('Found new apps: {0}'.format(apps))
    for app_name in apps:
        current_app.running_context.execution_db.session.add(
            App(name=app_name, devices=[]))
    db.session.commit()
    current_app.running_context.execution_db.session.commit()
    reschedule_all_workflows()
    current_app.logger.handlers = logging.getLogger('server').handlers
Ejemplo n.º 7
0
def create_user():
    from walkoff.serverdb import add_user, User, Role, initialize_default_resources_admin, \
        initialize_default_resources_guest
    from sqlalchemy_utils import database_exists, create_database

    if not database_exists(db.engine.url):
        create_database(db.engine.url)
    db.create_all()

    alembic_cfg = Config(walkoff.config.Config.ALEMBIC_CONFIG, ini_section="walkoff",
                         attributes={'configure_logger': False})

    # This is necessary for a flask database
    connection = db.engine.connect()
    context = MigrationContext.configure(connection)
    script = ScriptDirectory.from_config(alembic_cfg)
    context.stamp(script, "head")

    # Setup admin and guest roles
    initialize_default_resources_admin()
    initialize_default_resources_guest()

    # Setup admin user
    admin_role = Role.query.filter_by(id=1).first()
    admin_user = User.query.filter_by(username="******").first()
    if not admin_user:
        add_user(username='******', password='******', roles=[1])
    elif admin_role not in admin_user.roles:
        admin_user.roles.append(admin_role)

    db.session.commit()

    apps = set(helpers.list_apps(walkoff.config.Config.APPS_PATH)) - set([_app.name
                                                                          for _app in
                                                                          current_app.running_context.execution_db.session.query(
                                                                              App).all()])
    current_app.logger.debug('Found new apps: {0}'.format(apps))
    for app_name in apps:
        current_app.running_context.execution_db.session.add(App(name=app_name, devices=[]))
    db.session.commit()
    current_app.running_context.execution_db.session.commit()
    reschedule_all_workflows()
    current_app.logger.handlers = logging.getLogger('server').handlers
Ejemplo n.º 8
0
 def __func():
     apps = helpers.list_apps()
     return sorted(apps, key=(lambda app_name: app_name.lower())), SUCCESS
Ejemplo n.º 9
0
 def __func():
     apps = helpers.list_apps(walkoff.config.Config.APPS_PATH)
     return sorted(apps, key=(lambda app_name: app_name.lower())), SUCCESS
Ejemplo n.º 10
0
 def __func():
     apps = helpers.list_apps(walkoff.config.Config.APPS_PATH)
     return sorted(apps, key=(lambda app_name: app_name.lower())), SUCCESS
Ejemplo n.º 11
0
def test_app(app_name):
    print('Testing app: {0}'.format(app))
    test_modules = get_tests(app_name)
    if test_modules:
        suite = unittest.TestSuite()
        suite.addTests([
            unittest.TestLoader().loadTestsFromModule(test_module)
            for test_module in test_modules
        ])
        return unittest.TextTestRunner(verbosity=1).run(suite).wasSuccessful()
    elif test_modules is None or len(test_modules) == 0:
        print("App {0} has no tests. Don't be that person. Write your tests.".
              format(app_name))
        return True


if __name__ == '__main__':
    cmd_args = cmd_line()
    all_apps = list_apps()
    ret = True
    if cmd_args.all:
        for app in all_apps:
            ret &= test_app(app)
    elif cmd_args.apps:
        for app in cmd_args.apps:
            if app in all_apps:
                ret &= test_app(app)
            else:
                print('App {0} not found!'.format(app))
    sys.exit(not ret)
                        help='List of apps for which you would like to install dependencies')
    parser.add_argument('-i', '--interfaces', nargs='*', type=str, required=False,
                        help='List of interfaces for which you would like to install dependencies')
    args = parser.parse_args()
    return args


if __name__ == '__main__':

    args = cmd_line()
    apps = args.apps
    interfaces = args.interfaces
    from walkoff.config import Config

    if not apps:
        apps = list_apps(Config.APPS_PATH)

    if not interfaces:
        interfaces = list_interfaces(Config.INTERFACES_PATH)

    for app in apps:
        print("Installing dependencies for " + app + " App...")
        path = os.path.abspath(os.path.join('apps', app, 'requirements.txt'))
        if os.path.isfile(path) is False:
            print("No requirements.txt file found in " + app + " folder. Skipping...")
            continue
        subprocess.call(['pip', 'install', '-r', path])

    for interface in interfaces:
        print("Installing dependencies for " + interface + " Interface...")
        path = os.path.abspath(os.path.join('interfaces', interface, 'requirements.txt'))
Ejemplo n.º 13
0
def apps(ctx, select):
    apps_path = ctx.obj['config'].APPS_PATH if 'config' in ctx.obj else Config.APPS_PATH
    apps_ = list_apps(apps_path) if not select else select.split(',')
    install_apps(apps_, apps_path)
Ejemplo n.º 14
0
def _install_all_apps_interfaces(apps_path, interfaces_path):
    apps_ = list_apps(apps_path)
    interfaces_ = list_interfaces(interfaces_path)
    install_apps(apps_, apps_path)
    install_interfaces(interfaces_, interfaces_path)
Ejemplo n.º 15
0
def apps(ctx, select):
    apps_path = ctx.obj[
        'config'].APPS_PATH if 'config' in ctx.obj else Config.APPS_PATH
    apps_ = list_apps(apps_path) if not select else select.split(',')
    install_apps(apps_, apps_path)
Ejemplo n.º 16
0
def _install_all_apps_interfaces(apps_path, interfaces_path):
    apps_ = list_apps(apps_path)
    interfaces_ = list_interfaces(interfaces_path)
    install_apps(apps_, apps_path)
    install_interfaces(interfaces_, interfaces_path)