Пример #1
0
def load_app_apis(apps_path=None):
    from core.helpers import list_apps, format_exception_message
    global app_apis
    if apps_path is None:
        apps_path = core.config.paths.apps_path
    try:
        with open(join(core.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 core.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))))
Пример #2
0
def create_user():
    from server.context import running_context
    from server.database import add_user, User, ResourcePermission, Role, initialize_resource_roles_from_database

    running_context.db.create_all()
    if not User.query.all():
        admin_role = running_context.Role(
            name='admin',
            description='administrator',
            resources=server.database.default_resources)
        running_context.db.session.add(admin_role)
        admin_user = add_user(username='******', password='******')
        admin_user.roles.append(admin_role)
        running_context.db.session.commit()
    if Role.query.all() or ResourcePermission.query.all():
        initialize_resource_roles_from_database()

    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=[]))
    running_context.db.session.commit()
    device_db.session.commit()
    running_context.CaseSubscription.sync_to_subscriptions()

    app.logger.handlers = logging.getLogger('server').handlers
Пример #3
0
def create_user():
    from server.context import running_context
    from . import database
    from server import flaskserver

    running_context.db.create_all()

    if not database.User.query.first():
        admin_role = running_context.user_datastore.create_role(
            name='admin',
            description='administrator',
            pages=flaskserver.default_urls)

        u = running_context.user_datastore.create_user(
            email='admin', password=encrypt_password('admin'))
        running_context.user_datastore.add_role_to_user(u, admin_role)
        running_context.db.session.commit()

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

    running_context.CaseSubscription.sync_to_subscriptions()

    app.logger.handlers = logging.getLogger('server').handlers
Пример #4
0
def list_all_apps_and_actions():
    apps = helpers.list_apps()
    return json.dumps({
        app: list(
            (set(helpers.list_app_functions(app)) - get_base_app_functions()))
        for app in apps
    })
Пример #5
0
 def get_apps(path=core.config.paths.apps_path):
     """Gets all the App instances.
     
     Args:
         path (str, optional): The path to the apps. Defaults to the apps_path set in the configuration.
         
     Returns:
         A list of App instances.
     """
     return list_apps(path=path)
Пример #6
0
def load_function_info():
    global function_info
    try:
        with open(core.config.paths.function_info_path) as f:
            function_info = json.loads(f.read())
        app_funcs = {}
        for app in list_apps():
            with open(join(core.config.paths.apps_path, app, 'functions.json')) as function_file:
                app_funcs[app] = json.loads(function_file.read())
        function_info['apps'] = app_funcs

    except Exception as e:
        print("caught!")
        print(e)
Пример #7
0
def load_function_info():
    """ Loads the app action metadata
    """
    global function_info
    with open(core.config.paths.function_info_path) as f:
        function_info = json.loads(f.read())
    app_funcs = {}
    for app in list_apps():
        try:
            with open(join(core.config.paths.apps_path, app,
                           'functions.json')) as function_file:
                app_funcs[app] = json.loads(function_file.read())
        except Exception as e:
            __logger.error(
                'Cannot load function metadata: Error {0}'.format(e))
    function_info['apps'] = app_funcs
Пример #8
0
def create_user():
    running_context.db.create_all()

    if not database.User.query.first():
        admin_role = running_context.user_datastore.create_role(
            name='admin', description='administrator', pages=default_urls)

        u = running_context.user_datastore.create_user(
            email='admin', password=encrypt_password('admin'))

        running_context.user_datastore.add_role_to_user(u, admin_role)

        running_context.db.session.commit()

    apps = set(helpers.list_apps()) - set([
        _app.name for _app in running_context.db.session.query(
            running_context.App).all()
    ])
    for app_name in apps:
        running_context.db.session.add(
            running_context.App(app=app_name, devices=[]))
    running_context.db.session.commit()

    running_context.CaseSubscription.sync_to_subscriptions()
Пример #9
0
 def __func():
     return {"apps": helpers.list_apps()}, SUCCESS
Пример #10
0
            if func1 != func2 and 'aliases' in info1 and 'aliases' in info2:
                overlap = set(info1['aliases']) & set(info2['aliases'])
                if overlap:
                    print('In app {0}: Error: Function {1} and function {2} '
                          'have same aliases {3}!'.format(
                              app_name, func1, func2, list(overlap)))


def validate_app(app_name):
    print('Validating App {0}'.format(app_name))
    app_functions = list_all_app_functions(app_name)
    function_json = load_functions_json(app_name)
    if app_functions and function_json:
        validate_functions_exist(app_name, app_functions, function_json)
        validate_fields(app_name, function_json)
        check_duplicate_aliases(app_name, function_json)


if __name__ == '__main__':
    cmd_args = cmd_line()
    all_apps = list_apps()
    if cmd_args.all:
        for app in all_apps:
            validate_app(app)
    else:
        for app in cmd_args.apps:
            if app in all_apps:
                validate_app(app)
            else:
                print('App {0} not found!'.format(app))
Пример #11
0
def list_all_widgets():
    return json.dumps(
        {_app: helpers.list_widgets(_app)
         for _app in helpers.list_apps()})
Пример #12
0
 def get_apps(path=core.config.paths.apps_path):
     return list_apps(path=path)
Пример #13
0
def list_all_apps():
    return json.dumps({"apps": helpers.list_apps()})
Пример #14
0
 def __func():
     if interfaces_only:
         return helpers.list_apps_with_interfaces(), SUCCESS
     if has_device_types:
         return helpers.list_apps_with_device_types(), SUCCESS
     return helpers.list_apps(), SUCCESS
Пример #15
0
 def __func():
     return {
         _app: helpers.list_widgets(_app)
         for _app in helpers.list_apps()
     }
Пример #16
0
 def __func():
     apps = helpers.list_apps()
     return sorted(apps, key=(lambda app_name: app_name.lower())), SUCCESS
Пример #17
0
 def getApps(path="apps"):
     return list_apps(path=path)