Example #1
0
    def __create_environment(self,context, loader):

        jenv = jinja2.Environment(
            loader=loader,
            extensions=['jinja2.ext.autoescape'],
            autoescape=False)

        for key, fn in JinjaEnvironment._template_functions.items():
            jenv.globals[key]=fn

        params={"environment": jenv, "loader": loader}
        handler=Plugin(context, "jinja_environment","create")
        handler.execute('after', params)

        return jenv
Example #2
0
    def post(self, action):
        try:
            create_parser_post().parse_args()
            context = g.context

            if request.json == None:
                abort(400, f"cannot extract json data in body action:{action}")

            params = {"input": request.json, "output": {}}
            handler = Plugin(context, action, "execute")
            handler.execute('before', params)

            output = params['output']

            response = make_response(output, 200)
            return response

        except NameError as err:
            abort(400, f"{err}")
        except Exception as err:
            abort(500, f"{err}")
Example #3
0
def execute_plugin(context, publisher, params):
    create_logger(__name__).info(publisher)
    plugin = Plugin(context, publisher, 'execute')
    plugin.execute('after', {'input': params, 'output': {}})
Example #4
0
            runner.run()


if __name__ == '__main__':
    from core import params

    menu = Menu(
        name="test menu",
        description="test description",
    )

    menu.add_option(
        "1",
        Plugin(
            name="hello_world_1",
            description="description",
            run_command=lambda: print("Hello world1!"),
        ))
    menu.add_option(
        "2",
        Plugin(
            name="hellow_world_2",
            description="descr",
            run_command=lambda port: print(f"Hello world2! {port}"),
            parameters=params.PORT,
        ))

    menu2 = Menu(
        name="Some name",
        description=" descro",
        banner="LOL BANNER",
Example #5
0
    def exec(command_builder, context, run_as_system=False, fetch_mode=-1):
        #
        # Validate the permission
        # in case of no permission the check_permission function triggers an errror
        #

        if not run_as_system:
            for table in command_builder.get_tables():
                if not Permission().validate(context,
                                             command_builder.get_sql_type(),
                                             context.get_username(), table):
                    #raise NameError (f"no permission ({command_builder.get_sql_type()}) for {context.get_username()} on {table}")
                    raise RestApiNotAllowed(
                        f"no permission ({command_builder.get_sql_type()}) for {context.get_username()} on {table}"
                    )

        logger.info(
            f"Try to read table metadata: {command_builder.get_main_table()}")
        meta = read_table_meta(context,
                               table_name=command_builder.get_main_table())
        id_field_name = meta['id_field_name']
        id_field_type = meta['id_field_type']

        if command_builder.get_sql_type().upper() == 'UPDATE':
            #meta=read_table_meta(context, table_name=command_builder.get_main_table())
            if meta['enable_audit_log'] != 0:
                sql, paras = command_builder.get_select()
                cursor = context.get_connection().cursor()
                cursor.execute(sql, paras)
                rsold = Recordset(cursor)
                rsold.read(0)
                #id_field_name=meta['id_field_name']
                #id_field_type=meta['id_field_type']

                logger.info(rsold.get_result())
                if rsold.get_result() != None:
                    for rec in rsold.get_result():
                        id = rec[id_field_name]
                        for k, v in rec.items():
                            if k in command_builder.get_sql_fields():
                                value = command_builder.get_sql_fields(
                                )[k]['value']
                                old_value = v
                                command_builder.get_sql_fields(
                                )[k]['old_value'] = old_value
                                AuditLog.log(context,
                                             command_builder.get_sql_type(),
                                             id,
                                             command_builder.get_main_table(),
                                             k, old_value, value)

                        logger.info(command_builder.get_sql_fields())

        params = {"data": command_builder.get_sql_fields()}
        handler = Plugin(context, command_builder.get_main_table(),
                         command_builder.get_sql_type())
        handler.execute('before', params)

        sql, paras = command_builder.get_sql()

        logger.info(sql)
        logger.info(paras)

        cursor = context.get_connection().cursor()
        cursor.execute(sql, paras)

        handler.execute('after', params)

        if command_builder.get_auto_commit(
        ) == 1 or command_builder.get_auto_commit() == True:
            context.get_connection().commit()

        rs = Recordset(cursor)
        if fetch_mode != -1:
            rs.read(fetch_mode)

        rs.get_columns()
        if command_builder.get_sql_type().upper() == "INSERT":
            if context.get_connection().insert_id(
            ) == 0 or context.get_connection().insert_id() == None:
                rs.set_inserted_id(
                    command_builder.get_sql_fields()[id_field_name]['value'])
            else:
                rs.set_inserted_id(context.get_connection().insert_id())
        return rs
Example #6
0
# ----- < import > -----
from core.plugin import Plugin
from core.utils import write_msg

plugin = Plugin('example', '/example', ['test - тестовая комманда'], '⚪')
data = plugin.plugin_data

@plugin.command(['test'])
def test(data, arg):
	write_msg(data, 'hello world!')